Rename the main module to gotea.dev and the binary to gotea, and update the application name and English locale. Keep the external gitea.dev/sdk and gitea.dev/actionslib module imports unchanged. Assisted-by: OpenCode:DeepSeek-V4.1-Flash
62 lines
1.8 KiB
Go
62 lines
1.8 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"context"
|
|
"maps"
|
|
"slices"
|
|
|
|
actions_model "gotea.dev/models/actions"
|
|
"gotea.dev/models/db"
|
|
git_model "gotea.dev/models/git"
|
|
"gotea.dev/modules/log"
|
|
)
|
|
|
|
// CommitActionsStatusMap maps CommitStatus.ID to the live ActionRunJob status
|
|
// for Gitea Actions rows.
|
|
type CommitActionsStatusMap map[int64]actions_model.Status
|
|
|
|
// IconStatus returns the action status name to route the icon through
|
|
// repo/icons/action_status, or "" when the row isn't from Gitea Actions.
|
|
func (m CommitActionsStatusMap) IconStatus(s *git_model.CommitStatus) string {
|
|
if status, ok := m[s.ID]; ok {
|
|
return status.String()
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// GetCommitActionsStatusMap resolves the live ActionRunJob.Status for every
|
|
// CommitStatus row backed by Gitea Actions. Rows from other sources (external
|
|
// CIs, API) are left untouched and rendered from their stored State.
|
|
func GetCommitActionsStatusMap(ctx context.Context, statuses []*git_model.CommitStatus) CommitActionsStatusMap {
|
|
if len(statuses) == 0 {
|
|
return nil
|
|
}
|
|
statusByJobID := make(map[int64]*git_model.CommitStatus)
|
|
for _, status := range statuses {
|
|
if status == nil || status.TargetURL == "" {
|
|
continue
|
|
}
|
|
if _, jobID, ok := status.ParseGiteaActionsTargetURL(ctx); ok {
|
|
statusByJobID[jobID] = status
|
|
}
|
|
}
|
|
if len(statusByJobID) == 0 {
|
|
return nil
|
|
}
|
|
jobs := make(map[int64]*actions_model.ActionRunJob, len(statusByJobID))
|
|
if err := db.GetEngine(ctx).In("id", slices.Collect(maps.Keys(statusByJobID))).Cols("id", "status").Find(&jobs); err != nil {
|
|
log.Error("db.Find: failed to find action run jobs: %v", err)
|
|
return nil
|
|
}
|
|
info := make(CommitActionsStatusMap, len(jobs))
|
|
for jobID, status := range statusByJobID {
|
|
if job, ok := jobs[jobID]; ok {
|
|
info[status.ID] = job.Status
|
|
}
|
|
}
|
|
return info
|
|
}
|