-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
426f698
commit fa70386
Showing
2 changed files
with
24 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)") | ||
} | ||
} | ||
} |