From 6930959dc78395393287361044f5c613859dc6d0 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 6 Sep 2024 12:43:04 -0700 Subject: [PATCH] Display head branch more comfortable on pull request view --- models/issues/pull.go | 4 ++++ options/locale/locale_en-US.ini | 1 + routers/web/repo/pull.go | 14 +++++++++++++- templates/repo/issue/view_title.tmpl | 9 +++++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/models/issues/pull.go b/models/issues/pull.go index 5fe95d56cc253..4a5782f836c89 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -268,6 +268,10 @@ func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) { return nil } +func (pr *PullRequest) IsAgitFlow() bool { + return pr.Flow == PullRequestFlowAGit +} + // LoadHeadRepo loads the head repository, pr.HeadRepo will remain nil if it does not exist // and thus ErrRepoNotExist will never be returned func (pr *PullRequest) LoadHeadRepo(ctx context.Context) (err error) { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 7d8eb1a475399..08ea07c2942dc 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1922,6 +1922,7 @@ pulls.delete.text = Do you really want to delete this pull request? (This will p pulls.recently_pushed_new_branches = You pushed on branch %[1]s %[2]s pull.deleted_branch = (deleted):%s +pull.agit_documentation = Review documentation about AGit comments.edit.already_changed = Unable to save changes to the comment. It appears the content has already been changed by another user. Please refresh the page and try editing again to avoid overwriting their changes diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index e001e872aa8af..d4192a7246ebf 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -163,7 +163,19 @@ func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) { ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch } ctx.Data["BaseTarget"] = pull.BaseBranch - ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink(ctx) + headBranchLink := "" + if pull.Flow == issues_model.PullRequestFlowGithub { + b, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, pull.HeadBranch) + switch { + case err == nil: + if !b.IsDeleted { + headBranchLink = pull.GetHeadBranchLink(ctx) + } + case !git_model.IsErrBranchNotExist(err): + log.Error("GetBranch: %v", err) + } + } + ctx.Data["HeadBranchLink"] = headBranchLink ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink(ctx) } diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index 1243681f3a219..7fa77b3f1cf33 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -50,9 +50,14 @@ {{if .Issue.IsPull}} {{$headHref := .HeadTarget}} {{if .HeadBranchLink}} - {{$headHref = HTMLFormat `%s` .HeadBranchLink $headHref}} + {{$headHref = HTMLFormat `%s ` .HeadBranchLink $headHref (ctx.Locale.Tr "copy_branch") .HeadTarget (svg "octicon-copy" 14)}} + {{else}} + {{if .Issue.PullRequest.IsAgitFlow}} + {{$headHref = HTMLFormat `%s AGit` $headHref "https://docs.gitea.com/usage/agit" (ctx.Locale.Tr "repo.pull.agit_documentation")}} + {{else}} + {{$headHref = HTMLFormat `%s` (ctx.Locale.Tr "form.target_branch_not_exist") $headHref}} + {{end}} {{end}} - {{$headHref = HTMLFormat `%s ` $headHref (ctx.Locale.Tr "copy_branch") .HeadTarget (svg "octicon-copy" 14)}} {{$baseHref := .BaseTarget}} {{if .BaseBranchLink}} {{$baseHref = HTMLFormat `%s` .BaseBranchLink $baseHref}}