Allow to set pull request milestone and labels.

Add the `-M/--milestone` and `-l/--labels` flags to `hub pull-request` to
set the milestone or tags when a pull request is created.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2015-08-05 14:29:51 -07:00
Родитель 4c018ba9d5
Коммит 2ab5c55589
3 изменённых файлов: 47 добавлений и 6 удалений

Просмотреть файл

@ -41,9 +41,11 @@ var (
flagPullRequestIssue, flagPullRequestIssue,
flagPullRequestMessage, flagPullRequestMessage,
flagPullRequestAssignee, flagPullRequestAssignee,
flagPullRequestLabels,
flagPullRequestFile string flagPullRequestFile string
flagPullRequestBrowse, flagPullRequestBrowse,
flagPullRequestForce bool flagPullRequestForce bool
flagPullRequestMilestone uint64
) )
func init() { func init() {
@ -55,6 +57,8 @@ func init() {
cmdPullRequest.Flag.BoolVarP(&flagPullRequestForce, "force", "f", false, "FORCE") cmdPullRequest.Flag.BoolVarP(&flagPullRequestForce, "force", "f", false, "FORCE")
cmdPullRequest.Flag.StringVarP(&flagPullRequestFile, "file", "F", "", "FILE") cmdPullRequest.Flag.StringVarP(&flagPullRequestFile, "file", "F", "", "FILE")
cmdPullRequest.Flag.StringVarP(&flagPullRequestAssignee, "assign", "a", "", "USER") cmdPullRequest.Flag.StringVarP(&flagPullRequestAssignee, "assign", "a", "", "USER")
cmdPullRequest.Flag.Uint64VarP(&flagPullRequestMilestone, "milestone", "M", 0, "MILESTONE")
cmdPullRequest.Flag.StringVarP(&flagPullRequestLabels, "labels", "l", "", "LABELS")
CmdRunner.Use(cmdPullRequest) CmdRunner.Use(cmdPullRequest)
} }
@ -215,8 +219,16 @@ func pullRequest(cmd *Command, args *Args) {
pullRequestURL = pr.HTMLURL pullRequestURL = pr.HTMLURL
if flagPullRequestAssignee != "" { if flagPullRequestAssignee != "" || flagPullRequestMilestone > 0 ||
err = client.UpdateIssueAssignee(baseProject, pr.Number, flagPullRequestAssignee) flagPullRequestLabels != "" {
params := octokit.IssueParams{
Assignee: flagPullRequestAssignee,
Milestone: flagPullRequestMilestone,
Labels: strings.Split(flagPullRequestLabels, ","),
}
err = client.UpdateIssue(baseProject, pr.Number, params)
utils.Check(err) utils.Check(err)
} }
} }

Просмотреть файл

@ -611,3 +611,35 @@ Feature: hub pull-request
""" """
When I successfully run `hub pull-request -m hereyougo -a mislav` When I successfully run `hub pull-request -m hereyougo -a mislav`
Then the output should contain exactly "the://url\n" Then the output should contain exactly "the://url\n"
Scenario: Pull request with milestone
Given I am on the "feature" branch with upstream "origin/feature"
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
assert :head => "mislav:feature"
json :html_url => "the://url", :number => 1234
}
patch('/repos/mislav/coral/issues/1234') {
assert :milestone => 1234
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m hereyougo -M 1234`
Then the output should contain exactly "the://url\n"
Scenario: Pull request with labels
Given I am on the "feature" branch with upstream "origin/feature"
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
assert :head => "mislav:feature"
json :html_url => "the://url", :number => 1234
}
patch('/repos/mislav/coral/issues/1234') {
assert :labels => ["feature", "release"]
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m hereyougo -l feature,release`
Then the output should contain exactly "the://url\n"

Просмотреть файл

@ -428,7 +428,7 @@ func (client *Client) CreateIssue(project *Project, title, body string, labels [
return return
} }
func (client *Client) UpdateIssueAssignee(project *Project, issueNumber int, assignee string) (err error) { func (client *Client) UpdateIssue(project *Project, issueNumber int, params octokit.IssueParams) (err error) {
url, err := octokit.RepoIssuesURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name, "number": issueNumber}) url, err := octokit.RepoIssuesURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name, "number": issueNumber})
if err != nil { if err != nil {
return return
@ -440,9 +440,6 @@ func (client *Client) UpdateIssueAssignee(project *Project, issueNumber int, ass
return return
} }
params := octokit.IssueParams{
Assignee: assignee,
}
_, result := api.Issues(client.requestURL(url)).Update(params) _, result := api.Issues(client.requestURL(url)).Update(params)
if result.HasError() { if result.HasError() {
err = FormatError("updating issue", result.Err) err = FormatError("updating issue", result.Err)