mirror of
1
Fork 0

Restore warning commit status (#27504) (#27529)

Backport #27504 by @silverwind

Partial revert of https://github.com/go-gitea/gitea/pull/25839. This
commit status is used by a number of external integrations, so I think
we should not remove it (See
https://github.com/go-gitea/gitea/pull/25839#issuecomment-1729002077).
This is a rare case where an existing migration needed to be alterted to
avoid data loss.

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
Giteabot 2023-10-09 11:56:02 +08:00 committed by GitHub
parent 8419897fba
commit fb5ae2ab94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 7 deletions

View File

@ -31,6 +31,10 @@ func TestGetCommitStatuses(t *testing.T) {
assert.Equal(t, structs.CommitStatusPending, statuses[0].State) assert.Equal(t, structs.CommitStatusPending, statuses[0].State)
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[0].APIURL(db.DefaultContext)) assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[0].APIURL(db.DefaultContext))
assert.Equal(t, "cov/awesomeness", statuses[1].Context)
assert.Equal(t, structs.CommitStatusWarning, statuses[1].State)
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[1].APIURL(db.DefaultContext))
assert.Equal(t, "cov/awesomeness", statuses[2].Context) assert.Equal(t, "cov/awesomeness", statuses[2].Context)
assert.Equal(t, structs.CommitStatusSuccess, statuses[2].State) assert.Equal(t, structs.CommitStatusSuccess, statuses[2].State)
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[2].APIURL(db.DefaultContext)) assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[2].APIURL(db.DefaultContext))

View File

@ -18,9 +18,6 @@ func ReduceCommitStatus(x *xorm.Engine) error {
if _, err := sess.Exec(`UPDATE commit_status SET state='pending' WHERE state='running'`); err != nil { if _, err := sess.Exec(`UPDATE commit_status SET state='pending' WHERE state='running'`); err != nil {
return err return err
} }
if _, err := sess.Exec(`UPDATE commit_status SET state='failure' WHERE state='warning'`); err != nil {
return err
}
return sess.Commit() return sess.Commit()
} }

View File

