Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
48092d4f
H
hub
项目概览
github
/
hub
10 个月 前同步成功
通知
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 搜索 >>
提交
48092d4f
编写于
10月 08, 2019
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[pr show] Avoid duplicate API requests
上级
dcf47d6c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
38 addition
and
40 deletion
+38
-40
commands/pr.go
commands/pr.go
+30
-25
features/pr-show.feature
features/pr-show.feature
+8
-15
未找到文件。
commands/pr.go
浏览文件 @
48092d4f
...
...
@@ -17,8 +17,8 @@ var (
Usage
:
`
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>] [-f <FORMAT
>]
pr show [-uc] <PR-NUMBER>
pr show [-uc] [-
f <FORMAT>] [-h <HEAD
>]
pr show [-uc]
[-f <FORMAT>]
<PR-NUMBER>
`
,
Long
:
`Manage GitHub Pull Requests for the current repository.
...
...
@@ -160,9 +160,15 @@ hub-issue(1), hub-pull-request(1), hub(1)
}
cmdShowPr
=
&
Command
{
Key
:
"show"
,
Run
:
showPr
,
Long
:
cmdPr
.
Long
,
Key
:
"show"
,
Run
:
showPr
,
KnownFlags
:
`
-h, --head HEAD
-u, --url
-c, --copy
-f, --format FORMAT
--color
`
,
}
)
...
...
@@ -277,9 +283,15 @@ func showPr(command *Command, args *Args) {
baseProject
,
err
:=
localRepo
.
MainProject
()
utils
.
Check
(
err
)
host
,
err
:=
github
.
CurrentConfig
()
.
PromptForHost
(
baseProject
.
Host
)
utils
.
Check
(
err
)
gh
:=
github
.
NewClientWithHost
(
host
)
words
:=
args
.
Words
()
openUrl
:=
""
prNumber
:=
0
var
pr
*
github
.
PullRequest
if
len
(
words
)
>
0
{
if
prNumber
,
err
=
strconv
.
Atoi
(
words
[
0
]);
err
==
nil
{
openUrl
=
baseProject
.
WebURL
(
""
,
""
,
fmt
.
Sprintf
(
"pull/%d"
,
prNumber
))
...
...
@@ -287,36 +299,29 @@ func showPr(command *Command, args *Args) {
utils
.
Check
(
fmt
.
Errorf
(
"invalid pull request number: '%s'"
,
words
[
0
]))
}
}
else
{
pr
,
err
:=
findCurrentPullRequest
(
localRepo
,
baseProject
,
args
.
Flag
.
Value
(
"--head"
))
pr
,
err
=
findCurrentPullRequest
(
localRepo
,
gh
,
baseProject
,
args
.
Flag
.
Value
(
"--head"
))
utils
.
Check
(
err
)
openUrl
=
pr
.
HtmlUrl
prNumber
=
pr
.
Number
}
args
.
NoForward
()
if
format
:=
args
.
Flag
.
Value
(
"--format"
);
format
!=
""
{
host
,
err
:=
github
.
CurrentConfig
()
.
PromptForHost
(
baseProject
.
Host
)
utils
.
Check
(
err
)
client
:=
github
.
NewClientWithHost
(
host
)
pr
,
err
:=
client
.
PullRequest
(
baseProject
,
strconv
.
Itoa
(
prNumber
))
utils
.
Check
(
err
)
// ui.Println(pr.Number)
if
pr
==
nil
{
pr
,
err
=
gh
.
PullRequest
(
baseProject
,
strconv
.
Itoa
(
prNumber
))
utils
.
Check
(
err
)
}
colorize
:=
colorizeOutput
(
args
.
Flag
.
HasReceived
(
"--color"
),
args
.
Flag
.
Value
(
"--color"
))
ui
.
Println
(
formatPullRequest
(
*
pr
,
format
,
colorize
))
}
else
{
printUrl
:=
args
.
Flag
.
Bool
(
"--url"
)
copyUrl
:=
args
.
Flag
.
Bool
(
"--copy"
)
printBrowseOrCopy
(
args
,
openUrl
,
!
printUrl
&&
!
copyUrl
,
copyUrl
)
return
}
}
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
)
printUrl
:=
args
.
Flag
.
Bool
(
"--url"
)
copyUrl
:=
args
.
Flag
.
Bool
(
"--copy"
)
printBrowseOrCopy
(
args
,
openUrl
,
!
printUrl
&&
!
copyUrl
,
copyUrl
)
}
func
findCurrentPullRequest
(
localRepo
*
github
.
GitHubRepo
,
gh
*
github
.
Client
,
baseProject
*
github
.
Project
,
headArg
string
)
(
*
github
.
PullRequest
,
error
)
{
filterParams
:=
map
[
string
]
interface
{}{
"state"
:
"open"
,
}
...
...
@@ -332,7 +337,7 @@ func findCurrentPullRequest(localRepo *github.GitHubRepo, baseProject *github.Pr
utils
.
Check
(
err
)
if
headBranch
,
headProject
,
err
:=
findPushTarget
(
currentBranch
);
err
==
nil
{
headWithOwner
=
fmt
.
Sprintf
(
"%s:%s"
,
headProject
.
Owner
,
headBranch
.
ShortName
())
}
else
if
headProject
,
err
:=
deducePushTarget
(
currentBranch
,
h
ost
.
User
);
err
==
nil
{
}
else
if
headProject
,
err
:=
deducePushTarget
(
currentBranch
,
gh
.
H
ost
.
User
);
err
==
nil
{
headWithOwner
=
fmt
.
Sprintf
(
"%s:%s"
,
headProject
.
Owner
,
currentBranch
.
ShortName
())
}
else
{
headWithOwner
=
fmt
.
Sprintf
(
"%s:%s"
,
baseProject
.
Owner
,
currentBranch
.
ShortName
())
...
...
features/pr-show.feature
浏览文件 @
48092d4f
...
...
@@ -44,17 +44,8 @@ Feature: hub pr show
get('/repos/ashemesh/hub/pulls'){
assert :state => "open",
:head => "ashemesh:topic"
json [
{
:html_url => "https://github.com/ashemesh/hub/pull/102",
:number => 102
},
]
}
get('/repos/ashemesh/hub/pulls/102') {
json :number => 999,
:title => "First",
json [{
:number => 102,
:state => "open",
:base => {
:ref => "master",
...
...
@@ -69,14 +60,16 @@ Feature: hub pr show
:requested_teams => [
{ :slug => "troopers" },
{ :slug => "cantina-band" },
]
],
:html_url => "https://github.com/ashemesh/hub/pull/102",
}]
}
"""
When
I successfully run `hub pr show -f
"%sC%>(8)%i %rs%n"
`
Then "open https
:
//github.com/ashemesh/hub/pull/102"
should
not
be
run
And the output should contain exactly
:
"""
#
999
rey, github/troopers, github/cantina-band\n
#
102
rey, github/troopers, github/cantina-band\n
"""
Scenario
:
Current branch in fork
...
...
@@ -192,7 +185,7 @@ Feature: hub pr show
Given the GitHub API server
:
"""
get('/repos/ashemesh/hub/pulls/102') {
json :number =>
999
,
json :number =>
102
,
:title => "First",
:state => "open",
:base => {
...
...
@@ -215,7 +208,7 @@ Feature: hub pr show
Then "open https
:
//github.com/ashemesh/hub/pull/102"
should
not
be
run
And the output should contain exactly
:
"""
#
999
rey, github/troopers, github/cantina-band\n
#
102
rey, github/troopers, github/cantina-band\n
"""
Scenario
:
Show pull request by invalid number
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录