Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(log): move finished log #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Sources/ReleaseSubscriptions/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ struct App: AsyncParsableCommand {
var secondarySlackURL: URL?

func run() async throws {
defer {
Logger.app.info("🎉 \(#function) finished")
}
Logger.app.info("ℹ️ \(#function) started")
do {
if primarySlackURL == nil {
Expand All @@ -38,6 +35,7 @@ struct App: AsyncParsableCommand {
try await SlackNotifier.notify(to: slackURLs(), updates: updatedContents)
try FileHelper.save(contents: combinedContents)
try FileHelper.writeToREADME(repositories: repositories)
Logger.app.info("🎉 \(#function) finished")
} catch {
Logger.app.error("❌ \(error)")
throw error
Expand Down
4 changes: 1 addition & 3 deletions Sources/ReleaseSubscriptionsCore/DifferenceComparator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import Logging

public struct DifferenceComparator {
public static func insertions(repositories: [GitHubRepository], old: [GitHubRepository : [Release]], new: [GitHubRepository : [Release]]) -> [GitHubRepository : [Release]] {
defer {
Logger.shared.info("🎉 \(#function) finished")
}
Logger.shared.info("ℹ️ \(#function) started")
var insertions: [GitHubRepository : [Release]] = [:]
for repository in repositories {
Expand All @@ -34,6 +31,7 @@ public struct DifferenceComparator {
Logger.shared.info("🤩 There are differences in \(repository.name) releases")
}
}
Logger.shared.info("🎉 \(#function) finished")
return insertions
}
}
4 changes: 1 addition & 3 deletions Sources/ReleaseSubscriptionsCore/Fetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public struct Fetcher {
}

public static func fetch(repositories: [GitHubRepository]) async throws -> [GitHubRepository : [Release]] {
defer {
Logger.shared.info("🎉 \(#function) finished")
}
Logger.shared.info("ℹ️ \(#function) started")
return try await withThrowingTaskGroup(of: (GitHubRepository, [Release]).self) { group in
for repository in repositories {
Expand All @@ -44,6 +41,7 @@ public struct Fetcher {
for try await (repository, releases) in group {
results[repository] = releases
}
Logger.shared.info("🎉 \(#function) finished")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この変更により、Fetcher.fetch(repositories:) がエラーだったときに何も log が残らないため、エラー時もその旨の log を追加したいです。

(1つ上にある Fetcher.fetch(repository:) にもエラー時の log を追加したいです。)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スローした先でログを出力するので、ここでは何も残さなくていいと思うんだけどどうだろう?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ほかも同様

return results
}
}
Expand Down
17 changes: 4 additions & 13 deletions Sources/ReleaseSubscriptionsCore/FileHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public struct FileHelper {
// MARK: - Repositories and Releases

public static func load(repositories: [GitHubRepository]) throws -> [GitHubRepository : [Release]] {
defer {
Logger.shared.info("🎉 \(#function) finished")
}
Logger.shared.info("ℹ️ \(#function) started")
var contents: [GitHubRepository : [Release]] = [:]
for repository in repositories {
Expand All @@ -71,13 +68,11 @@ public struct FileHelper {
Logger.shared.info("🔔 \(repository.outputJSONFileName) loading was skipped because that file could not be found")
}
}
Logger.shared.info("🎉 \(#function) finished")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この変更により、FileHelper.load(repositories:) がエラーだったときに何も log が残らないため、エラー時もその旨の log を追加したいです。

return contents
}

public static func save(contents: [GitHubRepository : [Release]]) throws {
defer {
Logger.shared.info("🎉 \(#function) finished")
}
Logger.shared.info("ℹ️ \(#function) started")
for (repository, releases) in contents {
Logger.shared.info("ℹ️ Saving \(repository.outputJSONFileName)")
Expand All @@ -86,17 +81,14 @@ public struct FileHelper {
try data.write(to: url)
Logger.shared.info("✅ Saved \(repository.outputJSONFileName)")
}
Logger.shared.info("🎉 \(#function) finished")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この変更により、FileHelper.save(contents:) がエラーだったときに何も log が残らないため、エラー時もその旨の log を追加したいです。

}


// MARK: - README.md

private static let lowerBoundKeyword = "<!-- BEGIN LIST OF REPOSITORIES (AUTOMATICALLY OUTPUT) -->"
private static let upperBoundKeyword = "<!-- END LIST OF REPOSITORIES (AUTOMATICALLY OUTPUT) -->"
public static func writeToREADME(repositories: [GitHubRepository]) throws {
defer {
Logger.shared.info("🎉 \(#function) finished")
}
Logger.shared.info("ℹ️ \(#function) started")
let (url, string, lowerBound, upperBound) = try readFromREADME()
let outputListOfRepositoriesString = """
Expand All @@ -112,19 +104,18 @@ public struct FileHelper {
+ upperBoundKeyword
try string.replacingCharacters(in: lowerBound..<upperBound, with: outputListOfRepositoriesString)
.write(to: url, atomically: true, encoding: .utf8)
Logger.shared.info("🎉 \(#function) finished")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この変更により、FileHelper.writeToREADME(repositories:) がエラーだったときに何も log が残らないため、エラー時もその旨の log を追加したいです。

}

static func readFromREADME() throws -> (URL, String, String.Index, String.Index) {
defer {
Logger.shared.info("🎉 \(#function) finished")
}
Logger.shared.info("ℹ️ \(#function) started")
let url = URL.topLevelDirectory.appendingPathComponent("README.md")
let string = try String(contentsOf: url)
guard let lowerBound = string.range(of: lowerBoundKeyword)?.lowerBound,
let upperBound = string.range(of: upperBoundKeyword)?.upperBound else {
throw Error.invalidREADMEFormat
}
Logger.shared.info("🎉 \(#function) finished")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この変更により、FileHelper.readFromREADME() がエラーだったときに何も log が残らないため、エラー時もその旨の log を追加したいです。

return (url, string, lowerBound, upperBound)
}
}
5 changes: 2 additions & 3 deletions Sources/ReleaseSubscriptionsCore/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public struct Parser {
}

public static func parse() throws -> [GitHubRepository] {
defer {
Logger.shared.info("🎉 \(#function) finished")
}
Logger.shared.info("ℹ️ \(#function) started")
let url = URL.topLevelDirectory.appendingPathComponent("ReleaseSubscriptions.yml")
let string = try String(contentsOf: url)
Expand All @@ -39,9 +36,11 @@ public struct Parser {
switch `case` {
case "releases":
Logger.shared.info("✅ The correct YAML format: \(name) (\(`case`))")
Logger.shared.info("🎉 \(#function) finished")
return .releases(destination, .init(name: name, owner: owner, repository: repository))
case "tags":
Logger.shared.info("✅ The correct YAML format: \(name) (\(`case`))")
Logger.shared.info("🎉 \(#function) finished")
Comment on lines +39 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この変更により、Parser.parse() がエラーだったときに何も log が残らないため、エラー時もその旨の log を追加したいです。

return .tags(destination, .init(name: name, owner: owner, repository: repository))
default:
throw Error.unknownCase
Expand Down
4 changes: 1 addition & 3 deletions Sources/ReleaseSubscriptionsCore/SlackNotifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public struct SlackNotifier {
}()

public static func notify(to slackURLs: [SlackWebhookDestination : URL], updates: [GitHubRepository : [Release]]) async throws {
defer {
Logger.shared.info("🎉 \(#function) finished")
}
Logger.shared.info("ℹ️ \(#function) started")
try await withThrowingTaskGroup(of: Void.self) { group in
for (repository, releases) in updates {
Expand Down Expand Up @@ -60,6 +57,7 @@ public struct SlackNotifier {
}
try await group.waitForAll()
}
Logger.shared.info("🎉 \(#function) finished")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この変更により、SlackNotifier.notify(to:updates:) がエラーだったときに何も log が残らないため、エラー時もその旨の log を追加したいです。

}

static private func message(name: String, owner: String, repo: String, repoURL: URL, title: String, version: String, releaseURL: URL, publishedAt: String?, body: String) -> String {
Expand Down