diff --git a/commands/issue.go b/commands/issue.go index 7797344d67ed576de5678fb90b2c885081fc5386..f78908a7b9acd28757b257fdc115efe734abd062 100644 --- a/commands/issue.go +++ b/commands/issue.go @@ -95,7 +95,7 @@ func writeIssueTitleAndBody(project *github.Project) (string, string, error) { # Creating issue for %s. # # Write a message for this issue. The first block -# of the text is the title and the rest is description. +# of text is the title and the rest is description. ` message = fmt.Sprintf(message, project.Name) diff --git a/commands/pull_request.go b/commands/pull_request.go index ba1139b2d0a6dfff9b76a490ad948b2e9b0652ed..ff31419b9c24ea0350ba8078f3260dfad2d0ef20 100644 --- a/commands/pull_request.go +++ b/commands/pull_request.go @@ -156,9 +156,23 @@ func pullRequest(cmd *Command, args *Args) { } } + baseTracking := base + headTracking := head + + remote := gitRemoteForProject(baseProject) + if remote != nil { + baseTracking = remote.Name + "/" + base + } + if remote == nil || !baseProject.SameAs(headProject) { + remote = gitRemoteForProject(headProject) + } + if remote != nil { + headTracking = remote.Name + "/" + head + } + var editor *github.Editor if title == "" && flagPullRequestIssue == "" { - message, err := pullRequestChangesMessage(base, head, fullBase, fullHead) + message, err := pullRequestChangesMessage(baseTracking, headTracking, fullBase, fullHead) utils.Check(err) editor, err = github.NewEditor("PULLREQ", "pull request", message) diff --git a/commands/pull_request_tpl.go b/commands/pull_request_tpl.go index 87d1951ee7365193c7d46c0932459a4f0f53da99..dd2c11e64b62228a2c71d5fce4692527cb13e44b 100644 --- a/commands/pull_request_tpl.go +++ b/commands/pull_request_tpl.go @@ -8,12 +8,12 @@ import ( "strings" ) -const pullRequestTmpl = `{{if .InitMsg}}{{.InitMsg}}{{end}} - +const pullRequestTmpl = `{{if .InitMsg}}{{.InitMsg}} +{{end}} {{.CS}} Requesting a pull to {{.Base}} from {{.Head}} {{.CS}} {{.CS}} Write a message for this pull request. The first block -{{.CS}} of the text is the title and the rest is description.{{if .HasCommitLogs}} +{{.CS}} of text is the title and the rest is description.{{if .HasCommitLogs}} {{.CS}} {{.CS}} Changes: {{.CS}}{{if .HasCommitLogs}} diff --git a/commands/pull_request_tpl_test.go b/commands/pull_request_tpl_test.go index 33b00d9328dfbf7a5844bef715a8d1db158994f3..96fc4cffb270b3acd8863fc07589fcc086627dcc 100644 --- a/commands/pull_request_tpl_test.go +++ b/commands/pull_request_tpl_test.go @@ -15,7 +15,7 @@ func TestRenderPullRequestTpl(t *testing.T) { # Requesting a pull to base from head # # Write a message for this pull request. The first block -# of the text is the title and the rest is description. +# of text is the title and the rest is description. # # Changes: # diff --git a/commands/release.go b/commands/release.go index 90e1a4c0d5eb3ab41e6efa903d0a3e30dcbad461..1ef73734974f61861fc20fae070472375739f191 100644 --- a/commands/release.go +++ b/commands/release.go @@ -125,7 +125,7 @@ func writeReleaseTitleAndBody(project *github.Project, tag, currentBranch string # Creating release %s for %s from %s # # Write a message for this release. The first block -# of the text is the title and the rest is description. +# of text is the title and the rest is description. ` message = fmt.Sprintf(message, tag, project.Name, currentBranch) diff --git a/features/pull_request.feature b/features/pull_request.feature index 61a2f0770bc78a4fc5712c566d3b08d03a4beba6..71e289221d8bcf8cc7e7b62dc009743f329a98f4 100644 --- a/features/pull_request.feature +++ b/features/pull_request.feature @@ -89,6 +89,49 @@ Feature: hub pull-request When I successfully run `hub pull-request` Then the output should contain exactly "the://url\n" + Scenario: Message template should include git log summary between base and head + Given the text editor adds: + """ + Hello + """ + Given the GitHub API server: + """ + post('/repos/mislav/coral/pulls') { + status 500 + } + """ + Given I am on the "master" branch + And I make a commit with message "One on master" + And I make a commit with message "Two on master" + And the "master" branch is pushed to "origin/master" + Given I successfully run `git reset --hard HEAD~2` + And I successfully run `git checkout --quiet -B topic origin/master` + Given I make a commit with message "One on topic" + And I make a commit with message "Two on topic" + Given the "topic" branch is pushed to "origin/topic" + And I successfully run `git reset --hard HEAD~1` + When I run `hub pull-request` + Given the SHAs and timestamps are normalized in ".git/PULLREQ_EDITMSG" + Then the file ".git/PULLREQ_EDITMSG" should contain exactly: + """ + Hello + + +# Requesting a pull to mislav:master from mislav:topic +# +# Write a message for this pull request. The first block +# of text is the title and the rest is description. +# +# Changes: +# +# SHA1SHA (Hub, 0 seconds ago) +# Two on topic +# +# SHA1SHA (Hub, 0 seconds ago) +# One on topic + + """ + Scenario: Non-existing base Given the GitHub API server: """ diff --git a/features/steps.rb b/features/steps.rb index f4cac7245abc71d31aad034be733ade65862ac2f..4e6f4863ad9a406b60e3abad1e3a375d0bcb6a64 100644 --- a/features/steps.rb +++ b/features/steps.rb @@ -249,3 +249,11 @@ Given(/^the SSH config:$/) do |config_lines| FileUtils.mkdir_p(File.dirname(ssh_config)) File.open(ssh_config, 'w') {|f| f << config_lines } end + +Given(/^the SHAs and timestamps are normalized in "([^"]+)"$/) do |file| + in_current_dir do + contents = File.read(file) + contents.gsub!(/[0-9a-f]{7} \(Hub, \d seconds? ago\)/, "SHA1SHA (Hub, 0 seconds ago)") + File.open(file, "w") { |f| f.write(contents) } + end +end