Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore warning commit status #27504

Merged
merged 6 commits into from Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions models/git/commit_status_test.go
Expand Up @@ -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))
Expand Down
3 changes: 0 additions & 3 deletions models/migrations/v1_21/v266.go
Expand Up @@ -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()
}
12 changes: 10 additions & 2 deletions modules/structs/commit_status.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions templates/repo/commit_status.tmpl
Expand Up @@ -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}}
2 changes: 1 addition & 1 deletion templates/repo/issue/view_content/pull.tmpl
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/pull_status_test.go
Expand Up @@ -53,13 +53,15 @@ func TestPullCreate_CommitStatus(t *testing.T) {
api.CommitStatusError,
api.CommitStatusFailure,
api.CommitStatusSuccess,
api.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",
}

testCtx := NewAPITestContext(t, "user1", "repo1", auth_model.AccessTokenScopeWriteRepository)
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/repo_commits_test.go
Expand Up @@ -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)()

Expand Down
1 change: 1 addition & 0 deletions web_src/js/components/DashboardRepoList.vue
Expand Up @@ -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 = {
Expand Down