Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
a7426780
H
hub
项目概览
github
/
hub
8 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
提交
a7426780
编写于
6月 14, 2019
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[pr show] Add ability to open a pull request based on number
上级
7a620665
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
12 deletion
+42
-12
commands/pr.go
commands/pr.go
+30
-12
features/pr-show.feature
features/pr-show.feature
+12
-0
未找到文件。
commands/pr.go
浏览文件 @
a7426780
...
...
@@ -17,6 +17,7 @@ var (
pr list [-s <STATE>] [-h <HEAD>] [-b <BASE>] [-o <SORT_KEY> [-^]] [-f <FORMAT>] [-L <LIMIT>]
pr checkout <PR-NUMBER> [<BRANCH>]
pr show [-uc] [-h <HEAD>]
pr show [-uc] <PR-NUMBER>
`
,
Long
:
`Manage GitHub Pull Requests for the current repository.
...
...
@@ -29,7 +30,7 @@ pr show [-uc] [-h <HEAD>]
Check out the head of a pull request in a new branch.
* _show_:
Open
the GitHub
pull request page in a web browser.
Open
a
pull request page in a web browser.
## Options:
...
...
@@ -283,6 +284,27 @@ func showPr(command *Command, args *Args) {
baseProject
,
err
:=
localRepo
.
MainProject
()
utils
.
Check
(
err
)
words
:=
args
.
Words
()
openUrl
:=
""
if
len
(
words
)
>
0
{
if
prNumber
,
err
:=
strconv
.
Atoi
(
words
[
0
]);
err
==
nil
{
openUrl
=
baseProject
.
WebURL
(
""
,
""
,
fmt
.
Sprintf
(
"pull/%d"
,
prNumber
))
}
else
{
utils
.
Check
(
fmt
.
Errorf
(
"invalid pull request number: '%s'"
,
words
[
0
]))
}
}
else
{
pr
,
err
:=
findCurrentPullRequest
(
localRepo
,
baseProject
,
args
.
Flag
.
Value
(
"--head"
))
utils
.
Check
(
err
)
openUrl
=
pr
.
HtmlUrl
}
args
.
NoForward
()
printUrl
:=
args
.
Flag
.
Bool
(
"--url"
)
copyUrl
:=
args
.
Flag
.
Bool
(
"--copy"
)
printBrowseOrCopy
(
args
,
openUrl
,
!
printUrl
&&
!
copyUrl
,
copyUrl
)
}
func
findCurrentPullRequest
(
localRepo
*
github
.
GitHubRepo
,
baseProject
*
github
.
Project
,
headArg
string
)
(
*
github
.
PullRequest
,
error
)
{
host
,
err
:=
github
.
CurrentConfig
()
.
PromptForHost
(
baseProject
.
Host
)
utils
.
Check
(
err
)
gh
:=
github
.
NewClientWithHost
(
host
)
...
...
@@ -292,8 +314,8 @@ func showPr(command *Command, args *Args) {
}
headWithOwner
:=
""
if
args
.
Flag
.
HasReceived
(
"--head"
)
{
headWithOwner
=
args
.
Flag
.
Value
(
"--head"
)
if
headArg
!=
""
{
headWithOwner
=
headArg
if
!
strings
.
Contains
(
headWithOwner
,
":"
)
{
headWithOwner
=
fmt
.
Sprintf
(
"%s:%s"
,
baseProject
.
Owner
,
headWithOwner
)
}
...
...
@@ -311,16 +333,12 @@ func showPr(command *Command, args *Args) {
filterParams
[
"head"
]
=
headWithOwner
pulls
,
err
:=
gh
.
FetchPullRequests
(
baseProject
,
filterParams
,
1
,
nil
)
utils
.
Check
(
err
)
if
len
(
pulls
)
==
1
{
pr
:=
pulls
[
0
]
args
.
NoForward
()
flagBrowseURLPrint
:=
args
.
Flag
.
Bool
(
"--url"
)
flagBrowseURLCopy
:=
args
.
Flag
.
Bool
(
"--copy"
)
printBrowseOrCopy
(
args
,
pr
.
HtmlUrl
,
!
flagBrowseURLPrint
&&
!
flagBrowseURLCopy
,
flagBrowseURLCopy
)
if
err
!=
nil
{
return
nil
,
err
}
else
if
len
(
pulls
)
==
1
{
return
&
pulls
[
0
],
nil
}
else
{
utils
.
Check
(
fmt
.
Errorf
(
"no open pull requests found for branch '%s'"
,
headWithOwner
)
)
return
nil
,
fmt
.
Errorf
(
"no open pull requests found for branch '%s'"
,
headWithOwner
)
}
}
...
...
features/pr-show.feature
浏览文件 @
a7426780
...
...
@@ -94,3 +94,15 @@ Feature: hub pr show
"""
no open pull requests found for branch 'ashemesh:topic'\n
"""
Scenario
:
Show pull request by number
When
I successfully run `hub pr show 102`
Then "open https
:
//github.com/ashemesh/hub/pull/102"
should
be
run
Scenario
:
Show pull request by invalid number
When
I run `hub pr show XYZ`
Then
the exit status should be 1
And the stderr should contain exactly
:
"""
invalid pull request number: 'XYZ'\n
"""
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录