forked from kevadesu/forgejo
Merge pull request '[gitea] week 2024-52 cherry pick (gitea/main -> forgejo)' (#6342) from earl-warren/wcp/2024-52 into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6342 Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
commit
1fffd116e5
14 changed files with 217 additions and 29 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
33
routers/web/repo/actions/actions_test.go
Normal file
33
routers/web/repo/actions/actions_test.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
14
routers/web/repo/actions/main_test.go
Normal file
14
routers/web/repo/actions/main_test.go
Normal file
|
@ -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…
Add table
Add a link
Reference in a new issue