-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Detect whether action view branch was deleted #32764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
d37bd75
2b6a605
a87efd7
890863f
450b309
affe773
3a06760
f45c6f6
a16748d
de6160a
434e3ed
581c194
632b154
e1eab27
f1fa72d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,36 @@ 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 { | ||
branchRuns := make(map[string][]*actions_model.ActionRun) | ||
branches := make(container.Set[string], len(runs)) | ||
for _, run := range runs { | ||
refName := git.RefName(run.Ref) | ||
if refName.IsBranch() { | ||
branchName := refName.ShortName() | ||
run.IsRefDeleted = true // assume it's deleted then if it's found in the database it's not deleted | ||
branchRuns[branchName] = append(branchRuns[branchName], run) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it right? What if a branch starts 2 runs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And since the logic seems fragile, I think it needs tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A branch could start multiple runs, feature branches maybe updated multiple times and main branches may merge many commits. All these behaviours will trigger action runs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. de6160a |
||
branches.Add(branchName) | ||
} | ||
} | ||
if len(branches) == 0 { | ||
return nil | ||
} | ||
branchInfos, err := git_model.GetExistBranches(ctx, ctx.Repo.Repository.ID, branches.Values()) | ||
if err != nil { | ||
return err | ||
} | ||
for _, branchInfo := range branchInfos { | ||
branchRun := branchRuns[branchInfo.Name] | ||
for _, br := range branchRun { | ||
br.IsRefDeleted = false | ||
} | ||
} | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil | ||
} | ||
|
||
type WorkflowDispatchInput struct { | ||
Name string `yaml:"name"` | ||
Description string `yaml:"description"` | ||
|
Uh oh!
There was an error while loading. Please reload this page.