Skip to content

Commit

Permalink
Merge pull request #35 from ios-osushi/feature/refactor_comments_and_…
Browse files Browse the repository at this point in the history
…codes

コメントの追加とリファクタリング
  • Loading branch information
uhooi authored Sep 28, 2024
2 parents dabc408 + 0547b8f commit 9197ead
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
28 changes: 23 additions & 5 deletions Sources/ReleaseSubscriptions/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct App: AsyncParsableCommand {
}
Logger.app.info("ℹ️ \(#function) started")
do {
// 各オプションが空の場合、ログを出力する
if accessToken == nil {
Logger.app.info("🔔 accessToken is nil")
}
Expand All @@ -36,14 +37,31 @@ struct App: AsyncParsableCommand {
if secondarySlackURL == nil {
Logger.app.info("🔔 secondarySlackURL is nil")
}
let repositories = try Parser.parse()
let oldContents = try FileHelper.load(repositories: repositories)
let newContents = try await Fetcher.fetch(repositories: repositories, accessToken: accessToken)

// リリース購読ファイルをパースする
let repositories = try ReleaseSubscriptionsParser.parse()

// 古いコンテンツをJSONから読み込む
let oldContents = try OutputFileHelper.load(repositories: repositories)

// 新しいコンテンツをGitHubから取得する
let newContents = try await ReleaseFetcher.fetch(repositories: repositories, accessToken: accessToken)

// 新旧のコンテンツをマージする
// 新しいコンテンツのみだとリリース情報が多いと古いのが含まれないため、マージする
let combinedContents = oldContents.merging(newContents) { ($0 + $1).identified().sorted() }

// 古いコンテンツとマージされたコンテンツを比較して、更新されたコンテンツを抽出する
let updatedContents = DifferenceComparator.insertions(repositories: repositories, old: oldContents, new: combinedContents)

// 更新されたコンテンツをSlackに通知する
try await SlackNotifier.notify(to: slackURLs(), updates: updatedContents)
try FileHelper.save(contents: combinedContents)
try FileHelper.writeToREADME(repositories: repositories)

// マージしたコンテンツを保存する
try OutputFileHelper.save(contents: combinedContents)

// READMEを更新する
try OutputFileHelper.writeToREADME(repositories: repositories)
} catch {
Logger.app.error("\(error)")
throw error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FileHelper.swift
// OutputFileHelper.swift
// ReleaseSubscriptionsCore
//
// Created by treastrain on 2022/04/03.
Expand All @@ -11,7 +11,7 @@ import FoundationNetworking
#endif
import Logging

public struct FileHelper {
public struct OutputFileHelper {
enum Error: Swift.Error {
case invalidREADMEFormat
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Fetcher.swift
// ReleaseFetcher.swift
// ReleaseSubscriptionsCore
//
// Created by treastrain on 2022/04/02.
Expand All @@ -11,7 +11,7 @@ import FoundationNetworking
#endif
import Logging

public struct Fetcher {
public struct ReleaseFetcher {
static let decoder: JSONDecoder = {
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Parser.swift
// ReleaseSubscriptionsParser.swift
// ReleaseSubscriptionsCore
//
// Created by treastrain on 2022/04/02.
Expand All @@ -9,7 +9,7 @@ import Foundation
import Logging
import Yaml

public struct Parser {
public struct ReleaseSubscriptionsParser {
enum Error: Swift.Error {
case invalidYamlFormat
case unknownCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import XCTest

final class ReleaseSubscriptionsCoreTests: XCTestCase {
func testYamlParsing() throws {
_ = try Parser.parse()
_ = try ReleaseSubscriptionsParser.parse()
}

func testREADMELoading() throws {
_ = try FileHelper.readFromREADME()
_ = try OutputFileHelper.readFromREADME()
}

func testPastOutputsLoading() throws {
let repositories = try Parser.parse()
_ = try FileHelper.load(repositories: repositories)
let repositories = try ReleaseSubscriptionsParser.parse()
_ = try OutputFileHelper.load(repositories: repositories)
}

func testYamlSortOrderChecking() throws {
let repositories = try Parser.parse()
let repositories = try ReleaseSubscriptionsParser.parse()
let sortedRepositories = repositories
.sorted { $0.repository.lowercased() < $1.repository.lowercased() }
.sorted { $0.owner.lowercased() < $1.owner.lowercased() }
Expand Down

0 comments on commit 9197ead

Please sign in to comment.