mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +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:
@@ -26,6 +26,7 @@ import (
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/commitstatus"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/lfs"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@@ -713,7 +714,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
|
||||
|
||||
commitID := path.Base(commitURL)
|
||||
|
||||
addCommitStatus := func(status api.CommitStatusState) func(*testing.T) {
|
||||
addCommitStatus := func(status commitstatus.CommitStatusState) func(*testing.T) {
|
||||
return doAPICreateCommitStatus(ctx, commitID, api.CreateStatusOption{
|
||||
State: status,
|
||||
TargetURL: "http://test.ci/",
|
||||
@@ -723,7 +724,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
|
||||
}
|
||||
|
||||
// Call API to add Pending status for commit
|
||||
t.Run("CreateStatus", addCommitStatus(api.CommitStatusPending))
|
||||
t.Run("CreateStatus", addCommitStatus(commitstatus.CommitStatusPending))
|
||||
|
||||
// Cancel not existing auto merge
|
||||
ctx.ExpectedCode = http.StatusNotFound
|
||||
@@ -752,7 +753,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
|
||||
assert.False(t, pr.HasMerged)
|
||||
|
||||
// Call API to add Failure status for commit
|
||||
t.Run("CreateStatus", addCommitStatus(api.CommitStatusFailure))
|
||||
t.Run("CreateStatus", addCommitStatus(commitstatus.CommitStatusFailure))
|
||||
|
||||
// Check pr status
|
||||
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
|
||||
@@ -760,7 +761,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
|
||||
assert.False(t, pr.HasMerged)
|
||||
|
||||
// Call API to add Success status for commit
|
||||
t.Run("CreateStatus", addCommitStatus(api.CommitStatusSuccess))
|
||||
t.Run("CreateStatus", addCommitStatus(commitstatus.CommitStatusSuccess))
|
||||
|
||||
// wait to let gitea merge stuff
|
||||
time.Sleep(time.Second)
|
||||
|
Reference in New Issue
Block a user