aboutsummaryrefslogtreecommitdiff
path: root/internal/route/repo
diff options
context:
space:
mode:
authorivan <hello@ivanbogomolov.ru>2020-01-29 11:28:59 +0300
committerGitHub <noreply@github.com>2020-01-29 16:28:59 +0800
commita0342d95278702ae3802723087f41cd1876a8620 (patch)
tree4122b6443fdd548cfd62d801d321296abc0ffff9 /internal/route/repo
parent2f4cc5480e77b8802265aaa5bbf24c1573a0523d (diff)
repo: able fill pull request title by template from md file (#5901)
* able fill pull request title by template from md file * fix: unusedresult: result of fmt.Sprintf call not used (from govet) * fix: remove import fmt -> not used * after review / PullRequestTitleTemplateCandidates moved to after line 39 * Update pull.go * Update pull.go Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
Diffstat (limited to 'internal/route/repo')
-rw-r--r--internal/route/repo/pull.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/route/repo/pull.go b/internal/route/repo/pull.go
index b6ae9875..38c04c7c 100644
--- a/internal/route/repo/pull.go
+++ b/internal/route/repo/pull.go
@@ -29,6 +29,7 @@ const (
PULL_FILES = "repo/pulls/files"
PULL_REQUEST_TEMPLATE_KEY = "PullRequestTemplate"
+ PULL_REQUEST_TITLE_TEMPLATE_KEY = "PullRequestTitleTemplate"
)
var (
@@ -37,6 +38,12 @@ var (
".gogs/PULL_REQUEST.md",
".github/PULL_REQUEST.md",
}
+
+ PullRequestTitleTemplateCandidates = []string{
+ "PULL_REQUEST_TITLE.md",
+ ".gogs/PULL_REQUEST_TITLE.md",
+ ".github/PULL_REQUEST_TITLE.md",
+ }
)
func parseBaseRepository(c *context.Context) *db.Repository {
@@ -637,6 +644,14 @@ func CompareAndPullRequest(c *context.Context) {
}
c.Data["IsSplitStyle"] = c.Query("style") == "split"
+ setTemplateIfExists(c, PULL_REQUEST_TITLE_TEMPLATE_KEY, PullRequestTitleTemplateCandidates)
+
+ if c.Data[PULL_REQUEST_TITLE_TEMPLATE_KEY] != nil {
+ customTitle := c.Data[PULL_REQUEST_TITLE_TEMPLATE_KEY].(string)
+ r := strings.NewReplacer("{{headBranch}}", headBranch,"{{baseBranch}}", baseBranch)
+ c.Data["title"] = r.Replace(customTitle)
+ }
+
c.Success(COMPARE_PULL)
}