mirror of
https://github.com/go-gitea/gitea.git
synced 2026-12-04 15:54:57 +00:00
enhance: support running and unknown commit status states (#40396)
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
This commit is contained in:
1 parent
67463386b1
commit
d4101fda0c
9 files changed
+46
-20
No files matched your search
@@ -33,6 +33,9 @@ import (
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// CommitStatusStateMaxLength must match the size of the CommitStatus.State column
|
||||
const CommitStatusStateMaxLength = 7
|
||||
|
||||
// CommitStatus holds a single Status of a single Commit
|
||||
type CommitStatus struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -10,6 +10,8 @@ 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
|
||||
|
||||
@@ -43,6 +43,11 @@ func TestCombine(t *testing.T) {
|
||||
states: CommitStatusStates{CommitStatusWarning},
|
||||
expected: CommitStatusFailure,
|
||||
},
|
||||
{
|
||||
name: "running",
|
||||
states: CommitStatusStates{CommitStatusRunning},
|
||||
expected: CommitStatusPending,
|
||||
},
|
||||
// 2 states
|
||||
{
|
||||
name: "pending and success",
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
type CommitStatus struct {
|
||||
// ID is the unique identifier for the commit status
|
||||
ID int64 `json:"id"`
|
||||
// State represents the status state (pending, success, error, failure)
|
||||
// State represents the status state (pending, running, success, error, failure, warning, skipped)
|
||||
State commitstatus.CommitStatusState `json:"status"`
|
||||
// TargetURL is the URL to link to for more details
|
||||
TargetURL string `json:"target_url"`
|
||||
@@ -51,7 +51,7 @@ type CombinedStatus struct {
|
||||
|
||||
// CreateStatusOption holds the information needed to create a new CommitStatus for a Commit
|
||||
type CreateStatusOption struct {
|
||||
// State represents the status state to set (pending, success, error, failure)
|
||||
// State represents the status state to set (pending, running, success, error, failure, warning, skipped)
|
||||
State commitstatus.CommitStatusState `json:"state"`
|
||||
// TargetURL is the URL to link to for more details
|
||||
TargetURL string `json:"target_url"`
|
||||
|
||||
@@ -6,6 +6,7 @@ package repo
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"unicode/utf8"
|
||||
|
||||
"gitea.dev/models/db"
|
||||
git_model "gitea.dev/models/git"
|
||||
@@ -56,6 +57,10 @@ func NewCommitStatus(ctx *context.APIContext) {
|
||||
ctx.APIError(http.StatusBadRequest, "sha not provided")
|
||||
return
|
||||
}
|
||||
if stateLen := utf8.RuneCountInString(string(form.State)); stateLen == 0 || stateLen > git_model.CommitStatusStateMaxLength {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("state must be 1 to %d characters", git_model.CommitStatusStateMaxLength))
|
||||
return
|
||||
}
|
||||
status := &git_model.CommitStatus{
|
||||
State: form.State,
|
||||
TargetURL: form.TargetURL,
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
<!-- make sure this matches the color logic in web_src/js/components/DashboardRepoList.vue -->
|
||||
<!-- make sure the combined states match the color logic in web_src/js/components/DashboardRepoList.vue -->
|
||||
{{if eq .State "pending"}}
|
||||
{{svg "octicon-dot-fill" 18 "commit-status icon tw-text-yellow"}}
|
||||
{{end}}
|
||||
{{if eq .State "success"}}
|
||||
{{else if eq .State "running"}}
|
||||
{{svg "gitea-running" 18 "commit-status icon tw-text-yellow rotate-clockwise"}}
|
||||
{{else if eq .State "success"}}
|
||||
{{svg "octicon-check" 18 "commit-status icon tw-text-green"}}
|
||||
{{end}}
|
||||
{{if eq .State "error"}}
|
||||
{{else if eq .State "error"}}
|
||||
{{svg "gitea-exclamation" 18 "commit-status icon tw-text-red"}}
|
||||
{{end}}
|
||||
{{if eq .State "failure"}}
|
||||
{{else if eq .State "failure"}}
|
||||
{{svg "octicon-x" 18 "commit-status icon tw-text-red"}}
|
||||
{{end}}
|
||||
{{if eq .State "warning"}}
|
||||
{{else if eq .State "warning"}}
|
||||
{{svg "gitea-exclamation" 18 "commit-status icon tw-text-yellow"}}
|
||||
{{end}}
|
||||
{{if eq .State "skipped"}}
|
||||
{{else if eq .State "skipped"}}
|
||||
{{svg "octicon-skip" 18 "commit-status icon tw-text-text-light"}}
|
||||
{{else}}{{/* external CI may report any state */}}
|
||||
{{svg "octicon-question" 18 "commit-status icon tw-text-text-light"}}
|
||||
{{end}}
|
||||
+3
-2
@@ -3556,7 +3556,7 @@
|
||||
"$ref": "#/components/schemas/CommitStatusState"
|
||||
}
|
||||
],
|
||||
"description": "State represents the status state (pending, success, error, failure)"
|
||||
"description": "State represents the status state (pending, running, success, error, failure, warning, skipped)"
|
||||
},
|
||||
"target_url": {
|
||||
"description": "TargetURL is the URL to link to for more details",
|
||||
@@ -3582,6 +3582,7 @@
|
||||
"CommitStatusState": {
|
||||
"enum": [
|
||||
"pending",
|
||||
"running",
|
||||
"success",
|
||||
"error",
|
||||
"failure",
|
||||
@@ -4929,7 +4930,7 @@
|
||||
"$ref": "#/components/schemas/CommitStatusState"
|
||||
}
|
||||
],
|
||||
"description": "State represents the status state to set (pending, success, error, failure)"
|
||||
"description": "State represents the status state to set (pending, running, success, error, failure, warning, skipped)"
|
||||
},
|
||||
"target_url": {
|
||||
"description": "TargetURL is the URL to link to for more details",
|
||||
|
||||
+8
-5
@@ -25763,13 +25763,14 @@
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"pending",
|
||||
"running",
|
||||
"success",
|
||||
"error",
|
||||
"failure",
|
||||
"warning",
|
||||
"skipped"
|
||||
],
|
||||
"x-go-enum-desc": "pending CommitStatusPending is for when the CommitStatus is Pending\nsuccess CommitStatusSuccess is for when the CommitStatus is Success\nerror CommitStatusError is for when the CommitStatus is Error\nfailure CommitStatusFailure is for when the CommitStatus is Failure\nwarning CommitStatusWarning is for when the CommitStatus is Warning\nskipped CommitStatusSkipped is for when CommitStatus is Skipped",
|
||||
"x-go-enum-desc": "pending CommitStatusPending is for when the CommitStatus is Pending\nrunning CommitStatusRunning is for when the CommitStatus is Running\nsuccess CommitStatusSuccess is for when the CommitStatus is Success\nerror CommitStatusError is for when the CommitStatus is Error\nfailure CommitStatusFailure is for when the CommitStatus is Failure\nwarning CommitStatusWarning is for when the CommitStatus is Warning\nskipped CommitStatusSkipped is for when CommitStatus is Skipped",
|
||||
"x-go-name": "State"
|
||||
},
|
||||
"statuses": {
|
||||
@@ -26017,17 +26018,18 @@
|
||||
"x-go-name": "ID"
|
||||
},
|
||||
"status": {
|
||||
"description": "State represents the status state (pending, success, error, failure)",
|
||||
"description": "State represents the status state (pending, running, success, error, failure, warning, skipped)",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"pending",
|
||||
"running",
|
||||
"success",
|
||||
"error",
|
||||
"failure",
|
||||
"warning",
|
||||
"skipped"
|
||||
],
|
||||
"x-go-enum-desc": "pending CommitStatusPending is for when the CommitStatus is Pending\nsuccess CommitStatusSuccess is for when the CommitStatus is Success\nerror CommitStatusError is for when the CommitStatus is Error\nfailure CommitStatusFailure is for when the CommitStatus is Failure\nwarning CommitStatusWarning is for when the CommitStatus is Warning\nskipped CommitStatusSkipped is for when CommitStatus is Skipped",
|
||||
"x-go-enum-desc": "pending CommitStatusPending is for when the CommitStatus is Pending\nrunning CommitStatusRunning is for when the CommitStatus is Running\nsuccess CommitStatusSuccess is for when the CommitStatus is Success\nerror CommitStatusError is for when the CommitStatus is Error\nfailure CommitStatusFailure is for when the CommitStatus is Failure\nwarning CommitStatusWarning is for when the CommitStatus is Warning\nskipped CommitStatusSkipped is for when CommitStatus is Skipped",
|
||||
"x-go-name": "State"
|
||||
},
|
||||
"target_url": {
|
||||
@@ -27395,17 +27397,18 @@
|
||||
"x-go-name": "Description"
|
||||
},
|
||||
"state": {
|
||||
"description": "State represents the status state to set (pending, success, error, failure)",
|
||||
"description": "State represents the status state to set (pending, running, success, error, failure, warning, skipped)",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"pending",
|
||||
"running",
|
||||
"success",
|
||||
"error",
|
||||
"failure",
|
||||
"warning",
|
||||
"skipped"
|
||||
],
|
||||
"x-go-enum-desc": "pending CommitStatusPending is for when the CommitStatus is Pending\nsuccess CommitStatusSuccess is for when the CommitStatus is Success\nerror CommitStatusError is for when the CommitStatus is Error\nfailure CommitStatusFailure is for when the CommitStatus is Failure\nwarning CommitStatusWarning is for when the CommitStatus is Warning\nskipped CommitStatusSkipped is for when CommitStatus is Skipped",
|
||||
"x-go-enum-desc": "pending CommitStatusPending is for when the CommitStatus is Pending\nrunning CommitStatusRunning is for when the CommitStatus is Running\nsuccess CommitStatusSuccess is for when the CommitStatus is Success\nerror CommitStatusError is for when the CommitStatus is Error\nfailure CommitStatusFailure is for when the CommitStatus is Failure\nwarning CommitStatusWarning is for when the CommitStatus is Warning\nskipped CommitStatusSkipped is for when CommitStatus is Skipped",
|
||||
"x-go-name": "State"
|
||||
},
|
||||
"target_url": {
|
||||
|
||||
@@ -192,6 +192,14 @@ func TestRepoCommitsWithStatus(t *testing.T) {
|
||||
t.Run("error", func(t *testing.T) { testRefMaster(t, "error", "gitea-exclamation", "tw-text-red") })
|
||||
t.Run("failure", func(t *testing.T) { testRefMaster(t, "failure", "octicon-x", "tw-text-red") })
|
||||
t.Run("warning", func(t *testing.T) { testRefMaster(t, "warning", "gitea-exclamation", "tw-text-yellow") })
|
||||
t.Run("running", func(t *testing.T) { testRefMaster(t, "running", "gitea-running", "tw-text-yellow", "rotate-clockwise") })
|
||||
t.Run("unknown", func(t *testing.T) { testRefMaster(t, "stage-1", "octicon-question", "tw-text-text-light") })
|
||||
t.Run("InvalidState", func(t *testing.T) {
|
||||
invalidCtx := ctx
|
||||
invalidCtx.ExpectedCode = http.StatusUnprocessableEntity
|
||||
doAPICreateCommitStatusTest(invalidCtx, "master", "", "testci")(t)
|
||||
doAPICreateCommitStatusTest(invalidCtx, "master", "in_progress", "testci")(t)
|
||||
})
|
||||
t.Run("BranchWithSlash", func(t *testing.T) {
|
||||
_ = db.TruncateBeans(t.Context(), &git_model.CommitStatus{})
|
||||
|
||||
|
||||
Reference in new issue
Block a user