Skip to content

Commit 890863f

Browse files
committed
Add deleted mark for branches in action list
1 parent a87efd7 commit 890863f

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

models/actions/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type ActionRun struct {
3737
TriggerUser *user_model.User `xorm:"-"`
3838
ScheduleID int64
3939
Ref string `xorm:"index"` // the commit/tag/… that caused the run
40+
IsRefDeleted bool `xorm:"-"`
4041
CommitSHA string
4142
IsForkPullRequest bool // If this is triggered by a PR from a forked repository or an untrusted user, we need to check if it is approved and limit permissions when running the workflow.
4243
NeedApproval bool // may need approval if it's a fork pull request

routers/web/repo/actions/actions.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ func List(ctx *context.Context) {
245245
return
246246
}
247247

248+
if err := loadIsRefDeleted(ctx, runs); err != nil {
249+
ctx.ServerError("LoadIsRefDeleted", err)
250+
return
251+
}
252+
248253
ctx.Data["Runs"] = runs
249254

250255
actors, err := actions_model.GetActors(ctx, ctx.Repo.Repository.ID)
@@ -267,6 +272,42 @@ func List(ctx *context.Context) {
267272
ctx.HTML(http.StatusOK, tplListActions)
268273
}
269274

275+
// loadIsRefDeleted loads the IsRefDeleted field for each run in the list.
276+
// TODO: move this function to models/actions/run_list.go but now it will result in a circular import.
277+
func loadIsRefDeleted(ctx *context.Context, runs actions_model.RunList) error {
278+
branchRuns := make(map[string][]*actions_model.ActionRun)
279+
branches := make(container.Set[string], len(runs))
280+
for _, run := range runs {
281+
refName := git.RefName(run.Ref)
282+
if refName.IsBranch() {
283+
branchName := refName.ShortName()
284+
branchRuns[branchName] = append(branchRuns[branchName], run)
285+
branches.Add(branchName)
286+
}
287+
}
288+
if len(branches) == 0 {
289+
return nil
290+
}
291+
var branchInfos []*git_model.Branch
292+
if err := db.GetEngine(ctx).Where("repo_id = ?", ctx.Repo.Repository.ID).
293+
In("name", branches.Values()).Find(&branchInfos); err != nil {
294+
return err
295+
}
296+
for branch, branchRun := range branchRuns {
297+
exist := false
298+
for _, branchInfo := range branchInfos {
299+
if branchInfo.Name == branch {
300+
exist = !branchInfo.IsDeleted
301+
break
302+
}
303+
}
304+
for _, br := range branchRun {
305+
br.IsRefDeleted = !exist
306+
}
307+
}
308+
return nil
309+
}
310+
270311
type WorkflowDispatchInput struct {
271312
Name string `yaml:"name"`
272313
Description string `yaml:"description"`

templates/repo/actions/runs_list.tmpl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@
2828
</div>
2929
<div class="flex-item-trailing">
3030
{{if .RefLink}}
31-
<a class="ui label run-list-ref gt-ellipsis" href="{{.RefLink}}">{{.PrettyRef}}</a>
31+
{{if .IsRefDeleted}}
32+
<span class="ui label run-list-ref gt-ellipsis tw-line-through" data-tooltip-content="{{.PrettyRef}}">{{.PrettyRef}}</span>
33+
{{else}}
34+
<a class="ui label run-list-ref gt-ellipsis" href="{{.RefLink}}" data-tooltip-content="{{.PrettyRef}}">{{.PrettyRef}}</a>
35+
{{end}}
3236
{{else}}
33-
<span class="ui label run-list-ref gt-ellipsis">{{.PrettyRef}}</span>
37+
<span class="ui label run-list-ref gt-ellipsis" data-tooltip-content="{{.PrettyRef}}">{{.PrettyRef}}</span>
3438
{{end}}
3539
<div class="run-list-item-right">
3640
<div class="run-list-meta">{{svg "octicon-calendar" 16}}{{DateUtils.TimeSince .Updated}}</div>

0 commit comments

Comments
 (0)