@ -16,13 +16,16 @@ const (
CommitStatusError CommitStatusState = "error" CommitStatusError CommitStatusState = "error"
// CommitStatusFailure is for when the CommitStatus is Failure // CommitStatusFailure is for when the CommitStatus is Failure
CommitStatusFailure CommitStatusState = "failure" CommitStatusFailure CommitStatusState = "failure"
// CommitStatusWarning is for when the CommitStatus is Warning
CommitStatusWarning CommitStatusState = "warning"
) )
var commitStatusPriorities = map[CommitStatusState]int{ var commitStatusPriorities = map[CommitStatusState]int{
CommitStatusError: 0, CommitStatusError: 0,
CommitStatusFailure: 1, CommitStatusFailure: 1,
CommitStatusPending: 2, CommitStatusWarning: 2,
CommitStatusSuccess: 3, CommitStatusPending: 3,
CommitStatusSuccess: 4,
} }
func (css CommitStatusState) String() string { func (css CommitStatusState) String() string {
@ -32,7 +35,7 @@ func (css CommitStatusState) String() string {
// NoBetterThan returns true if this State is no better than the given State // NoBetterThan returns true if this State is no better than the given State
// This function only handles the states defined in CommitStatusPriorities // This function only handles the states defined in CommitStatusPriorities
func (css CommitStatusState) NoBetterThan(css2 CommitStatusState) bool { func (css CommitStatusState) NoBetterThan(css2 CommitStatusState) bool {
// NoBetterThan only handles the 4 states above // NoBetterThan only handles the 5 states above
if _, exist := commitStatusPriorities[css]; !exist { if _, exist := commitStatusPriorities[css]; !exist {
return false return false
} }
@ -63,3 +66,8 @@ func (css CommitStatusState) IsError() bool {
func (css CommitStatusState) IsFailure() bool { func (css CommitStatusState) IsFailure() bool {
return css == CommitStatusFailure return css == CommitStatusFailure
} }
// IsWarning represents if commit status state is warning
func (css CommitStatusState) IsWarning() bool {
return css == CommitStatusWarning
}

View File

@ -11,3 +11,6 @@
{{if eq .State "failure"}} {{if eq .State "failure"}}
{{svg "octicon-x" 18 "commit-status icon text red"}} {{svg "octicon-x" 18 "commit-status icon text red"}}
{{end}} {{end}}
{{if eq .State "warning"}}
{{svg "gitea-exclamation" 18 "commit-status icon text yellow"}}
{{end}}

View File

@ -13,7 +13,7 @@
{{- else if .IsBlockedByOutdatedBranch}}red {{- else if .IsBlockedByOutdatedBranch}}red
{{- else if .IsBlockedByChangedProtectedFiles}}red {{- else if .IsBlockedByChangedProtectedFiles}}red
{{- else if and .EnableStatusCheck (or .RequiredStatusCheckState.IsFailure .RequiredStatusCheckState.IsError)}}red {{- else if and .EnableStatusCheck (or .RequiredStatusCheckState.IsFailure .RequiredStatusCheckState.IsError)}}red
{{- else if and .EnableStatusCheck (or (not $.LatestCommitStatus) .RequiredStatusCheckState.IsPending)}}yellow {{- else if and .EnableStatusCheck (or (not $.LatestCommitStatus) .RequiredStatusCheckState.IsPending .RequiredStatusCheckState.IsWarning)}}yellow
{{- else if and .AllowMerge .RequireSigned (not .WillSign)}}red {{- else if and .AllowMerge .RequireSigned (not .WillSign)}}red
{{- else if .Issue.PullRequest.IsChecking}}yellow {{- else if .Issue.PullRequest.IsChecking}}yellow
{{- else if .Issue.PullRequest.IsEmpty}}grey {{- else if .Issue.PullRequest.IsEmpty}}grey

View File

@ -53,6 +53,7 @@ func TestPullCreate_CommitStatus(t *testing.T) {
api.CommitStatusError, api.CommitStatusError,
api.CommitStatusFailure, api.CommitStatusFailure,
api.CommitStatusSuccess, api.CommitStatusSuccess,
api.CommitStatusWarning,
} }
statesIcons := map[api.CommitStatusState]string{ statesIcons := map[api.CommitStatusState]string{
@ -60,6 +61,7 @@ func TestPullCreate_CommitStatus(t *testing.T) {
api.CommitStatusSuccess: "octicon-check", api.CommitStatusSuccess: "octicon-check",
api.CommitStatusError: "gitea-exclamation", api.CommitStatusError: "gitea-exclamation",
api.CommitStatusFailure: "octicon-x", api.CommitStatusFailure: "octicon-x",
api.CommitStatusWarning: "gitea-exclamation",
} }
testCtx := NewAPITestContext(t, "user1", "repo1", auth_model.AccessTokenScopeWriteRepository) testCtx := NewAPITestContext(t, "user1", "repo1", auth_model.AccessTokenScopeWriteRepository)

View File

@ -125,6 +125,10 @@ func TestRepoCommitsWithStatusFailure(t *testing.T) {
doTestRepoCommitWithStatus(t, "failure", "octicon-x", "red") doTestRepoCommitWithStatus(t, "failure", "octicon-x", "red")
} }
func TestRepoCommitsWithStatusWarning(t *testing.T) {
doTestRepoCommitWithStatus(t, "warning", "gitea-exclamation", "yellow")
}
func TestRepoCommitsStatusParallel(t *testing.T) { func TestRepoCommitsStatusParallel(t *testing.T) {
defer tests.PrepareTestEnv(t)() defer tests.PrepareTestEnv(t)()

View File

@ -12,6 +12,7 @@ const commitStatus = {
success: {name: 'octicon-check', color: 'green'}, success: {name: 'octicon-check', color: 'green'},
error: {name: 'gitea-exclamation', color: 'red'}, error: {name: 'gitea-exclamation', color: 'red'},
failure: {name: 'octicon-x', color: 'red'}, failure: {name: 'octicon-x', color: 'red'},
warning: {name: 'gitea-exclamation', color: 'yellow'},
}; };
const sfc = { const sfc = {