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

[pull-request] Tweak & test opening a PR as a draft

上级 b207e803
......@@ -16,7 +16,7 @@ import (
var cmdPullRequest = &Command{
Run: pullRequest,
Usage: `
pull-request [-focp] [-b <BASE>] [-h <HEAD>] [-r <REVIEWERS> ] [-a <ASSIGNEES>] [-M <MILESTONE>] [-l <LABELS>] [--draft]
pull-request [-focpd] [-b <BASE>] [-h <HEAD>] [-r <REVIEWERS> ] [-a <ASSIGNEES>] [-M <MILESTONE>] [-l <LABELS>]
pull-request -m <MESSAGE> [--edit]
pull-request -F <FILE> [--edit]
pull-request -i <ISSUE>
......@@ -312,20 +312,17 @@ of text is the title and the rest is the description.`, fullBase, fullHead))
}
}
draft := args.Flag.Bool("--draft")
var pullRequestURL string
if args.Noop {
args.Before(fmt.Sprintf("Would request a pull request to %s from %s", fullBase, fullHead), "")
pullRequestURL = "PULL_REQUEST_URL"
} else {
params := map[string]interface{}{
"base": base,
"head": fullHead,
"base": base,
"head": fullHead,
"draft": args.Flag.Bool("--draft"),
}
params["draft"] = draft
if title != "" {
params["title"] = title
if body != "" {
......
......@@ -4,6 +4,25 @@ Feature: hub pull-request
And I am "mislav" on github.com with OAuth token "OTOKEN"
And the git commit editor is "vim"
Scenario: Basic pull request
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.shadow-cat-preview+json;charset=utf-8'
halt 400 if (params.keys - %w[title body base head draft issue]).any?
assert :title => 'hello',
:body => nil,
:base => 'master',
:head => 'mislav:master',
:draft => false,
:issue => nil
status 201
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m hello`
Then the output should contain exactly "the://url\n"
Scenario: Detached HEAD
Given I am in detached HEAD
When I run `hub pull-request`
......@@ -1232,3 +1251,16 @@ Feature: hub pull-request
"""
And the output should match /Given up after retrying for 5\.\d seconds\./
And a file named ".git/PULLREQ_EDITMSG" should exist
Scenario: Draft pull request
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.shadow-cat-preview+json;charset=utf-8'
assert :draft => true
status 201
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -d -m wip`
Then the output should contain exactly "the://url\n"
......@@ -119,7 +119,7 @@ func (client *Client) CreatePullRequest(project *Project, params map[string]inte
return
}
res, err := api.PostJSON(fmt.Sprintf("repos/%s/%s/pulls", project.Owner, project.Name), params)
res, err := api.PostJSONPreview(fmt.Sprintf("repos/%s/%s/pulls", project.Owner, project.Name), params, draftsType)
if err = checkStatus(201, "creating pull request", res, err); err != nil {
if res != nil && res.StatusCode == 404 {
projectUrl := strings.SplitN(project.WebURL("", "", ""), "://", 2)[1]
......
......@@ -409,7 +409,6 @@ func (c *simpleClient) jsonRequest(method, path string, body interface{}, config
return c.performRequest(method, path, buf, func(req *http.Request) {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
req.Header.Set("Accept", "application/vnd.github.shadow-cat-preview")
if configure != nil {
configure(req)
}
......@@ -434,6 +433,12 @@ func (c *simpleClient) PostJSON(path string, payload interface{}) (*simpleRespon
return c.jsonRequest("POST", path, payload, nil)
}
func (c *simpleClient) PostJSONPreview(path string, payload interface{}, mimeType string) (*simpleResponse, error) {
return c.jsonRequest("POST", path, payload, func(req *http.Request) {
req.Header.Set("Accept", mimeType)
})
}
func (c *simpleClient) PatchJSON(path string, payload interface{}) (*simpleResponse, error) {
return c.jsonRequest("PATCH", path, payload, nil)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册