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/commit_status.go | |
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/commit_status.go')
-rw-r--r-- | models/commit_status.go | 59 |
1 files changed, 13 insertions, 46 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 } |