mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-04-29 04:24:58 +08:00
Simply merge status logic (#1818)
This commit is contained in:
@@ -9,27 +9,23 @@
|
||||
import Foundation
|
||||
|
||||
enum MergeHelper {
|
||||
|
||||
static func combinedMergeStatus(for states: [StatusState]) -> (state: IssueMergeSummaryModel.State, description: String) {
|
||||
assert(!states.isEmpty, "Should only check merge status when there is at least one state")
|
||||
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.containsOnly(.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
|
||||
var hasError = false, hasPending = false
|
||||
for state in states {
|
||||
switch state {
|
||||
case .error, .failure, .expected, .__unknown: hasError = true
|
||||
case .pending: hasPending = true
|
||||
case .success: break
|
||||
}
|
||||
}
|
||||
|
||||
return (state, stateDescription)
|
||||
if hasError {
|
||||
return (.failure, NSLocalizedString("Some checks failed", comment: ""))
|
||||
} else if hasPending {
|
||||
return (.pending, NSLocalizedString("Merge status pending", comment: ""))
|
||||
} else {
|
||||
return (.success, NSLocalizedString("All checks passed", comment: ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,12 @@ class MergeTests: XCTestCase {
|
||||
XCTAssertEqual(
|
||||
MergeHelper.combinedMergeStatus(for: [.failure, .pending]).state,
|
||||
.failure)
|
||||
XCTAssertEqual(
|
||||
MergeHelper.combinedMergeStatus(for: [.pending, .failure]).state,
|
||||
.failure)
|
||||
XCTAssertEqual(
|
||||
MergeHelper.combinedMergeStatus(for: [.failure, .pending, .success]).state,
|
||||
.failure)
|
||||
}
|
||||
|
||||
func test_mergeStatuses_containsFailure_andError() {
|
||||
@@ -63,6 +69,12 @@ class MergeTests: XCTestCase {
|
||||
XCTAssertEqual(
|
||||
MergeHelper.combinedMergeStatus(for: [.pending, .success]).state,
|
||||
.pending)
|
||||
XCTAssertEqual(
|
||||
MergeHelper.combinedMergeStatus(for: [.success, .pending]).state,
|
||||
.pending)
|
||||
XCTAssertEqual(
|
||||
MergeHelper.combinedMergeStatus(for: [.success, .pending, .success]).state,
|
||||
.pending)
|
||||
}
|
||||
|
||||
func test_mergeStatuses_containsOnlySuccess() {
|
||||
|
||||
Reference in New Issue
Block a user