mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
Detect whether action view branch was deleted (#32764)
Fix #32761 
This commit is contained in:
@ -245,6 +245,10 @@ func List(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := loadIsRefDeleted(ctx, runs); err != nil {
|
||||
log.Error("LoadIsRefDeleted", err)
|
||||
}
|
||||
|
||||
ctx.Data["Runs"] = runs
|
||||
|
||||
actors, err := actions_model.GetActors(ctx, ctx.Repo.Repository.ID)
|
||||
@ -267,6 +271,34 @@ func List(ctx *context.Context) {
|
||||
ctx.HTML(http.StatusOK, tplListActions)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
branches := make(container.Set[string], len(runs))
|
||||
for _, run := range runs {
|
||||
refName := git.RefName(run.Ref)
|
||||
if refName.IsBranch() {
|
||||
branches.Add(refName.ShortName())
|
||||
}
|
||||
}
|
||||
if len(branches) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
branchInfos, err := git_model.GetBranches(ctx, ctx.Repo.Repository.ID, 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) {
|
||||
run.IsRefDeleted = true
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type WorkflowDispatchInput struct {
|
||||
Name string `yaml:"name"`
|
||||
Description string `yaml:"description"`
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@ -136,8 +137,9 @@ type ViewUser struct {
|
||||
}
|
||||
|
||||
type ViewBranch struct {
|
||||
Name string `json:"name"`
|
||||
Link string `json:"link"`
|
||||
Name string `json:"name"`
|
||||
Link string `json:"link"`
|
||||
IsDeleted bool `json:"isDeleted"`
|
||||
}
|
||||
|
||||
type ViewJobStep struct {
|
||||
@ -236,6 +238,16 @@ func ViewPost(ctx *context_module.Context) {
|
||||
Name: run.PrettyRef(),
|
||||
Link: run.RefLink(),
|
||||
}
|
||||
refName := git.RefName(run.Ref)
|
||||
if refName.IsBranch() {
|
||||
b, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, refName.ShortName())
|
||||
if err != nil && !git_model.IsErrBranchNotExist(err) {
|
||||
log.Error("GetBranch: %v", err)
|
||||
} else if git_model.IsErrBranchNotExist(err) || (b != nil && b.IsDeleted) {
|
||||
branch.IsDeleted = true
|
||||
}
|
||||
}
|
||||
|
||||
resp.State.Run.Commit = ViewCommit{
|
||||
ShortSha: base.ShortSha(run.CommitSHA),
|
||||
Link: fmt.Sprintf("%s/commit/%s", run.Repo.Link(), run.CommitSHA),
|
||||
|
Reference in New Issue
Block a user