Skip to content

Commit d6cd40b

Browse files
silverwindclaude
andcommitted
Collapse statusinfo subpackage into modules/actions
modules/actions/statusinfo only existed to dodge the modules/actions -> services/context leak from artifacts.go. With that file moved, the subpackage is unneeded. Rename types to avoid stutter in their new home: statusinfo.ActionInfo -> actions.CommitStatusInfo and statusinfo.GetActionInfo -> actions.GetCommitStatusInfo. Also tighten doc on util_actions.go's ActionsUtils (drop drift-prone cross-file comparison and a duplicated rationale on the one-line wrapper method). Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
1 parent 6cb3859 commit d6cd40b

3 files changed

Lines changed: 23 additions & 26 deletions

File tree

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2026 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
package statusinfo
4+
package actions
55

66
import (
77
"context"
@@ -13,41 +13,43 @@ import (
1313
"code.gitea.io/gitea/modules/log"
1414
)
1515

16-
// ActionInfo maps CommitStatus.ID to the live ActionRunJob status
16+
// CommitStatusInfo maps CommitStatus.ID to the live ActionRunJob status
1717
// for Gitea Actions rows.
18-
type ActionInfo map[int64]actions_model.Status
18+
type CommitStatusInfo map[int64]actions_model.Status
1919

2020
// IconStatus returns the action status name to route the icon through
2121
// repo/icons/action_status, or "" when the row isn't from Gitea Actions.
22-
func (m ActionInfo) IconStatus(s *git_model.CommitStatus) string {
22+
func (m CommitStatusInfo) IconStatus(s *git_model.CommitStatus) string {
2323
if status, ok := m[s.ID]; ok {
2424
return status.String()
2525
}
2626
return ""
2727
}
2828

29-
// GetActionInfo resolves the live ActionRunJob.Status for every
29+
// GetCommitStatusInfo resolves the live ActionRunJob.Status for every
3030
// CommitStatus row backed by Gitea Actions. Rows from other sources (external
3131
// CIs, API) are left untouched and rendered from their stored State.
3232
//
33-
// Side effect: populates status.Repo for inputs whose Repo is nil, sharing
34-
// one lookup across entries with the same RepoID. ParseGiteaActionsTargetURL
35-
// needs the Repo loaded; the caching avoids one DB hit per row.
36-
func GetActionInfo(ctx context.Context, statuses []*git_model.CommitStatus) ActionInfo {
33+
// Side effect: fills in status.Repo for inputs whose Repo is nil, sharing one
34+
// lookup across entries with the same RepoID ParseGiteaActionsTargetURL
35+
// needs Repo loaded and would otherwise lazy-load it per row.
36+
func GetCommitStatusInfo(ctx context.Context, statuses []*git_model.CommitStatus) CommitStatusInfo {
3737
if len(statuses) == 0 {
3838
return nil
3939
}
4040
statusByJobID := make(map[int64]*git_model.CommitStatus)
41-
repoCache := make(map[int64]*repo_model.Repository)
41+
repoByID := make(map[int64]*repo_model.Repository)
4242
for _, status := range statuses {
4343
if status == nil || status.TargetURL == "" {
4444
continue
4545
}
4646
if status.Repo == nil {
47-
status.Repo = repoCache[status.RepoID]
47+
status.Repo = repoByID[status.RepoID]
4848
}
49+
// ParseGiteaActionsTargetURL lazy-loads status.Repo on miss; cache the
50+
// outcome so later entries with the same RepoID skip that load.
4951
_, jobID, ok := status.ParseGiteaActionsTargetURL(ctx)
50-
repoCache[status.RepoID] = status.Repo
52+
repoByID[status.RepoID] = status.Repo
5153
if ok {
5254
statusByJobID[jobID] = status
5355
}
@@ -61,10 +63,10 @@ func GetActionInfo(ctx context.Context, statuses []*git_model.CommitStatus) Acti
6163
}
6264
jobs := make(map[int64]*actions_model.ActionRunJob, len(jobIDs))
6365
if err := db.GetEngine(ctx).In("id", jobIDs).Cols("id", "status").Find(&jobs); err != nil {
64-
log.Error("GetActionInfo: find action run jobs: %v", err)
66+
log.Error("GetCommitStatusInfo: find action run jobs: %v", err)
6567
return nil
6668
}
67-
info := make(ActionInfo, len(jobs))
69+
info := make(CommitStatusInfo, len(jobs))
6870
for jobID, status := range statusByJobID {
6971
if job, ok := jobs[jobID]; ok && !job.Status.IsUnknown() {
7072
info[status.ID] = job.Status

modules/templates/util_actions.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
"context"
88

99
git_model "code.gitea.io/gitea/models/git"
10-
"code.gitea.io/gitea/modules/actions/statusinfo"
10+
actions_module "code.gitea.io/gitea/modules/actions"
1111
)
1212

1313
// ActionsUtils groups template helpers for Gitea Actions data. Methods may
14-
// issue DB queries; unlike MiscUtils/RenderUtils these are not pure.
14+
// issue DB queries.
1515
type ActionsUtils struct {
1616
ctx context.Context
1717
}
@@ -20,10 +20,6 @@ func NewActionsUtils(ctx context.Context) *ActionsUtils {
2020
return &ActionsUtils{ctx: ctx}
2121
}
2222

23-
// CommitStatusInfo resolves the live ActionRunJob.Status for every
24-
// Gitea-Actions-backed CommitStatus row so repo/pulls/status.tmpl can render
25-
// the matching live icon (the stored State collapses Waiting/Running/Blocked
26-
// into Pending).
27-
func (a *ActionsUtils) CommitStatusInfo(statuses []*git_model.CommitStatus) statusinfo.ActionInfo {
28-
return statusinfo.GetActionInfo(a.ctx, statuses)
23+
func (a *ActionsUtils) CommitStatusInfo(statuses []*git_model.CommitStatus) actions_module.CommitStatusInfo {
24+
return actions_module.GetCommitStatusInfo(a.ctx, statuses)
2925
}

tests/integration/actions_trigger_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"code.gitea.io/gitea/models/unittest"
2323
user_model "code.gitea.io/gitea/models/user"
2424
actions_module "code.gitea.io/gitea/modules/actions"
25-
"code.gitea.io/gitea/modules/actions/statusinfo"
2625
"code.gitea.io/gitea/modules/commitstatus"
2726
"code.gitea.io/gitea/modules/gitrepo"
2827
"code.gitea.io/gitea/modules/json"
@@ -1810,7 +1809,7 @@ jobs:
18101809
})
18111810
}
18121811

1813-
// Verify GetActionInfo surfaces the live ActionRunJob.Status so the
1812+
// Verify GetCommitStatusInfo surfaces the live ActionRunJob.Status so the
18141813
// icon reflects Waiting/Running/Blocked — all three share State=Pending in the
18151814
// stored CommitStatus row.
18161815
func TestActionsCommitStatusRunning(t *testing.T) {
@@ -1850,11 +1849,11 @@ func TestActionsCommitStatusRunning(t *testing.T) {
18501849
require.Len(t, statuses, 1)
18511850
assert.Equal(t, commitstatus.CommitStatusPending, statuses[0].State)
18521851

1853-
info := statusinfo.GetActionInfo(t.Context(), statuses)
1852+
info := actions_module.GetCommitStatusInfo(t.Context(), statuses)
18541853
assert.Equal(t, actions_model.StatusRunning.String(), info.IconStatus(statuses[0]))
18551854

18561855
// No enrichment available → IconStatus is empty.
1857-
empty := statusinfo.ActionInfo{}
1856+
empty := actions_module.CommitStatusInfo{}
18581857
assert.Empty(t, empty.IconStatus(statuses[0]))
18591858

18601859
// The commits-list tippy tooltip renders status.tmpl too: verify the live

0 commit comments

Comments
 (0)