Skip to content

Commit d37bd75

Browse files
committed
Detect whether action view branch was deleted
1 parent c986718 commit d37bd75

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

routers/web/repo/actions/view.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
actions_model "code.gitea.io/gitea/models/actions"
2121
"code.gitea.io/gitea/models/db"
22+
git_model "code.gitea.io/gitea/models/git"
2223
"code.gitea.io/gitea/models/perm"
2324
access_model "code.gitea.io/gitea/models/perm/access"
2425
repo_model "code.gitea.io/gitea/models/repo"
@@ -236,6 +237,16 @@ func ViewPost(ctx *context_module.Context) {
236237
Name: run.PrettyRef(),
237238
Link: run.RefLink(),
238239
}
240+
refName := git.RefName(run.Ref)
241+
if refName.IsBranch() {
242+
b, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, refName.ShortName())
243+
if err != nil && !git_model.IsErrBranchNotExist(err) {
244+
log.Error("GetBranch: %v", err)
245+
} else if git_model.IsErrBranchNotExist(err) || (b != nil && b.IsDeleted) {
246+
branch.Link = "" // remove the link of branch if it doesn't exist'
247+
}
248+
}
249+
239250
resp.State.Run.Commit = ViewCommit{
240251
ShortSha: base.ShortSha(run.CommitSHA),
241252
Link: fmt.Sprintf("%s/commit/%s", run.Repo.Link(), run.CommitSHA),

web_src/js/components/RepoActionView.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,12 @@ export function initRepositoryActionView() {
409409
<a class="muted" :href="run.commit.pusher.link">{{ run.commit.pusher.displayName }}</a>
410410
</template>
411411
<span class="ui label tw-max-w-full" v-if="run.commit.shortSHA">
412-
<a class="gt-ellipsis" :href="run.commit.branch.link">{{ run.commit.branch.name }}</a>
412+
<template v-if="run.commit.branch.link">
413+
<a class="gt-ellipsis" :href="run.commit.branch.link" :data-tooltip-content="run.commit.branch.name">{{ run.commit.branch.name }}</a>
414+
</template>
415+
<template v-else>
416+
<span class="gt-ellipsis tw-line-through" :data-tooltip-content="run.commit.branch.name">{{ run.commit.branch.name }}</span>
417+
</template>
413418
</span>
414419
</div>
415420
</div>

0 commit comments

Comments
 (0)