Skip to content

Commit 7a687ca

Browse files
yp05327GiteaBot
andauthored
Fix wrong commit status in web ui (#26121)
Before: ![image](https://github.com/go-gitea/gitea/assets/18380374/8c5643b5-5c16-4674-9fe6-9e7fa2dda0b9) After: ![image](https://github.com/go-gitea/gitea/assets/18380374/caf8891b-14df-418d-a7eb-977b54b9e9be) There's a bug in the recent logic, `CalcCommitStatus` will always return the first item of `statuses` or error status, because `state` is defined with default value which should be `CommitStatusSuccess` Then ``` golang if status.State.NoBetterThan(state) { ``` this `if` will always return false unless `status.State = CommitStatusError` which makes no sense. So `lastStatus` will always be `nil` or error status. Then we will always return the first item of `statuses` here or only return error status, and this is why in the first picture the commit status is `Success` but not `Failure`. https://github.com/go-gitea/gitea/blob/af1ffbcd63569df8646b20c524378f25710f129e/models/git/commit_status.go#L204-L211 Co-authored-by: Giteabot <[email protected]>
1 parent ab72f7e commit 7a687ca

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

models/git/commit_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (status *CommitStatus) APIURL(ctx context.Context) string {
194194
// CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc
195195
func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus {
196196
var lastStatus *CommitStatus
197-
var state api.CommitStatusState
197+
state := api.CommitStatusSuccess
198198
for _, status := range statuses {
199199
if status.State.NoBetterThan(state) {
200200
state = status.State

0 commit comments

Comments
 (0)