提交 2113b100 编写于 作者: M Mislav Marohnić

Merge pull request #645 from github/base-head-upstream

Fix git commit summary in pull request message template
...@@ -95,7 +95,7 @@ func writeIssueTitleAndBody(project *github.Project) (string, string, error) { ...@@ -95,7 +95,7 @@ func writeIssueTitleAndBody(project *github.Project) (string, string, error) {
# Creating issue for %s. # Creating issue for %s.
# #
# Write a message for this issue. The first block # 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) message = fmt.Sprintf(message, project.Name)
......
...@@ -156,9 +156,23 @@ func pullRequest(cmd *Command, args *Args) { ...@@ -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 var editor *github.Editor
if title == "" && flagPullRequestIssue == "" { if title == "" && flagPullRequestIssue == "" {
message, err := pullRequestChangesMessage(base, head, fullBase, fullHead) message, err := pullRequestChangesMessage(baseTracking, headTracking, fullBase, fullHead)
utils.Check(err) utils.Check(err)
editor, err = github.NewEditor("PULLREQ", "pull request", message) editor, err = github.NewEditor("PULLREQ", "pull request", message)
......
...@@ -8,12 +8,12 @@ import ( ...@@ -8,12 +8,12 @@ import (
"strings" "strings"
) )
const pullRequestTmpl = `{{if .InitMsg}}{{.InitMsg}}{{end}} const pullRequestTmpl = `{{if .InitMsg}}{{.InitMsg}}
{{end}}
{{.CS}} Requesting a pull to {{.Base}} from {{.Head}} {{.CS}} Requesting a pull to {{.Base}} from {{.Head}}
{{.CS}} {{.CS}}
{{.CS}} Write a message for this pull request. The first block {{.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}}
{{.CS}} Changes: {{.CS}} Changes:
{{.CS}}{{if .HasCommitLogs}} {{.CS}}{{if .HasCommitLogs}}
......
...@@ -15,7 +15,7 @@ func TestRenderPullRequestTpl(t *testing.T) { ...@@ -15,7 +15,7 @@ func TestRenderPullRequestTpl(t *testing.T) {
# Requesting a pull to base from head # Requesting a pull to base from head
# #
# Write a message for this pull request. The first block # 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: # Changes:
# #
......
...@@ -125,7 +125,7 @@ func writeReleaseTitleAndBody(project *github.Project, tag, currentBranch string ...@@ -125,7 +125,7 @@ func writeReleaseTitleAndBody(project *github.Project, tag, currentBranch string
# Creating release %s for %s from %s # Creating release %s for %s from %s
# #
# Write a message for this release. The first block # 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) message = fmt.Sprintf(message, tag, project.Name, currentBranch)
......
...@@ -89,6 +89,49 @@ Feature: hub pull-request ...@@ -89,6 +89,49 @@ Feature: hub pull-request
When I successfully run `hub pull-request` When I successfully run `hub pull-request`
Then the output should contain exactly "the://url\n" 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 Scenario: Non-existing base
Given the GitHub API server: Given the GitHub API server:
""" """
......
...@@ -249,3 +249,11 @@ Given(/^the SSH config:$/) do |config_lines| ...@@ -249,3 +249,11 @@ Given(/^the SSH config:$/) do |config_lines|
FileUtils.mkdir_p(File.dirname(ssh_config)) FileUtils.mkdir_p(File.dirname(ssh_config))
File.open(ssh_config, 'w') {|f| f << config_lines } File.open(ssh_config, 'w') {|f| f << config_lines }
end 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册