Add support for review requests in pull-request command

上级 aebccad8
......@@ -17,7 +17,7 @@ import (
var cmdPullRequest = &Command{
Run: pullRequest,
Usage: `
pull-request [-foc] [-b <BASE>] [-h <HEAD>] [-a <USERS>] [-M <MILESTONE>] [-l <LABELS>]
pull-request [-foc] [-b <BASE>] [-h <HEAD>] [-r <REVIEWERS> ] [-a <ASSIGNEES>] [-M <MILESTONE>] [-l <LABELS>]
pull-request -m <MESSAGE>
pull-request -F <FILE> [--edit]
pull-request -i <ISSUE>
......@@ -57,6 +57,9 @@ pull-request -i <ISSUE>
-h, --head <HEAD>
The head branch in "[OWNER:]BRANCH" format. Defaults to the current branch.
-r, --reviewer <USERS>
A comma-separated list of GitHub handles to request a review from.
-a, --assign <USERS>
A comma-separated list of GitHub handles to assign to this pull request.
......@@ -93,6 +96,7 @@ var (
flagPullRequestMilestone uint64
flagPullRequestAssignees,
flagPullRequestReviewers,
flagPullRequestLabels listFlag
)
......@@ -108,6 +112,7 @@ func init() {
cmdPullRequest.Flag.BoolVarP(&flagPullRequestForce, "force", "f", false, "FORCE")
cmdPullRequest.Flag.StringVarP(&flagPullRequestFile, "file", "F", "", "FILE")
cmdPullRequest.Flag.VarP(&flagPullRequestAssignees, "assign", "a", "USERS")
cmdPullRequest.Flag.VarP(&flagPullRequestReviewers, "reviewer", "r", "USERS")
cmdPullRequest.Flag.Uint64VarP(&flagPullRequestMilestone, "milestone", "M", 0, "MILESTONE")
cmdPullRequest.Flag.VarP(&flagPullRequestLabels, "labels", "l", "LABELS")
......@@ -329,6 +334,11 @@ func pullRequest(cmd *Command, args *Args) {
err = client.UpdateIssue(baseProject, pr.Number, params)
utils.Check(err)
}
if len(flagPullRequestReviewers) > 0 {
err = client.RequestReview(baseProject, pr.Number, map[string]interface{}{"reviewers": flagPullRequestReviewers})
utils.Check(err)
}
}
if flagPullRequestIssue != "" {
......
......@@ -733,6 +733,23 @@ BODY
When I successfully run `hub pull-request -m hereyougo -a mislav,josh -apcorpet`
Then the output should contain exactly "the://url\n"
Scenario: Pull request with reviewers
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"
status 201
json :html_url => "the://url", :number => 1234
}
post('/repos/mislav/coral/pulls/1234/requested_reviewers') {
assert :reviewers => ["mislav", "josh", "pcorpet"]
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m hereyougo -r mislav,josh -rpcorpet`
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:
......
......@@ -22,6 +22,9 @@ const (
var UserAgent = "Hub " + version.Version
const apiPayloadVersion = "application/vnd.github.v3+json;charset=utf-8"
const previewApiPayloadVersion = "application/vnd.github.black-cat-preview+json;charset=utf-8"
func NewClient(h string) *Client {
return NewClientWithHost(&Host{Host: h})
}
......@@ -134,6 +137,21 @@ func (client *Client) CreatePullRequest(project *Project, params map[string]inte
return
}
func (client *Client) RequestReview(project *Project, prNumber int, params map[string]interface{}) (err error) {
api, err := client.previewSimpleApi()
if err != nil {
return
}
res, err := api.PostJSON(fmt.Sprintf("repos/%s/%s/pulls/%d/requested_reviewers", project.Owner, project.Name, prNumber), params)
if err = checkStatus(200, "requesting reviewer", res, err); err != nil {
return
}
res.Body.Close()
return
}
func (client *Client) CommitPatch(project *Project, sha string) (patch io.ReadCloser, err error) {
url, err := octokit.CommitsURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name, "sha": sha})
if err != nil {
......@@ -641,9 +659,28 @@ func (client *Client) simpleApi() (c *simpleClient, err error) {
apiRoot := client.requestURL(client.absolute(normalizeHost(client.Host.Host)))
c = &simpleClient{
httpClient: httpClient,
rootUrl: apiRoot,
accessToken: client.Host.AccessToken,
httpClient: httpClient,
rootUrl: apiRoot,
accessToken: client.Host.AccessToken,
apiPayloadVersion: apiPayloadVersion,
}
return
}
func (client *Client) previewSimpleApi() (c *simpleClient, err error) {
err = client.ensureAccessToken()
if err != nil {
return
}
httpClient := newHttpClient(os.Getenv("HUB_TEST_HOST"), os.Getenv("HUB_VERBOSE") != "")
apiRoot := client.requestURL(client.absolute(normalizeHost(client.Host.Host)))
c = &simpleClient{
httpClient: httpClient,
rootUrl: apiRoot,
accessToken: client.Host.AccessToken,
apiPayloadVersion: previewApiPayloadVersion,
}
return
}
......
......@@ -18,8 +18,6 @@ import (
"github.com/github/hub/utils"
)
const apiPayloadVersion = "application/vnd.github.v3+json;charset=utf-8"
type verboseTransport struct {
Transport *http.Transport
Verbose bool
......@@ -193,9 +191,10 @@ func proxyFromEnvironment(req *http.Request) (*url.URL, error) {
}
type simpleClient struct {
httpClient *http.Client
rootUrl *url.URL
accessToken string
httpClient *http.Client
rootUrl *url.URL
accessToken string
apiPayloadVersion string
}
func (c *simpleClient) performRequest(method, path string, body io.Reader, configure func(*http.Request)) (*simpleResponse, error) {
......@@ -215,7 +214,7 @@ func (c *simpleClient) performRequestUrl(method string, url *url.URL, body io.Re
}
req.Header.Set("Authorization", "token "+c.accessToken)
req.Header.Set("User-Agent", UserAgent)
req.Header.Set("Accept", apiPayloadVersion)
req.Header.Set("Accept", c.apiPayloadVersion)
if configure != nil {
configure(req)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册