Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions routers/web/repo/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package actions

import (
"bytes"
stdCtx "context"
"fmt"
"net/http"
"slices"
Expand Down Expand Up @@ -245,7 +246,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)
}

Expand Down Expand Up @@ -273,7 +274,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)
Expand All @@ -285,14 +286,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
}
}
Expand Down
21 changes: 21 additions & 0 deletions routers/web/repo/actions/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"strings"
"testing"

actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
unittest "code.gitea.io/gitea/models/unittest"

act_model "github.com/nektos/act/pkg/model"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -154,3 +158,20 @@ func TestReadWorkflow_WorkflowDispatchConfig(t *testing.T) {
Type: "boolean",
}, workflowDispatch.Inputs[2])
}

func Test_loadIsRefDeleted(t *testing.T) {
unittest.PrepareTestEnv(t)

runs, total, err := db.FindAndCount[actions_model.ActionRun](db.DefaultContext, actions_model.FindRunOptions{RepoID: 4})
assert.NoError(t, err)
assert.Len(t, runs, 3)
assert.EqualValues(t, 3, total)
for _, run := range runs {
assert.False(t, run.IsRefDeleted)
}

assert.NoError(t, loadIsRefDeleted(db.DefaultContext, 4, runs))
for _, run := range runs {
assert.True(t, run.IsRefDeleted)
}
}
14 changes: 14 additions & 0 deletions routers/web/repo/actions/main_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
Loading