mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 10:18:38 +00:00
Keeping consistent between UI and API about combined commit status state and fix some bugs (#34562)
Extract from #34531 ## Move Commit status state to a standalone package Move the state from `structs` to `commitstatus` package. It also introduce `CommitStatusStates` so that the combine function could be used from UI and API logic. ## Combined commit status Changed This PR will follow Github's combined commit status. Before this PR, every commit status could be a combined one. According to https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#get-the-combined-status-for-a-specific-reference > Additionally, a combined state is returned. The state is one of: > failure if any of the contexts report as error or failure > pending if there are no statuses or a context is pending > success if the latest status for all contexts is success This PR will follow that rule and remove the `NoBetterThan` logic. This also fixes the inconsistent between UI and API. In the API convert package, it has implemented this which is different from the UI. It also fixed the missing `URL` and `CommitURL` in the API. ## `CalcCommitStatus` return nil if there is no commit statuses The behavior of `CalcCommitStatus` is changed. If the parameter commit statuses is empty, it will return nil. The reference places should check the returned value themselves.
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/commitstatus"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
@@ -55,20 +56,20 @@ func TestPullCreate_CommitStatus(t *testing.T) {
|
||||
|
||||
commitID := path.Base(commitURL)
|
||||
|
||||
statusList := []api.CommitStatusState{
|
||||
api.CommitStatusPending,
|
||||
api.CommitStatusError,
|
||||
api.CommitStatusFailure,
|
||||
api.CommitStatusSuccess,
|
||||
api.CommitStatusWarning,
|
||||
statusList := []commitstatus.CommitStatusState{
|
||||
commitstatus.CommitStatusPending,
|
||||
commitstatus.CommitStatusError,
|
||||
commitstatus.CommitStatusFailure,
|
||||
commitstatus.CommitStatusSuccess,
|
||||
commitstatus.CommitStatusWarning,
|
||||
}
|
||||
|
||||
statesIcons := map[api.CommitStatusState]string{
|
||||
api.CommitStatusPending: "octicon-dot-fill",
|
||||
api.CommitStatusSuccess: "octicon-check",
|
||||
api.CommitStatusError: "gitea-exclamation",
|
||||
api.CommitStatusFailure: "octicon-x",
|
||||
api.CommitStatusWarning: "gitea-exclamation",
|
||||
statesIcons := map[commitstatus.CommitStatusState]string{
|
||||
commitstatus.CommitStatusPending: "octicon-dot-fill",
|
||||
commitstatus.CommitStatusSuccess: "octicon-check",
|
||||
commitstatus.CommitStatusError: "gitea-exclamation",
|
||||
commitstatus.CommitStatusFailure: "octicon-x",
|
||||
commitstatus.CommitStatusWarning: "gitea-exclamation",
|
||||
}
|
||||
|
||||
testCtx := NewAPITestContext(t, "user1", "repo1", auth_model.AccessTokenScopeWriteRepository)
|
||||
@@ -99,7 +100,7 @@ func TestPullCreate_CommitStatus(t *testing.T) {
|
||||
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user1", Name: "repo1"})
|
||||
css := unittest.AssertExistsAndLoadBean(t, &git_model.CommitStatusSummary{RepoID: repo1.ID, SHA: commitID})
|
||||
assert.Equal(t, api.CommitStatusWarning, css.State)
|
||||
assert.Equal(t, commitstatus.CommitStatusSuccess, css.State)
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user