From c9193adb68dd3a85eeefc7981529a04f36b8f8dc Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 8 Sep 2026 09:34:49 -0600 Subject: [PATCH] fix: restore owner name in PR target branch selector (#39262) Co-authored-by: wxiaoguang --- models/issues/pull.go | 13 +++------- routers/web/repo/compare.go | 6 +++-- routers/web/repo/pull.go | 9 ++----- templates/repo/issue/view_title.tmpl | 37 +++++++++++++++++----------- web_src/css/repo.css | 5 ---- web_src/js/features/repo-issue.ts | 24 +++++++++--------- web_src/js/features/repo-legacy.ts | 3 +-- 7 files changed, 44 insertions(+), 53 deletions(-) diff --git a/models/issues/pull.go b/models/issues/pull.go index 6121b39b89c..84a9611df6e 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -202,15 +202,10 @@ func (pr *PullRequest) String() string { return s.String() } -// MustHeadUserName returns the HeadRepo's username if failed return blank -func (pr *PullRequest) MustHeadUserName(ctx context.Context) string { - if err := pr.LoadHeadRepo(ctx); err != nil { - if !repo_model.IsErrRepoNotExist(err) { - log.Error("LoadHeadRepo: %v", err) - } else { - log.Warn("LoadHeadRepo %d but repository does not exist: %v", pr.HeadRepoID, err) - } - return "" +// OptionalHeadUserName returns the HeadRepo's username if failed return blank +func (pr *PullRequest) OptionalHeadUserName(ctx context.Context) string { + if err := pr.LoadHeadRepo(ctx); err != nil && !errors.Is(err, util.ErrNotExist) { + log.Error("LoadHeadRepo: %v", err) } if pr.HeadRepo == nil { return "" diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 4781c5a68b5..49027ea2e25 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -207,10 +207,12 @@ func (cpi *comparePageInfoType) parseCompareInfo(ctx *context.Context, comparePa return err } + // for the dropdown links ("{base} ... {head}") in the compare page "compare.tmpl" ctx.Data["BaseName"] = baseRepo.OwnerName - ctx.Data["BaseBranch"] = baseRef.ShortName() // for legacy templates ctx.Data["HeadUser"] = headOwner - ctx.Data["HeadBranch"] = headRef.ShortName() // for legacy templates + ctx.Data["BaseBranch"] = baseRef.ShortName() // also for "commits_table.tmpl"'s "no_commits" message + ctx.Data["HeadBranch"] = headRef.ShortName() + ctx.Data["IsPull"] = true context.InitRepoPullRequestCtx(ctx, baseRepo, headRepo) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index a0cf6140332..fff8d107032 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -161,12 +161,12 @@ func getPullInfo(ctx *context.Context) (issue *issues_model.Issue, ok bool) { func (prInfo *pullRequestViewInfo) setTemplateDataMergeTarget(ctx *context.Context) { pull := prInfo.issue.PullRequest - if ctx.Repo.Owner.Name == pull.MustHeadUserName(ctx) { + if ctx.Repo.Owner.Name == pull.OptionalHeadUserName(ctx) { prInfo.headTarget = pull.HeadBranch } else if pull.HeadRepo == nil { prInfo.headTarget = ctx.Locale.TrString("repo.pull.deleted_branch", pull.HeadBranch) } else { - prInfo.headTarget = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch + prInfo.headTarget = pull.OptionalHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch } ctx.Data["HeadTarget"] = prInfo.headTarget ctx.Data["BaseTarget"] = pull.BaseBranch @@ -351,11 +351,6 @@ func (prInfo *pullRequestViewInfo) prepareViewInfo(ctx *context.Context, issue * return } - // for the PR target branch selector - ctx.Data["BaseBranch"] = issue.PullRequest.BaseBranch - ctx.Data["HeadBranch"] = issue.PullRequest.HeadBranch - ctx.Data["HeadUserName"] = issue.PullRequest.MustHeadUserName(ctx) - if issue.PullRequest.HasMerged { prInfo.prepareViewMergedPullInfo(ctx) } else { diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index 103fa5de530..f1ccbe68c13 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -38,7 +38,7 @@ {{end}} -
+
{{if .HasMerged}}
{{svg "octicon-git-merge" 16 "tw-mr-1"}} {{if eq .Issue.PullRequest.Status 3}}{{ctx.Locale.Tr "repo.pulls.manually_merged"}}{{else}}{{ctx.Locale.Tr "repo.pulls.merged"}}{{end}}
{{else if .Issue.IsClosed}} @@ -52,7 +52,7 @@ {{else}}
{{svg "octicon-issue-opened"}} {{ctx.Locale.Tr "repo.issues.open_title"}}
{{end}} -
+
{{if .Issue.IsPull}} {{$headHref := .HeadTarget}} {{if .HeadBranchLink}} @@ -90,16 +90,22 @@ {{ctx.Locale.Tr "repo.pulls.title_desc" .NumCommits $headHref $baseHref}} {{end}} - -