From d4101fda0c08b3290a90739a608ef302de21dcdc Mon Sep 17 00:00:00 2001 From: Mitrahsoft Date: Thu, 19 Nov 2026 11:28:12 +0000 Subject: [PATCH] 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 | | --- | --- | | before | after| Fixes: https://github.com/go-gitea/gitea/issues/39608 --- models/git/commit_status.go | 3 +++ modules/commitstatus/commit_status.go | 2 ++ modules/commitstatus/commit_status_test.go | 5 +++++ modules/structs/status.go | 4 ++-- routers/api/v1/repo/status.go | 5 +++++ templates/repo/icons/commit_status.tmpl | 21 ++++++++++---------- templates/swagger/v1-openapi3.generated.json | 5 +++-- templates/swagger/v1-swagger.generated.json | 13 +++++++----- tests/integration/repo_commits_test.go | 8 ++++++++ 9 files changed, 46 insertions(+), 20 deletions(-) diff --git a/models/git/commit_status.go b/models/git/commit_status.go index 9c57f54384f..c3c9b956ffa 100644 --- a/models/git/commit_status.go +++ b/models/git/commit_status.go @@ -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"` diff --git a/modules/commitstatus/commit_status.go b/modules/commitstatus/commit_status.go index 9c6994249b2..a08410542b3 100644 --- a/modules/commitstatus/commit_status.go +++ b/modules/commitstatus/commit_status.go @@ -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 diff --git a/modules/commitstatus/commit_status_test.go b/modules/commitstatus/commit_status_test.go index a5fffd914f3..3f7928aa730 100644 --- a/modules/commitstatus/commit_status_test.go +++ b/modules/commitstatus/commit_status_test.go @@ -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", diff --git a/modules/structs/status.go b/modules/structs/status.go index 7a700c6ef5f..cb4e47f4105 100644 --- a/modules/structs/status.go +++ b/modules/structs/status.go @@ -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"` diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index 1fce240d35a..00875e09b4f 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -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, diff --git a/templates/repo/icons/commit_status.tmpl b/templates/repo/icons/commit_status.tmpl index c61d381e0e3..13c0f9c92b5 100644 --- a/templates/repo/icons/commit_status.tmpl +++ b/templates/repo/icons/commit_status.tmpl @@ -1,19 +1,18 @@ - + {{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}} diff --git a/templates/swagger/v1-openapi3.generated.json b/templates/swagger/v1-openapi3.generated.json index 47c2eaf5184..6c5628b05b5 100644 --- a/templates/swagger/v1-openapi3.generated.json +++ b/templates/swagger/v1-openapi3.generated.json @@ -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", diff --git a/templates/swagger/v1-swagger.generated.json b/templates/swagger/v1-swagger.generated.json index 8e7780a348e..3aace40fa48 100644 --- a/templates/swagger/v1-swagger.generated.json +++ b/templates/swagger/v1-swagger.generated.json @@ -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": { diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index a54557bbd01..c093e6ce73d 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -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{})