Skip to content

Commit de6160a

Browse files
committed
Follow feedbacks
1 parent f45c6f6 commit de6160a

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed

models/git/branch.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
repo_model "code.gitea.io/gitea/models/repo"
1313
"code.gitea.io/gitea/models/unit"
1414
user_model "code.gitea.io/gitea/models/user"
15+
"code.gitea.io/gitea/modules/container"
1516
"code.gitea.io/gitea/modules/git"
1617
"code.gitea.io/gitea/modules/log"
1718
"code.gitea.io/gitea/modules/optional"
@@ -169,16 +170,22 @@ func GetBranch(ctx context.Context, repoID int64, branchName string) (*Branch, e
169170
return &branch, nil
170171
}
171172

172-
func GetBranches(ctx context.Context, repoID int64, branchNames []string) ([]*Branch, error) {
173+
func GetBranches(ctx context.Context, repoID int64, branchNames []string, includeDeleted bool) ([]*Branch, error) {
173174
branches := make([]*Branch, 0, len(branchNames))
174-
return branches, db.GetEngine(ctx).Where("repo_id=?", repoID).In("name", branchNames).Find(&branches)
175+
176+
sess := db.GetEngine(ctx).Where("repo_id=?", repoID).In("name", branchNames)
177+
if !includeDeleted {
178+
sess.And("is_deleted=?", false)
179+
}
180+
return branches, sess.Find(&branches)
175181
}
176182

177-
func GetExistBranches(ctx context.Context, repoID int64, branchNames []string) ([]*Branch, error) {
178-
branches := make([]*Branch, 0, len(branchNames))
179-
return branches, db.GetEngine(ctx).Where("repo_id=?", repoID).
180-
And("is_deleted=?", false).
181-
In("name", branchNames).Find(&branches)
183+
func BranchesToNamesSet(branches []*Branch) container.Set[string] {
184+
names := make(container.Set[string], len(branches))
185+
for _, branch := range branches {
186+
names.Add(branch.Name)
187+
}
188+
return names
182189
}
183190

184191
func AddBranches(ctx context.Context, branches []*Branch) error {

routers/web/repo/actions/actions.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,28 +274,26 @@ func List(ctx *context.Context) {
274274
// loadIsRefDeleted loads the IsRefDeleted field for each run in the list.
275275
// TODO: move this function to models/actions/run_list.go but now it will result in a circular import.
276276
func loadIsRefDeleted(ctx *context.Context, runs actions_model.RunList) error {
277-
branchRuns := make(map[string][]*actions_model.ActionRun)
278277
branches := make(container.Set[string], len(runs))
279278
for _, run := range runs {
280279
refName := git.RefName(run.Ref)
281280
if refName.IsBranch() {
282-
branchName := refName.ShortName()
283-
run.IsRefDeleted = true // assume it's deleted then if it's found in the database it's not deleted
284-
branchRuns[branchName] = append(branchRuns[branchName], run)
285-
branches.Add(branchName)
281+
branches.Add(refName.ShortName())
286282
}
287283
}
288284
if len(branches) == 0 {
289285
return nil
290286
}
291-
branchInfos, err := git_model.GetExistBranches(ctx, ctx.Repo.Repository.ID, branches.Values())
287+
288+
branchInfos, err := git_model.GetBranches(ctx, ctx.Repo.Repository.ID, branches.Values(), false)
292289
if err != nil {
293290
return err
294291
}
295-
for _, branchInfo := range branchInfos {
296-
branchRun := branchRuns[branchInfo.Name]
297-
for _, br := range branchRun {
298-
br.IsRefDeleted = false
292+
branchSet := git_model.BranchesToNamesSet(branchInfos)
293+
for _, run := range runs {
294+
refName := git.RefName(run.Ref)
295+
if refName.IsBranch() && !branchSet.Contains(run.Ref) {
296+
run.IsRefDeleted = true
299297
}
300298
}
301299
return nil

services/repository/branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames,
305305
}
306306

307307
return db.WithTx(ctx, func(ctx context.Context) error {
308-
branches, err := git_model.GetBranches(ctx, repoID, branchNames)
308+
branches, err := git_model.GetBranches(ctx, repoID, branchNames, true)
309309
if err != nil {
310310
return fmt.Errorf("git_model.GetBranches: %v", err)
311311
}

templates/repo/actions/runs_list.tmpl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@
2727
</div>
2828
</div>
2929
<div class="flex-item-trailing">
30-
{{if .RefLink}}
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}}
30+
{{if .IsRefDeleted}}
31+
<span class="ui label run-list-ref gt-ellipsis tw-line-through" data-tooltip-content="{{.PrettyRef}}">{{.PrettyRef}}</span>
3632
{{else}}
37-
<span class="ui label run-list-ref gt-ellipsis" data-tooltip-content="{{.PrettyRef}}">{{.PrettyRef}}</span>
33+
<a class="ui label run-list-ref gt-ellipsis" href="{{.RefLink}}" data-tooltip-content="{{.PrettyRef}}">{{.PrettyRef}}</a>
3834
{{end}}
3935
<div class="run-list-item-right">
4036
<div class="run-list-meta">{{svg "octicon-calendar" 16}}{{DateUtils.TimeSince .Updated}}</div>

web_src/js/components/RepoActionView.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,8 @@ export function initRepositoryActionView() {
429429
<a class="muted" :href="run.commit.pusher.link">{{ run.commit.pusher.displayName }}</a>
430430
</template>
431431
<span class="ui label tw-max-w-full" v-if="run.commit.shortSHA">
432-
<template v-if="run.commit.branch.isDeleted">
433-
<span class="gt-ellipsis tw-line-through" :data-tooltip-content="run.commit.branch.name">{{ run.commit.branch.name }}</span>
434-
</template>
435-
<template v-else>
436-
<a class="gt-ellipsis" :href="run.commit.branch.link" :data-tooltip-content="run.commit.branch.name">{{ run.commit.branch.name }}</a>
437-
</template>
432+
<span v-if="run.commit.branch.isDeleted" class="gt-ellipsis tw-line-through" :data-tooltip-content="run.commit.branch.name">{{ run.commit.branch.name }}</span>
433+
<a v-else class="gt-ellipsis" :href="run.commit.branch.link" :data-tooltip-content="run.commit.branch.name">{{ run.commit.branch.name }}</a>
438434
</span>
439435
</div>
440436
</div>

0 commit comments

Comments
 (0)