Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo: able fill pull request title by template from md file #5901

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion internal/route/repo/pull.go
Expand Up @@ -8,7 +8,6 @@ import (
"container/list"
"path"
"strings"

"github.com/unknwon/com"
log "gopkg.in/clog.v1"

Expand All @@ -29,6 +28,7 @@ const (
PULL_FILES = "repo/pulls/files"

PULL_REQUEST_TEMPLATE_KEY = "PullRequestTemplate"
PULL_REQUEST_TITLE_TEMPLATE_KEY = "PullRequestTitleTemplate"
)

var (
Expand All @@ -39,6 +39,14 @@ var (
}
)

var (
PullRequestTitleTemplateCandidates = []string{
unknwon marked this conversation as resolved.
Show resolved Hide resolved
"PULL_REQUEST_TITLE.md",
".gogs/PULL_REQUEST_TITLE.md",
".github/PULL_REQUEST_TITLE.md",
}
)

func parseBaseRepository(c *context.Context) *db.Repository {
baseRepo, err := db.GetRepositoryByID(c.ParamsInt64(":repoid"))
if err != nil {
Expand Down Expand Up @@ -637,6 +645,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)
unknwon marked this conversation as resolved.
Show resolved Hide resolved
}

c.Success(COMPARE_PULL)
}

Expand Down