mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-06-03 06:37:14 +08:00
Add support for pending merges (#1533)
* Add pending state * Add pending logic * Assert on `.expected` * Remove extraneous state check * Pull out combined merge status logic
This commit is contained in:
@@ -72,13 +72,10 @@ MergeButtonDelegate {
|
||||
var viewModels = [ListDiffable]()
|
||||
|
||||
if object.contexts.count > 0 {
|
||||
let success = object.contexts.reduce(true, { $0 && $1.state == .success })
|
||||
viewModels.append(IssueMergeSummaryModel(
|
||||
title: success ?
|
||||
NSLocalizedString("All checks passed", comment: "")
|
||||
: NSLocalizedString("Some checks failed", comment: ""),
|
||||
state: success ? .success : .failure
|
||||
))
|
||||
let states = object.contexts.map { $0.state }
|
||||
let (state, stateDescription) = combinedMergeStatus(for: states)
|
||||
|
||||
viewModels.append(IssueMergeSummaryModel(title: stateDescription, state: state))
|
||||
}
|
||||
|
||||
viewModels += object.contexts as [ListDiffable]
|
||||
@@ -187,4 +184,28 @@ MergeButtonDelegate {
|
||||
viewController?.present(alert, animated: trueUnlessReduceMotionEnabled)
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
private func combinedMergeStatus(for states: [StatusState]) -> (IssueMergeSummaryModel.State, String) {
|
||||
let state: IssueMergeSummaryModel.State
|
||||
let stateDescription: String
|
||||
let failureDescription = NSLocalizedString("Some checks failed", comment: "")
|
||||
switch states {
|
||||
case let states where states.contains(.failure) || states.contains(.error):
|
||||
state = .failure
|
||||
stateDescription = failureDescription
|
||||
case let states where states.contains(.pending):
|
||||
state = .pending
|
||||
stateDescription = NSLocalizedString("Merge status pending", comment: "")
|
||||
case let states where states.reduce(true, { $0 && $1 == .success }):
|
||||
state = .success
|
||||
stateDescription = NSLocalizedString("All checks passed", comment: "")
|
||||
default:
|
||||
assert(false, "This should only occur when any of the `states` are of type `.expected`, which we have no clue of when it is used. The documentation (https://developer.github.com/v4/enum/statusstate/) doesn't answer that question either.")
|
||||
state = .failure
|
||||
stateDescription = failureDescription
|
||||
}
|
||||
|
||||
return (state, stateDescription)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ final class IssueMergeSummaryCell: IssueCommentBaseCell, ListBindable {
|
||||
case .failure:
|
||||
imageViewBackground = Styles.Colors.Red.medium.color
|
||||
iconName = "merge-x"
|
||||
case .warning:
|
||||
case .warning, .pending:
|
||||
imageViewBackground = Styles.Colors.Gray.medium.color
|
||||
iconName = "merge-alert"
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ final class IssueMergeSummaryModel: ListDiffable {
|
||||
|
||||
enum State: Int {
|
||||
case success
|
||||
case pending
|
||||
case failure
|
||||
case warning
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user