From d37bd75debd26aaace16d01f2a9f2fa6a03cb6bd Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 8 Dec 2024 11:31:44 -0800 Subject: [PATCH 1/6] Detect whether action view branch was deleted --- routers/web/repo/actions/view.go | 11 +++++++++++ web_src/js/components/RepoActionView.vue | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 73c6e54fbf50a..9a40c8fa2984c 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -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" @@ -236,6 +237,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.Link = "" // remove the link of branch if it doesn't exist' + } + } + resp.State.Run.Commit = ViewCommit{ ShortSha: base.ShortSha(run.CommitSHA), Link: fmt.Sprintf("%s/commit/%s", run.Repo.Link(), run.CommitSHA), diff --git a/web_src/js/components/RepoActionView.vue b/web_src/js/components/RepoActionView.vue index eecbf7ef55936..b813ba37b237e 100644 --- a/web_src/js/components/RepoActionView.vue +++ b/web_src/js/components/RepoActionView.vue @@ -409,7 +409,12 @@ export function initRepositoryActionView() { {{ run.commit.pusher.displayName }} - {{ run.commit.branch.name }} + + From 2b6a605aec4c83c1ff1e9dfb056edff54fd17381 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 9 Dec 2024 20:17:59 -0800 Subject: [PATCH 2/6] Don't remove the link but add isDeleted --- routers/web/repo/actions/view.go | 7 ++++--- web_src/js/components/RepoActionView.vue | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 9a40c8fa2984c..b711038da065a 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -137,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 { @@ -243,7 +244,7 @@ func ViewPost(ctx *context_module.Context) { if err != nil && !git_model.IsErrBranchNotExist(err) { log.Error("GetBranch: %v", err) } else if git_model.IsErrBranchNotExist(err) || (b != nil && b.IsDeleted) { - branch.Link = "" // remove the link of branch if it doesn't exist' + branch.IsDeleted = true } } diff --git a/web_src/js/components/RepoActionView.vue b/web_src/js/components/RepoActionView.vue index b813ba37b237e..c67122603b938 100644 --- a/web_src/js/components/RepoActionView.vue +++ b/web_src/js/components/RepoActionView.vue @@ -409,11 +409,11 @@ export function initRepositoryActionView() { {{ run.commit.pusher.displayName }} - - - + {{ run.commit.branch.name }} + {{ run.commit.branch.name }}