diff --git a/Pulse/PullRequestAPI.swift b/Pulse/PullRequestAPI.swift index 9efc420..3a82278 100644 --- a/Pulse/PullRequestAPI.swift +++ b/Pulse/PullRequestAPI.swift @@ -55,7 +55,7 @@ func - (left: PullRequests, right: PullRequests) -> PullRequests { return left.filter { !rightIDs.contains($0.id) } } -struct PullRequestAPI { +actor PullRequestAPI { private let client: ApolloClient init(_ githubToken: String) { diff --git a/Pulse/PullRequestModel.swift b/Pulse/PullRequestModel.swift index 40a048c..e2b565a 100644 --- a/Pulse/PullRequestModel.swift +++ b/Pulse/PullRequestModel.swift @@ -1,12 +1,33 @@ import Foundation +import SwiftUI @MainActor class PullRequestModel: ObservableObject { // TODO: + @AppStorage("githubQuery") private var githubQuery = Constants.defaultGithubQuery + @Published var settled: PullRequests = [] + @Published var pending: PullRequests = [] @Published var updatedAt: Date? + @Published var error: GitHubError? func update(_ api: PullRequestAPI) async { - // TODO: - updatedAt = Date() + do { + let pulls = try await api.fetch(githubQuery) + + for pull in pulls { + if pull.pending { + pending.append(pull) + } else { + settled.append(pull) + } + } + + // TODO: + updatedAt = Date() + } catch let ghErr as GitHubError { + error = ghErr + } catch { + Logger.shared.error("failed to get pull requests: \(error)") + } } }