Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
0fad5194
H
hub
项目概览
github
/
hub
大约 1 年 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0fad5194
编写于
4月 17, 2017
作者:
T
Tomas Varneckas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for review requests in pull-request command
上级
aebccad8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
73 addition
and
10 deletion
+73
-10
commands/pull_request.go
commands/pull_request.go
+11
-1
features/pull_request.feature
features/pull_request.feature
+17
-0
github/client.go
github/client.go
+40
-3
github/http.go
github/http.go
+5
-6
未找到文件。
commands/pull_request.go
浏览文件 @
0fad5194
...
...
@@ -17,7 +17,7 @@ import (
var
cmdPullRequest
=
&
Command
{
Run
:
pullRequest
,
Usage
:
`
pull-request [-foc] [-b <BASE>] [-h <HEAD>] [-
a <USER
S>] [-M <MILESTONE>] [-l <LABELS>]
pull-request [-foc] [-b <BASE>] [-h <HEAD>] [-
r <REVIEWERS> ] [-a <ASSIGNEE
S>] [-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
!=
""
{
...
...
features/pull_request.feature
浏览文件 @
0fad5194
...
...
@@ -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
:
...
...
github/client.go
浏览文件 @
0fad5194
...
...
@@ -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
}
...
...
github/http.go
浏览文件 @
0fad5194
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录