From 5bf367f90415c178669f4c0d7a9c9b9fbbcd601d Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 9 Oct 2023 00:16:06 +0200 Subject: [PATCH] Restore warning commit status (#27504) 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: delvh Co-authored-by: Giteabot --- models/git/commit_status_test.go | 4 ++++ models/migrations/v1_21/v266.go | 3 --- modules/structs/commit_status.go | 14 +++++++++++--- templates/repo/commit_status.tmpl | 3 +++ templates/repo/issue/view_content/pull.tmpl | 2 +- tests/integration/pull_status_test.go | 2 ++ tests/integration/repo_commits_test.go | 4 ++++ web_src/js/components/DashboardRepoList.vue | 1 + 8 files changed, 26 insertions(+), 7 deletions(-) diff --git a/models/git/commit_status_test.go b/models/git/commit_status_test.go index a86941a0fe..2197433b3e 100644 --- a/models/git/commit_status_test.go +++ b/models/git/commit_status_test.go @@ -31,6 +31,10 @@ func TestGetCommitStatuses(t *testing.T) { 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, "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, structs.CommitStatusSuccess, statuses[2].State) assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[2].APIURL(db.DefaultContext)) diff --git a/models/migrations/v1_21/v266.go b/models/migrations/v1_21/v266.go index df85286c89..79a5f5e14c 100644 --- a/models/migrations/v1_21/v266.go +++ b/models/migrations/v1_21/v266.go @@ -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 { return err } - if _, err := sess.Exec(`UPDATE commit_status SET state='failure' WHERE state='warning'`); err != nil { - return err - } return sess.Commit() } diff --git a/modules/structs/commit_status.go b/modules/structs/commit_status.go index fda795dca6..dc880ef5eb 100644 --- a/modules/structs/commit_status.go +++ b/modules/structs/commit_status.go @@ -16,13 +16,16 @@ const ( CommitStatusError CommitStatusState = "error" // CommitStatusFailure is for when the CommitStatus is Failure CommitStatusFailure CommitStatusState = "failure" + // CommitStatusWarning is for when the CommitStatus is Warning + CommitStatusWarning CommitStatusState = "warning" ) var commitStatusPriorities = map[CommitStatusState]int{ CommitStatusError: 0, CommitStatusFailure: 1, - CommitStatusPending: 2, - CommitStatusSuccess: 3, + CommitStatusWarning: 2, + CommitStatusPending: 3, + CommitStatusSuccess: 4, } 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 // This function only handles the states defined in CommitStatusPriorities 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 { return false } @@ -63,3 +66,8 @@ func (css CommitStatusState) IsError() bool { func (css CommitStatusState) IsFailure() bool { return css == CommitStatusFailure } + +// IsWarning represents if commit status state is warning +func (css CommitStatusState) IsWarning() bool { + return css == CommitStatusWarning +} diff --git a/templates/repo/commit_status.tmpl b/templates/repo/commit_status.tmpl index ebd8a55f65..eb700ab2bb 100644 --- a/templates/repo/commit_status.tmpl +++ b/templates/repo/commit_status.tmpl @@ -11,3 +11,6 @@ {{if eq .State "failure"}} {{svg "octicon-x" 18 "commit-status icon text red"}} {{end}} +{{if eq .State "warning"}} + {{svg "gitea-exclamation" 18 "commit-status icon text yellow"}} +{{end}} diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index f9a43d7dbe..409af3a5d5 100644 --- a/templates/repo/issue/view_content/pull.tmpl +++ b/templates/repo/issue/view_content/pull.tmpl @@ -13,7 +13,7 @@ {{- else if .IsBlockedByOutdatedBranch}}red {{- else if .IsBlockedByChangedProtectedFiles}}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 .Issue.PullRequest.IsChecking}}yellow {{- else if .Issue.PullRequest.IsEmpty}}grey diff --git a/tests/integration/pull_status_test.go b/tests/integration/pull_status_test.go index 7c1f8c701e..01cb40d2cf 100644 --- a/tests/integration/pull_status_test.go +++ b/tests/integration/pull_status_test.go @@ -53,6 +53,7 @@ func TestPullCreate_CommitStatus(t *testing.T) { api.CommitStatusError, api.CommitStatusFailure, api.CommitStatusSuccess, + api.CommitStatusWarning, } statesIcons := map[api.CommitStatusState]string{ @@ -60,6 +61,7 @@ func TestPullCreate_CommitStatus(t *testing.T) { api.CommitStatusSuccess: "octicon-check", api.CommitStatusError: "gitea-exclamation", api.CommitStatusFailure: "octicon-x", + api.CommitStatusWarning: "gitea-exclamation", } testCtx := NewAPITestContext(t, "user1", "repo1", auth_model.AccessTokenScopeWriteRepository) diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index 789b5f7cc3..bb65d9e04a 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -125,6 +125,10 @@ func TestRepoCommitsWithStatusFailure(t *testing.T) { doTestRepoCommitWithStatus(t, "failure", "octicon-x", "red") } +func TestRepoCommitsWithStatusWarning(t *testing.T) { + doTestRepoCommitWithStatus(t, "warning", "gitea-exclamation", "yellow") +} + func TestRepoCommitsStatusParallel(t *testing.T) { defer tests.PrepareTestEnv(t)() diff --git a/web_src/js/components/DashboardRepoList.vue b/web_src/js/components/DashboardRepoList.vue index 5ff51168cb..f7cea32fb6 100644 --- a/web_src/js/components/DashboardRepoList.vue +++ b/web_src/js/components/DashboardRepoList.vue @@ -12,6 +12,7 @@ const commitStatus = { success: {name: 'octicon-check', color: 'green'}, error: {name: 'gitea-exclamation', color: 'red'}, failure: {name: 'octicon-x', color: 'red'}, + warning: {name: 'gitea-exclamation', color: 'yellow'}, }; const sfc = {