mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-23 09:18:15 -06:00
External CI can report any commit status state, but only the six known states rendered an icon, so `running` or something like `stage-1` showed nothing. `running` is now an official state rendered with the same spinner as Actions, and any other state gets a fallback icon. The combined status still treats both as pending. A state longer than the 7-character column (e.g. `in_progress`) caused a 500. It now returns 422, as does an empty state. Widening the column instead would need a migration, happy to do that in a follow-up if preferred. | Before | After | | --- | --- | | <img width="1904" height="654" alt="before" src="https://github.com/user-attachments/assets/811c6a4e-7b5a-4919-8d86-ec586d9f9bfb" /> | <img width="1919" height="675" alt="after" src="https://github.com/user-attachments/assets/a088c70d-47fe-40c5-93f7-43d1bacfa77e" />| Fixes: https://github.com/go-gitea/gitea/issues/39608
85 lines
2.9 KiB
Go
85 lines
2.9 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package commitstatus
|
|
|
|
// CommitStatusState holds the state of a CommitStatus
|
|
// swagger:enum CommitStatusState
|
|
type CommitStatusState string //nolint:revive // export stutter
|
|
|
|
const (
|
|
// CommitStatusPending is for when the CommitStatus is Pending
|
|
CommitStatusPending CommitStatusState = "pending"
|
|
// CommitStatusRunning is for when the CommitStatus is Running
|
|
CommitStatusRunning CommitStatusState = "running"
|
|
// CommitStatusSuccess is for when the CommitStatus is Success
|
|
CommitStatusSuccess CommitStatusState = "success"
|
|
// CommitStatusError is for when the CommitStatus is Error
|
|
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"
|
|
// CommitStatusSkipped is for when CommitStatus is Skipped
|
|
CommitStatusSkipped CommitStatusState = "skipped"
|
|
)
|
|
|
|
func (css CommitStatusState) String() string {
|
|
return string(css)
|
|
}
|
|
|
|
// IsPending represents if commit status state is pending
|
|
func (css CommitStatusState) IsPending() bool {
|
|
return css == CommitStatusPending
|
|
}
|
|
|
|
// IsSuccess represents if commit status state is success
|
|
func (css CommitStatusState) IsSuccess() bool {
|
|
return css == CommitStatusSuccess
|
|
}
|
|
|
|
// IsError represents if commit status state is error
|
|
func (css CommitStatusState) IsError() bool {
|
|
return css == CommitStatusError
|
|
}
|
|
|
|
// IsFailure represents if commit status state is failure
|
|
func (css CommitStatusState) IsFailure() bool {
|
|
return css == CommitStatusFailure
|
|
}
|
|
|
|
// IsWarning represents if commit status state is warning
|
|
func (css CommitStatusState) IsWarning() bool {
|
|
return css == CommitStatusWarning
|
|
}
|
|
|
|
// IsSkipped represents if commit status state is skipped
|
|
func (css CommitStatusState) IsSkipped() bool {
|
|
return css == CommitStatusSkipped
|
|
}
|
|
|
|
type CommitStatusStates []CommitStatusState //nolint:revive // export stutter
|
|
|
|
// According to https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#get-the-combined-status-for-a-specific-reference
|
|
// > Additionally, a combined state is returned. The state is one of:
|
|
// > failure if any of the contexts report as error or failure
|
|
// > failure if any of the contexts report as warning (Gitea specific behavior)
|
|
// > pending if there are no statuses or a context is pending
|
|
// > success if the latest status for all contexts is success
|
|
func (css CommitStatusStates) Combine() CommitStatusState {
|
|
successCnt := 0
|
|
for _, state := range css {
|
|
switch {
|
|
case state.IsError() || state.IsFailure() || state.IsWarning():
|
|
return CommitStatusFailure
|
|
case state.IsPending():
|
|
case state.IsSuccess() || state.IsSkipped():
|
|
successCnt++
|
|
}
|
|
}
|
|
if successCnt > 0 && successCnt == len(css) {
|
|
return CommitStatusSuccess
|
|
}
|
|
return CommitStatusPending
|
|
}
|