Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
df7b30a0
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 搜索 >>
提交
df7b30a0
编写于
1月 29, 2019
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ci-status] Add support for `--format` string
上级
cadc8d28
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
8 deletion
+67
-8
commands/ci_status.go
commands/ci_status.go
+33
-8
features/ci_status.feature
features/ci_status.feature
+34
-0
未找到文件。
commands/ci_status.go
浏览文件 @
df7b30a0
...
...
@@ -20,6 +20,19 @@ var cmdCiStatus = &Command{
-v, --verbose
Print detailed report of all status checks and their URLs.
-f, --format <FORMAT>
Pretty print all status checks using <FORMAT> (implies '--verbose'). See the
"PRETTY FORMATS" section of git-log(1) for some additional details on how
placeholders are used in format. The available placeholders for issues are:
%U: the URL of this status check
%S: check state (e.g. "success", "failure")
%sC: set color to red, green, or yellow, depending on state
%t: name of the status check
<COMMIT>
A commit SHA or branch name (default: "HEAD").
...
...
@@ -107,8 +120,9 @@ func ciStatus(cmd *Command, args *Args) {
exitCode
=
3
}
if
args
.
Flag
.
Bool
(
"--verbose"
)
&&
len
(
response
.
Statuses
)
>
0
{
verboseFormat
(
response
.
Statuses
)
verbose
:=
args
.
Flag
.
Bool
(
"--verbose"
)
||
args
.
Flag
.
HasReceived
(
"--format"
)
if
verbose
&&
len
(
response
.
Statuses
)
>
0
{
verboseFormat
(
response
.
Statuses
,
args
.
Flag
.
Value
(
"--format"
))
}
else
{
if
state
!=
""
{
ui
.
Println
(
state
)
...
...
@@ -121,7 +135,7 @@ func ciStatus(cmd *Command, args *Args) {
}
}
func
verboseFormat
(
statuses
[]
github
.
CIStatus
)
{
func
verboseFormat
(
statuses
[]
github
.
CIStatus
,
formatString
string
)
{
colorize
:=
ui
.
IsTerminal
(
os
.
Stdout
)
contextWidth
:=
0
...
...
@@ -153,15 +167,26 @@ func verboseFormat(statuses []github.CIStatus) {
color
=
33
}
placeholders
:=
map
[
string
]
string
{
"S"
:
status
.
State
,
"sC"
:
""
,
"t"
:
status
.
Context
,
"U"
:
status
.
TargetUrl
,
}
if
colorize
{
stateMarker
=
fmt
.
Sprintf
(
"
\0
33[%dm%s
\0
33[0m"
,
color
,
stateMarke
r
)
placeholders
[
"sC"
]
=
fmt
.
Sprintf
(
"
\0
33[%dm"
,
colo
r
)
}
if
status
.
TargetUrl
==
""
{
ui
.
Printf
(
"%s
\t
%s
\n
"
,
stateMarker
,
status
.
Context
)
}
else
{
ui
.
Printf
(
"%s
\t
%-*s
\t
%s
\n
"
,
stateMarker
,
contextWidth
,
status
.
Context
,
status
.
TargetUrl
)
format
:=
formatString
if
format
==
""
{
if
status
.
TargetUrl
==
""
{
format
=
fmt
.
Sprintf
(
"%%sC%s%%Creset
\t
%%t
\n
"
,
stateMarker
)
}
else
{
format
=
fmt
.
Sprintf
(
"%%sC%s%%Creset
\t
%%<(%d)%%t
\t
%%U
\n
"
,
stateMarker
,
contextWidth
)
}
}
ui
.
Print
(
ui
.
Expand
(
format
,
placeholders
,
colorize
))
}
}
...
...
features/ci_status.feature
浏览文件 @
df7b30a0
...
...
@@ -55,6 +55,40 @@ Feature: hub ci-status
"""
And
the exit status should be 1
Scenario
:
Multiple statuses with format string
Given
there is a commit named
"the_sha"
Given the remote commit states of "michiels/pencilbox" "the_sha" are
:
"""
{ :state => "error",
:statuses => [
{ :state => "success",
:context => "continuous-integration/travis-ci/push",
:target_url => "https://travis-ci.org/michiels/pencilbox/builds/1234567" },
{ :state => "success",
:context => "continuous-integration/travis-ci/ants",
:target_url => "https://travis-ci.org/michiels/pencilbox/builds/1234568" },
{ :state => "pending",
:context => "continuous-integration/travis-ci/merge",
:target_url => nil },
{ :state => "error",
:context => "whatevs!" },
{ :state => "failure",
:context => "GitHub CLA",
:target_url => "https://cla.github.com/michiels/pencilbox/accept/mislav" },
]
}
"""
When I run `hub ci-status the_sha --format '%S
:
%t
(%U)%n'`
Then the output should contain exactly
:
"""
failure: GitHub CLA (https://cla.github.com/michiels/pencilbox/accept/mislav)
error: whatevs! ()
pending: continuous-integration/travis-ci/merge ()
success: continuous-integration/travis-ci/ants (https://travis-ci.org/michiels/pencilbox/builds/1234568)
success: continuous-integration/travis-ci/push (https://travis-ci.org/michiels/pencilbox/builds/1234567)\n
"""
And
the exit status should be 1
Scenario
:
Exit status 1 for 'error' and 'failure'
Given
the remote commit state of
"michiels/pencilbox"
"HEAD"
is
"error"
When
I run `hub ci-status`
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录