summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-12-15 22:38:39 +0100
committerEarl Warren <contact@earl-warren.org>2024-12-22 07:21:38 +0100
commit967e04534e815b2e1166f928fefce63cb3d2ee9c (patch)
treec499d0bfdd473d9dd182427cc1c119578fe5f469 /routers
parentMerge pull request 'fix: keep commit count limit in file history pagination s... (diff)
downloadforgejo-967e04534e815b2e1166f928fefce63cb3d2ee9c.tar.xz
forgejo-967e04534e815b2e1166f928fefce63cb3d2ee9c.zip
Fix bug on action list deleted branch (#32848)
Fix https://github.com/go-gitea/gitea/issues/32761#issuecomment-2540946064 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> (cherry picked from commit 42090844ed2de5e615abc6ece351c152d3344295) Conflicts: models/fixtures/action_run.yml models/fixtures/branch.yml routers/web/repo/actions/actions_test.go trivial context conflict
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/actions/actions.go9
-rw-r--r--routers/web/repo/actions/actions_test.go33
-rw-r--r--routers/web/repo/actions/main_test.go14
3 files changed, 52 insertions, 4 deletions
diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go
index 283d476df1..e5134c1f62 100644
--- a/routers/web/repo/actions/actions.go
+++ b/routers/web/repo/actions/actions.go
@@ -5,6 +5,7 @@ package actions
import (
"bytes"
+ stdCtx "context"
"fmt"
"net/http"
"slices"
@@ -224,7 +225,7 @@ func List(ctx *context.Context) {
return
}
- if err := loadIsRefDeleted(ctx, runs); err != nil {
+ if err := loadIsRefDeleted(ctx, ctx.Repo.Repository.ID, runs); err != nil {
log.Error("LoadIsRefDeleted", err)
}
@@ -254,7 +255,7 @@ func List(ctx *context.Context) {
// loadIsRefDeleted loads the IsRefDeleted field for each run in the list.
// TODO: move this function to models/actions/run_list.go but now it will result in a circular import.
-func loadIsRefDeleted(ctx *context.Context, runs actions_model.RunList) error {
+func loadIsRefDeleted(ctx stdCtx.Context, repoID int64, runs actions_model.RunList) error {
branches := make(container.Set[string], len(runs))
for _, run := range runs {
refName := git.RefName(run.Ref)
@@ -266,14 +267,14 @@ func loadIsRefDeleted(ctx *context.Context, runs actions_model.RunList) error {
return nil
}
- branchInfos, err := git_model.GetBranches(ctx, ctx.Repo.Repository.ID, branches.Values(), false)
+ branchInfos, err := git_model.GetBranches(ctx, repoID, branches.Values(), false)
if err != nil {
return err
}
branchSet := git_model.BranchesToNamesSet(branchInfos)
for _, run := range runs {
refName := git.RefName(run.Ref)
- if refName.IsBranch() && !branchSet.Contains(run.Ref) {
+ if refName.IsBranch() && !branchSet.Contains(refName.ShortName()) {
run.IsRefDeleted = true
}
}
diff --git a/routers/web/repo/actions/actions_test.go b/routers/web/repo/actions/actions_test.go
new file mode 100644
index 0000000000..939c4aaf57
--- /dev/null
+++ b/routers/web/repo/actions/actions_test.go
@@ -0,0 +1,33 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package actions
+
+import (
+ "testing"
+
+ actions_model "code.gitea.io/gitea/models/actions"
+ "code.gitea.io/gitea/models/db"
+ unittest "code.gitea.io/gitea/models/unittest"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func Test_loadIsRefDeleted(t *testing.T) {
+ unittest.PrepareTestEnv(t)
+
+ runs, total, err := db.FindAndCount[actions_model.ActionRun](db.DefaultContext,
+ actions_model.FindRunOptions{RepoID: 4, Ref: "refs/heads/test"})
+ require.NoError(t, err)
+ assert.Len(t, runs, 1)
+ assert.EqualValues(t, 1, total)
+ for _, run := range runs {
+ assert.False(t, run.IsRefDeleted)
+ }
+
+ require.NoError(t, loadIsRefDeleted(db.DefaultContext, 4, runs))
+ for _, run := range runs {
+ assert.True(t, run.IsRefDeleted)
+ }
+}
diff --git a/routers/web/repo/actions/main_test.go b/routers/web/repo/actions/main_test.go
new file mode 100644
index 0000000000..a82f9c6672
--- /dev/null
+++ b/routers/web/repo/actions/main_test.go
@@ -0,0 +1,14 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package actions
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/unittest"
+)
+
+func TestMain(m *testing.M) {
+ unittest.MainTest(m)
+}