Skip to content

Commit aa21dc3

Browse files
committed
Fix bug when updating actions numbers
1 parent 6b348da commit aa21dc3

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

models/actions/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ func TestMain(m *testing.M) {
1313
unittest.MainTest(m, &unittest.TestOptions{
1414
FixtureFiles: []string{
1515
"action_runner_token.yml",
16+
"action_run.yml",
17+
"repository.yml",
1618
},
1719
})
1820
}

models/actions/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@ func (run *ActionRun) IsSchedule() bool {
193193
return run.ScheduleID > 0
194194
}
195195

196+
// UpdateRepoRunsNumbers updates the number of runs and closed runs of a repository.
196197
func UpdateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) error {
197198
_, err := db.GetEngine(ctx).ID(repo.ID).
198199
NoAutoTime().
200+
Cols("num_action_runs", "num_closed_action_runs").
199201
SetExpr("num_action_runs",
200202
builder.Select("count(*)").From("action_run").
201203
Where(builder.Eq{"repo_id": repo.ID}),

models/actions/run_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package actions
5+
6+
import (
7+
"testing"
8+
9+
repo_model "code.gitea.io/gitea/models/repo"
10+
"code.gitea.io/gitea/models/unittest"
11+
12+
"github.com/stretchr/testify/assert"
13+
)
14+
15+
func TestUpdateRepoRunsNumbers(t *testing.T) {
16+
assert.NoError(t, unittest.PrepareTestDatabase())
17+
18+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
19+
assert.Equal(t, 4, repo.NumActionRuns)
20+
assert.Equal(t, 2, repo.NumClosedActionRuns)
21+
22+
err := UpdateRepoRunsNumbers(t.Context(), repo)
23+
assert.NoError(t, err)
24+
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
25+
assert.Equal(t, 4, repo.NumActionRuns)
26+
assert.Equal(t, 3, repo.NumClosedActionRuns)
27+
}

models/fixtures/repository.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
num_closed_milestones: 0
111111
num_projects: 0
112112
num_closed_projects: 1
113+
num_action_runs: 4
114+
num_closed_action_runs: 2 # this is wrong, should be 3. It's for testing purpose of run_test.go
113115
is_private: false
114116
is_empty: false
115117
is_archived: false

0 commit comments

Comments
 (0)