Skip to content

Commit 0c1e6df

Browse files
authored
Merge pull request #83 from WeTransfer/feature/fix-swiftlint-issues
Fix SwiftLint and SwiftFormat warnings
2 parents fc1cd1f + 6e59042 commit 0c1e6df

39 files changed

+229
-136
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let package = Package(
66
name: "GitBuddy",
77
platforms: [
88
.macOS(.v10_15)
9-
],
9+
],
1010
products: [
1111
.executable(name: "GitBuddy", targets: ["GitBuddy"])
1212
],

Sources/GitBuddyCore/Changelog/ChangelogItemsFactory.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct ChangelogItemsFactory {
2121
return [ChangelogItem(input: pullRequest, closedBy: pullRequest)]
2222
}
2323
return resolvedIssues.map { issue -> ChangelogItem in
24-
return ChangelogItem(input: issue, closedBy: pullRequest)
24+
ChangelogItem(input: issue, closedBy: pullRequest)
2525
}
2626
}
2727
}

Sources/GitBuddyCore/Changelog/ChangelogProducer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import OctoKit
1111

1212
/// Capable of producing a changelog based on input parameters.
1313
final class ChangelogProducer: URLSessionInjectable {
14-
1514
enum Since {
1615
case date(date: Date)
1716
case tag(tag: String)
1817
case latestTag
1918

2019
/// Gets the date for the current Since property.
21-
/// In the case of a tag, we add 60 seconds to make sure that the Changelog does not include the commit that is used for creating the tag.
20+
/// In the case of a tag, we add 60 seconds to make sure that the Changelog does not include the commit that
21+
/// is used for creating the tag.
2222
/// This is needed as the tag creation date equals the commit creation date.
2323
func get() throws -> Date {
2424
switch self {
@@ -32,7 +32,7 @@ final class ChangelogProducer: URLSessionInjectable {
3232
}
3333
}
3434

35-
private lazy var octoKit: Octokit = Octokit()
35+
private lazy var octoKit: Octokit = .init()
3636
let baseBranch: Branch
3737
let since: Since
3838
let from: Date

Sources/GitBuddyCore/Commands/ChangelogCommand.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
// Created by Antoine van der Lee on 09/04/2020.
66
//
77

8-
import Foundation
98
import ArgumentParser
9+
import Foundation
1010

1111
struct ChangelogCommand: ParsableCommand {
12-
1312
public static let configuration = CommandConfiguration(commandName: "changelog", abstract: "Create a changelog for GitHub repositories")
1413

1514
@Option(name: .shortAndLong, help: "The tag to use as a base. Defaults to the latest tag.")

Sources/GitBuddyCore/Commands/GitBuddy.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// Copyright © 2020 WeTransfer. All rights reserved.
77
//
88

9-
import Foundation
109
import ArgumentParser
10+
import Foundation
1111

1212
/// Entry class of GitBuddy that registers commands and handles execution.
1313
public struct GitBuddy: ParsableCommand {
@@ -20,5 +20,5 @@ public struct GitBuddy: ParsableCommand {
2020
subcommands: [ChangelogCommand.self, ReleaseCommand.self, TagDeletionsCommand.self]
2121
)
2222

23-
public init() { }
23+
public init() {}
2424
}

Sources/GitBuddyCore/Commands/ReleaseCommand.swift

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
// Created by Antoine van der Lee on 09/04/2020.
66
//
77

8-
import Foundation
98
import ArgumentParser
9+
import Foundation
1010

1111
struct ReleaseCommand: ParsableCommand {
12-
13-
public static let configuration = CommandConfiguration(commandName: "release", abstract: "Create a new release including a changelog and publish comments on related issues.")
12+
public static let configuration = CommandConfiguration(
13+
commandName: "release",
14+
abstract: "Create a new release including a changelog and publish comments on related issues."
15+
)
1416

1517
@Option(name: .shortAndLong, help: "The path to the Changelog to update it with the latest changes.")
1618
var changelogPath: String?
@@ -22,11 +24,26 @@ struct ReleaseCommand: ParsableCommand {
2224
var isPrerelease: Bool = false
2325

2426
// Main
25-
@Option(name: .shortAndLong, help: "Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository's default branch (usually main).")
27+
@Option(
28+
name: .shortAndLong,
29+
help: """
30+
Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA.
31+
Unused if the Git tag already exists.
32+
33+
Default: the repository's default branch (usually main).
34+
"""
35+
)
2636
var targetCommitish: String?
2737

2838
// 1.3.1b1072
29-
@Option(name: [.long, .customShort("n")], help: "The name of the tag. If set, `changelogToTag` is required too. Default: takes the last created tag to publish as a GitHub release.")
39+
@Option(
40+
name: [.long, .customShort("n")],
41+
help: """
42+
The name of the tag. If set, `changelogToTag` is required too.
43+
44+
Default: takes the last created tag to publish as a GitHub release.
45+
"""
46+
)
3047
var tagName: String?
3148

3249
// // 1.3.1b1072 - App Store Release
@@ -37,7 +54,15 @@ struct ReleaseCommand: ParsableCommand {
3754
@Option(name: .shortAndLong, help: "The last release tag to use as a base for the changelog creation. Default: previous tag.")
3855
var lastReleaseTag: String?
3956

40-
@Option(name: .customLong("changelogToTag"), help: "If set, the date of this tag will be used as the limit for the changelog creation. This variable should be passed when `tagName` is set. Default: latest tag.")
57+
@Option(
58+
name: .customLong("changelogToTag"),
59+
help: """
60+
If set, the date of this tag will be used as the limit for the changelog creation.
61+
This variable should be passed when `tagName` is set.
62+
63+
Default: latest tag.
64+
"""
65+
)
4166
var changelogToTag: String?
4267

4368
// Develop

Sources/GitBuddyCore/Commands/TagDeletionsCommand.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import Foundation
21
import ArgumentParser
2+
import Foundation
33

44
struct TagDeletionsCommand: ParsableCommand {
5-
6-
public static let configuration = CommandConfiguration(commandName: "tagDeletion", abstract: "Delete a batch of tags based on given predicates.")
5+
public static let configuration = CommandConfiguration(
6+
commandName: "tagDeletion",
7+
abstract: "Delete a batch of tags based on given predicates."
8+
)
79

810
@Option(name: .shortAndLong, help: "The date of this tag will be used as a limit. Defaults to the latest tag.")
911
private var upUntilTag: String?

Sources/GitBuddyCore/GitHub/Commenter.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ enum Comment {
1818
case .releasedPR(let release):
1919
return "Congratulations! :tada: This was released as part of [Release \(release.title)](\(release.url)) :rocket:"
2020
case .releasedIssue(let release, let pullRequestID):
21-
var body = "The pull request #\(pullRequestID) that closed this issue was merged and released as part of [Release \(release.title)](\(release.url)) :rocket:\n"
22-
body += "Please let us know if the functionality works as expected as a reply here. If it does not, please open a new issue. Thanks!"
21+
var body = "The pull request #\(pullRequestID) that closed this issue was merged and released "
22+
body += "as part of [Release \(release.title)](\(release.url)) :rocket:\n"
23+
body += "Please let us know if the functionality works as expected as a reply here. "
24+
body += "If it does not, please open a new issue. Thanks!"
2325
return body
2426
}
2527
}
@@ -43,14 +45,17 @@ enum Commenter {
4345
static func post(_ comment: Comment, on issueID: Int, at project: GITProject, completion: @escaping () -> Void) {
4446
var body = comment.body
4547
body += watermark
46-
Octokit().commentIssue(urlSession, owner: project.organisation, repository: project.repository, number: issueID, body: body) { response in
47-
switch response {
48-
case .success(let comment):
49-
Log.debug("Successfully posted comment at: \(comment.htmlURL)")
50-
case .failure(let error):
51-
Log.debug("Posting comment for issue #\(issueID) failed: \(error)")
48+
Octokit()
49+
.commentIssue(urlSession, owner: project.organisation, repository: project.repository, number: issueID,
50+
body: body)
51+
{ response in
52+
switch response {
53+
case .success(let comment):
54+
Log.debug("Successfully posted comment at: \(comment.htmlURL)")
55+
case .failure(let error):
56+
Log.debug("Posting comment for issue #\(issueID) failed: \(error)")
57+
}
58+
completion()
5259
}
53-
completion()
54-
}
5560
}
5661
}

Sources/GitBuddyCore/GitHub/IssuesFetcher.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Foundation
99
import OctoKit
1010

1111
struct IssuesFetcher {
12-
1312
let octoKit: Octokit
1413
let project: GITProject
1514

@@ -20,7 +19,7 @@ struct IssuesFetcher {
2019

2120
var result: Result<[Issue], Swift.Error>!
2221

23-
octoKit.issues(session, owner: project.organisation, repository: project.repository, state: .closed) { (response) in
22+
octoKit.issues(session, owner: project.organisation, repository: project.repository, state: .closed) { response in
2423
switch response {
2524
case .success(let issues):
2625
result = .success(issues)
@@ -42,5 +41,4 @@ struct IssuesFetcher {
4241
return closedAt > fromDate && closedAt < toDate
4342
}
4443
}
45-
4644
}

Sources/GitBuddyCore/GitHub/IssuesResolver.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct IssuesResolver {
4242
}
4343

4444
extension String {
45-
4645
/// Extracts the resolved issues from a Pull Request body.
4746
func resolvingIssues() -> [Int] {
4847
var resolvedIssues = Set<Int>()
@@ -69,8 +68,8 @@ extension String {
6968
guard index + 1 <= splits.count - 1 else { break }
7069
let nextSplit = splits[index + 1]
7170

72-
let numberPrefixString = nextSplit.prefix { (character) -> Bool in
73-
return character.isNumber
71+
let numberPrefixString = nextSplit.prefix { character -> Bool in
72+
character.isNumber
7473
}
7574

7675
if !numberPrefixString.isEmpty, let numberPrefix = Int(numberPrefixString.description) {

0 commit comments

Comments
 (0)