From 0208f5bc4ce761ab54af1f29ff9f0422a08c9911 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 29 Aug 2024 12:43:47 -0700 Subject: [PATCH] Add ref issue when creating pull request from issue --- options/locale/locale_en-US.ini | 1 + routers/web/repo/compare.go | 15 +++++++++++++++ .../issue/view_content/sidebar_development.tmpl | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 157565539c4..c19788bf7dc 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1627,6 +1627,7 @@ issues.maybefixed = May be fixed by %s issues.create_branch_from_issue_success = Create branch %s from issue successfully issues.pr.completed = Completed issues.pr.conflicted = Merge conflicts +issues.pr.not_exist_issue = Reference issue does not exist. issues.branch.latest = Latest commit %s issues.link.created = Created %s issues.num_participants = %d Participants diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index e6a04782e5b..91f69c3c25d 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -845,6 +845,21 @@ func CompareDiff(ctx *context.Context) { ctx.Data["AllowMaintainerEdit"] = false } + refIssueIndex := ctx.FormInt64("ref_issue_index") + if refIssueIndex > 0 { + refIssue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, refIssueIndex) + if err != nil { + ctx.Flash.Warning(ctx.Tr("repo.issues.pr.not_exist_issue"), true) + } else { + keyword := "Resolve" + if len(setting.Repository.PullRequest.CloseKeywords) > 0 { + keyword = setting.Repository.PullRequest.CloseKeywords[0] + } + ctx.Data["TitleQuery"] = fmt.Sprintf("%s %s", keyword, refIssue.Title) + ctx.Data["BodyQuery"] = fmt.Sprintf("%s #%d", keyword, refIssueIndex) + } + } + ctx.HTML(http.StatusOK, tplCompare) } diff --git a/templates/repo/issue/view_content/sidebar_development.tmpl b/templates/repo/issue/view_content/sidebar_development.tmpl index dd3bc6b2db6..5b451aa989b 100644 --- a/templates/repo/issue/view_content/sidebar_development.tmpl +++ b/templates/repo/issue/view_content/sidebar_development.tmpl @@ -33,7 +33,7 @@
- + {{svg "octicon-git-pull-request"}}