diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-22 11:46:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-22 11:46:04 +0800 |
commit | 81daf26878d8a7e14c172fc39fc55c36281b1898 (patch) | |
tree | 9d4d43bf2e12cdc9c56196938d0618e9577cd1b6 /models | |
parent | cca13ae2acf1ef7a3b0516a8774dff0365b73697 (diff) | |
download | gitea-81daf26878d8a7e14c172fc39fc55c36281b1898.tar.gz gitea-81daf26878d8a7e14c172fc39fc55c36281b1898.zip |
Fix wrong hint when status checking is running on pull request view (#9886)
* Fix wrong hint when status checking is running on pull request view
* fix lint
* fix test
* fix test
* fix wrong tmpl
* fix import
* rename function name
Diffstat (limited to 'models')
-rw-r--r-- | models/commit_status.go | 59 | ||||
-rw-r--r-- | models/commit_status_test.go | 11 |
2 files changed, 19 insertions, 51 deletions
diff --git a/models/commit_status.go b/models/commit_status.go index 4e0f8166f3..4102e731e1 100644 --- a/models/commit_status.go +++ b/models/commit_status.go @@ -19,52 +19,19 @@ import ( "xorm.io/xorm" ) -// CommitStatusState holds the state of a Status -// It can be "pending", "success", "error", "failure", and "warning" -type CommitStatusState string - -// IsWorseThan returns true if this State is worse than the given State -func (css CommitStatusState) IsWorseThan(css2 CommitStatusState) bool { - switch css { - case CommitStatusError: - return true - case CommitStatusFailure: - return css2 != CommitStatusError - case CommitStatusWarning: - return css2 != CommitStatusError && css2 != CommitStatusFailure - case CommitStatusSuccess: - return css2 != CommitStatusError && css2 != CommitStatusFailure && css2 != CommitStatusWarning - default: - return css2 != CommitStatusError && css2 != CommitStatusFailure && css2 != CommitStatusWarning && css2 != CommitStatusSuccess - } -} - -const ( - // CommitStatusPending is for when the Status is Pending - CommitStatusPending CommitStatusState = "pending" - // CommitStatusSuccess is for when the Status is Success - CommitStatusSuccess CommitStatusState = "success" - // CommitStatusError is for when the Status is Error - CommitStatusError CommitStatusState = "error" - // CommitStatusFailure is for when the Status is Failure - CommitStatusFailure CommitStatusState = "failure" - // CommitStatusWarning is for when the Status is Warning - CommitStatusWarning CommitStatusState = "warning" -) - // CommitStatus holds a single Status of a single Commit type CommitStatus struct { - ID int64 `xorm:"pk autoincr"` - Index int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` - RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` - Repo *Repository `xorm:"-"` - State CommitStatusState `xorm:"VARCHAR(7) NOT NULL"` - SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` - TargetURL string `xorm:"TEXT"` - Description string `xorm:"TEXT"` - ContextHash string `xorm:"char(40) index"` - Context string `xorm:"TEXT"` - Creator *User `xorm:"-"` + ID int64 `xorm:"pk autoincr"` + Index int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` + RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` + Repo *Repository `xorm:"-"` + State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"` + SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` + TargetURL string `xorm:"TEXT"` + Description string `xorm:"TEXT"` + ContextHash string `xorm:"char(40) index"` + Context string `xorm:"TEXT"` + Creator *User `xorm:"-"` CreatorID int64 CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` @@ -118,9 +85,9 @@ func (status *CommitStatus) APIFormat() *api.Status { // CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus { var lastStatus *CommitStatus - var state CommitStatusState + var state api.CommitStatusState for _, status := range statuses { - if status.State.IsWorseThan(state) { + if status.State.NoBetterThan(state) { state = status.State lastStatus = status } diff --git a/models/commit_status_test.go b/models/commit_status_test.go index 97783ae6f1..90d72cd74d 100644 --- a/models/commit_status_test.go +++ b/models/commit_status_test.go @@ -7,6 +7,7 @@ package models import ( "testing" + "code.gitea.io/gitea/modules/structs" "github.com/stretchr/testify/assert" ) @@ -23,22 +24,22 @@ func TestGetCommitStatuses(t *testing.T) { assert.Len(t, statuses, 5) assert.Equal(t, "ci/awesomeness", statuses[0].Context) - assert.Equal(t, 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()) assert.Equal(t, "cov/awesomeness", statuses[1].Context) - assert.Equal(t, CommitStatusWarning, statuses[1].State) + 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()) assert.Equal(t, "cov/awesomeness", statuses[2].Context) - assert.Equal(t, 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()) assert.Equal(t, "ci/awesomeness", statuses[3].Context) - assert.Equal(t, CommitStatusFailure, statuses[3].State) + assert.Equal(t, structs.CommitStatusFailure, statuses[3].State) assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[3].APIURL()) assert.Equal(t, "deploy/awesomeness", statuses[4].Context) - assert.Equal(t, CommitStatusError, statuses[4].State) + assert.Equal(t, structs.CommitStatusError, statuses[4].State) assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[4].APIURL()) } |