Skip to content

Commit

Permalink
Add Default Pull Request Title (#5735)
Browse files Browse the repository at this point in the history
* add default PR title
Set default PR title to commit summary if there's a single commit on the head branch, else set it to the head branch name

* set default PR description
If there's a single commit on the head branch, and it's multiline, then set it as the default PR description
  • Loading branch information
eloyekunle authored and jonasfranz committed Jan 16, 2019
1 parent c2dcb35 commit 734834a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,9 @@ func PrepareCompareDiff(
baseBranch, headBranch string) bool {

var (
repo = ctx.Repo.Repository
err error
repo = ctx.Repo.Repository
err error
title string
)

// Get diff information.
Expand Down Expand Up @@ -762,6 +763,20 @@ func PrepareCompareDiff(
prInfo.Commits = models.ParseCommitsWithStatus(prInfo.Commits, headRepo)
ctx.Data["Commits"] = prInfo.Commits
ctx.Data["CommitCount"] = prInfo.Commits.Len()

if prInfo.Commits.Len() == 1 {
c := prInfo.Commits.Front().Value.(models.SignCommitWithStatuses)
title = strings.TrimSpace(c.UserCommit.Summary())

body := strings.Split(strings.TrimSpace(c.UserCommit.Message()), "\n")
if len(body) > 1 {
ctx.Data["content"] = strings.Join(body[1:], "\n")
}
} else {
title = headBranch
}

ctx.Data["title"] = title
ctx.Data["Username"] = headUser.Name
ctx.Data["Reponame"] = headRepo.Name
ctx.Data["IsImageFile"] = headCommit.IsImageFile
Expand Down

0 comments on commit 734834a

Please sign in to comment.