mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-24 07:49:34 +02:00
refactor(actions): small cleanups across models, services and routers (#39722)
Collection of small, behaviour-preserving cleanups in the Actions code. - Fix log and error prefixes that named non-existent or wrong functions, and wrap errors with `%w` so `errors.Is` keeps working. - Remove unused code. - Rely on `ctx.ServerError` / `ctx.APIErrorAuto`, which already map `util.ErrNotExist` and friends, instead of equivalent hand-written switches. - Load runs referenced by commit statuses with one query instead of one per run (used on every PR view); the result order is now stable. - Encode an event's payload once instead of up to three times. - Share the duplicated runner-token "get or create" logic and the "notify and emit" call pair. - Simplify `ToActionArtifact` / `ToActionRunner` signatures. --------- Signed-off-by: bircni <bircni@icloud.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
26 files changed
+113
-223
No files matched your search
@@ -4,7 +4,6 @@
|
||||
package private
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -13,7 +12,6 @@ import (
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/json"
|
||||
"gitea.dev/modules/private"
|
||||
"gitea.dev/modules/util"
|
||||
"gitea.dev/services/context"
|
||||
)
|
||||
|
||||
@@ -34,15 +32,9 @@ func GenerateActionsRunnerToken(ctx *context.PrivateContext) {
|
||||
return
|
||||
}
|
||||
|
||||
token, err := actions_model.GetLatestRunnerToken(ctx, owner, repo)
|
||||
if errors.Is(err, util.ErrNotExist) || (token != nil && !token.IsActive) {
|
||||
token, err = actions_model.NewRunnerToken(ctx, owner, repo)
|
||||
if err != nil {
|
||||
ctx.PrivateInternalErrorf("error while creating runner token: %v", err)
|
||||
return
|
||||
}
|
||||
} else if err != nil {
|
||||
ctx.PrivateInternalErrorf("could not get unactivated runner token: %v", err)
|
||||
token, err := actions_model.GetOrCreateActiveRunnerToken(ctx, owner, repo)
|
||||
if err != nil {
|
||||
ctx.PrivateInternalErrorf("GetOrCreateActiveRunnerToken failed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user