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:
Bas Broek
2018-02-21 01:27:32 +01:00
committed by Ryan Nystrom
parent 12fb61a318
commit 7c79f6a2af
3 changed files with 30 additions and 8 deletions

View File

@@ -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)
}
}

View File

@@ -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"
}

View File

@@ -13,6 +13,7 @@ final class IssueMergeSummaryModel: ListDiffable {
enum State: Int {
case success
case pending
case failure
case warning
}