Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
698f1508
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 搜索 >>
未验证
提交
698f1508
编写于
2月 18, 2019
作者:
M
Mislav Marohnić
提交者:
GitHub
2月 18, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2045 from github/pr-drafts
List PR "Draft" state using the `--format` string
上级
2b67d8c3
d2193739
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
90 addition
and
6 deletion
+90
-6
commands/issue.go
commands/issue.go
+26
-1
commands/pr.go
commands/pr.go
+8
-4
features/pr-list.feature
features/pr-list.feature
+51
-0
features/support/env.rb
features/support/env.rb
+2
-0
github/client.go
github/client.go
+2
-1
github/http.go
github/http.go
+1
-0
未找到文件。
commands/issue.go
浏览文件 @
698f1508
...
...
@@ -385,7 +385,30 @@ func formatIssuePlaceholders(issue github.Issue, colorize bool) map[string]strin
}
}
func
formatPullRequestPlaceholders
(
pr
github
.
PullRequest
)
map
[
string
]
string
{
func
formatPullRequestPlaceholders
(
pr
github
.
PullRequest
,
colorize
bool
)
map
[
string
]
string
{
prState
:=
pr
.
State
if
prState
==
"open"
&&
pr
.
Draft
{
prState
=
"draft"
}
else
if
!
pr
.
MergedAt
.
IsZero
()
{
prState
=
"merged"
}
var
stateColorSwitch
string
var
prColor
int
if
colorize
{
switch
prState
{
case
"draft"
:
prColor
=
37
case
"merged"
:
prColor
=
35
case
"closed"
:
prColor
=
31
default
:
prColor
=
32
}
stateColorSwitch
=
fmt
.
Sprintf
(
"
\0
33[%dm"
,
prColor
)
}
base
:=
pr
.
Base
.
Ref
head
:=
pr
.
Head
.
Label
if
pr
.
IsSameRepo
()
{
...
...
@@ -410,6 +433,8 @@ func formatPullRequestPlaceholders(pr github.PullRequest) map[string]string {
}
return
map
[
string
]
string
{
"pS"
:
prState
,
"pC"
:
stateColorSwitch
,
"B"
:
base
,
"H"
:
head
,
"sB"
:
pr
.
Base
.
Sha
,
...
...
commands/pr.go
浏览文件 @
698f1508
...
...
@@ -42,7 +42,7 @@ pr checkout <PR-NUMBER> [<BRANCH>]
-f, --format <FORMAT>
Pretty print the list of pull requests using format <FORMAT> (default:
"%
s
C%>(8)%i%Creset %t% l%n"). See the "PRETTY FORMATS" section of
"%
p
C%>(8)%i%Creset %t% l%n"). See the "PRETTY FORMATS" section of
git-log(1) for some additional details on how placeholders are used in
format. The available placeholders are:
...
...
@@ -54,7 +54,11 @@ pr checkout <PR-NUMBER> [<BRANCH>]
%S: state ("open" or "closed")
%sC: set color to red or green, depending on pull request state.
%pS: pull request state ("open", "draft", "merged", or "closed")
%sC: set color to red or green, depending on state
%pC: set color according to pull request state
%t: title
...
...
@@ -206,7 +210,7 @@ func listPulls(cmd *Command, args *Args) {
flagPullRequestLimit
:=
args
.
Flag
.
Int
(
"--limit"
)
flagPullRequestFormat
:=
args
.
Flag
.
Value
(
"--format"
)
if
!
args
.
Flag
.
HasReceived
(
"--format"
)
{
flagPullRequestFormat
=
"%
s
C%>(8)%i%Creset %t% l%n"
flagPullRequestFormat
=
"%
p
C%>(8)%i%Creset %t% l%n"
}
pulls
,
err
:=
gh
.
FetchPullRequests
(
project
,
filters
,
flagPullRequestLimit
,
func
(
pr
*
github
.
PullRequest
)
bool
{
...
...
@@ -253,7 +257,7 @@ func checkoutPr(command *Command, args *Args) {
func
formatPullRequest
(
pr
github
.
PullRequest
,
format
string
,
colorize
bool
)
string
{
placeholders
:=
formatIssuePlaceholders
(
github
.
Issue
(
pr
),
colorize
)
for
key
,
value
:=
range
formatPullRequestPlaceholders
(
pr
)
{
for
key
,
value
:=
range
formatPullRequestPlaceholders
(
pr
,
colorize
)
{
placeholders
[
key
]
=
value
}
return
ui
.
Expand
(
format
,
placeholders
,
colorize
)
...
...
features/pr-list.feature
浏览文件 @
698f1508
...
...
@@ -112,6 +112,57 @@ Feature: hub pr list
#102 luke, jyn\n
"""
Scenario
:
List draft status
Given the GitHub API server
:
"""
get('/repos/github/hub/pulls') {
halt 400 unless env['HTTP_ACCEPT'] == 'application/vnd.github.shadow-cat-preview+json;charset=utf-8'
json [
{ :number => 999,
:state => "open",
:draft => true,
:merged_at => nil,
:base => { :ref => "master", :label => "github:master" },
:head => { :ref => "patch-2", :label => "octocat:patch-2" },
:user => { :login => "octocat" },
},
{ :number => 102,
:state => "open",
:draft => false,
:merged_at => nil,
:base => { :ref => "master", :label => "github:master" },
:head => { :ref => "patch-1", :label => "octocat:patch-1" },
:user => { :login => "octocat" },
},
{ :number => 42,
:state => "closed",
:draft => false,
:merged_at => "2018-12-11T10:50:33Z",
:base => { :ref => "master", :label => "github:master" },
:head => { :ref => "patch-3", :label => "octocat:patch-3" },
:user => { :login => "octocat" },
},
{ :number => 8,
:state => "closed",
:draft => false,
:merged_at => nil,
:base => { :ref => "master", :label => "github:master" },
:head => { :ref => "patch-4", :label => "octocat:patch-4" },
:user => { :login => "octocat" },
},
]
}
"""
When
I successfully run `hub pr list --format
"%I %pC %pS %Creset%n"
--color`
Then the output should contain exactly
:
"""
999 \e[37m draft \e[m
102 \e[32m open \e[m
42 \e[35m merged \e[m
8 \e[31m closed \e[m\n
"""
Scenario
:
Sort by number of comments ascending
Given the GitHub API server
:
"""
...
...
features/support/env.rb
浏览文件 @
698f1508
...
...
@@ -58,6 +58,8 @@ Before do
# increase process exit timeout from the default of 3 seconds
@aruba_timeout_seconds
=
10
# don't be "helpful"
@aruba_keep_ansi
=
true
end
After
do
...
...
github/client.go
浏览文件 @
698f1508
...
...
@@ -58,7 +58,7 @@ func (client *Client) FetchPullRequests(project *Project, filterParams map[strin
var
res
*
simpleResponse
for
path
!=
""
{
res
,
err
=
api
.
Get
(
path
)
res
,
err
=
api
.
Get
File
(
path
,
draftsType
)
if
err
=
checkStatus
(
200
,
"fetching pull requests"
,
res
,
err
);
err
!=
nil
{
return
}
...
...
@@ -563,6 +563,7 @@ type Issue struct {
MergeCommitSha
string
`json:"merge_commit_sha"`
MaintainerCanModify
bool
`json:"maintainer_can_modify"`
Draft
bool
`json:"draft"`
Comments
int
`json:"comments"`
Labels
[]
IssueLabel
`json:"labels"`
...
...
github/http.go
浏览文件 @
698f1508
...
...
@@ -28,6 +28,7 @@ const apiPayloadVersion = "application/vnd.github.v3+json;charset=utf-8"
const
patchMediaType
=
"application/vnd.github.v3.patch;charset=utf-8"
const
textMediaType
=
"text/plain;charset=utf-8"
const
checksType
=
"application/vnd.github.antiope-preview+json;charset=utf-8"
const
draftsType
=
"application/vnd.github.shadow-cat-preview+json;charset=utf-8"
var
inspectHeaders
=
[]
string
{
"Authorization"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录