Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
f894442e
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 搜索 >>
提交
f894442e
编写于
1月 30, 2018
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'darrenwee-implement-label-list-color'
上级
3abe361e
cd443ec2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
113 addition
and
6 deletion
+113
-6
commands/issue.go
commands/issue.go
+64
-6
features/issue.feature
features/issue.feature
+21
-0
github/client.go
github/client.go
+28
-0
未找到文件。
commands/issue.go
浏览文件 @
f894442e
...
...
@@ -19,6 +19,7 @@ var (
Usage
:
`
issue [-a <ASSIGNEE>] [-c <CREATOR>] [-@ <USER>] [-s <STATE>] [-f <FORMAT>] [-M <MILESTONE>] [-l <LABELS>] [-d <DATE>] [-o <SORT_KEY> [-^]] [-L <LIMIT>]
issue create [-oc] [-m <MESSAGE>|-F <FILE>] [-a <USERS>] [-M <MILESTONE>] [-l <LABELS>]
issue labels [--color]
`
,
Long
:
`Manage GitHub issues for the current project.
...
...
@@ -29,6 +30,9 @@ With no arguments, show a list of open issues.
* _create_:
Open an issue in the current project.
* _labels_:
List the labels available in this repository.
## Options:
-a, --assignee <ASSIGNEE>
Display only issues assigned to <ASSIGNEE>.
...
...
@@ -136,6 +140,9 @@ With no arguments, show a list of open issues.
--include-pulls
Include pull requests as well as issues.
--color
Enable colored output for labels list.
`
,
}
...
...
@@ -146,6 +153,13 @@ With no arguments, show a list of open issues.
Long
:
"Open an issue in the current project."
,
}
cmdLabel
=
&
Command
{
Key
:
"labels"
,
Run
:
listLabels
,
Usage
:
"issue labels [--color]"
,
Long
:
"List the labels available in this repository."
,
}
flagIssueAssignee
,
flagIssueState
,
flagIssueFormat
,
...
...
@@ -170,6 +184,8 @@ With no arguments, show a list of open issues.
flagIssueLabels
listFlag
flagIssueLimit
int
flagLabelsColorize
bool
)
func
init
()
{
...
...
@@ -195,7 +211,10 @@ func init() {
cmdIssue
.
Flag
.
BoolVarP
(
&
flagIssueIncludePulls
,
"include-pulls"
,
""
,
false
,
"INCLUDE_PULLS"
)
cmdIssue
.
Flag
.
IntVarP
(
&
flagIssueLimit
,
"limit"
,
"L"
,
-
1
,
"LIMIT"
)
cmdLabel
.
Flag
.
BoolVarP
(
&
flagLabelsColorize
,
"color"
,
""
,
false
,
"COLORIZE"
)
cmdIssue
.
Use
(
cmdCreateIssue
)
cmdIssue
.
Use
(
cmdLabel
)
CmdRunner
.
Use
(
cmdIssue
)
}
...
...
@@ -282,12 +301,7 @@ func formatIssuePlaceholders(issue github.Issue, colorize bool) map[string]strin
utils
.
Check
(
err
)
}
textColor
:=
16
if
color
.
Brightness
()
<
0.65
{
textColor
=
15
}
labelStrings
=
append
(
labelStrings
,
fmt
.
Sprintf
(
"
\0
33[38;5;%d;48;2;%d;%d;%dm %s
\0
33[m"
,
textColor
,
color
.
Red
,
color
.
Green
,
color
.
Blue
,
label
.
Name
))
labelStrings
=
append
(
labelStrings
,
colorizeLabel
(
label
,
color
))
rawLabels
=
append
(
rawLabels
,
label
.
Name
)
}
...
...
@@ -431,3 +445,47 @@ text is the title and the rest is the description.`, project))
messageBuilder
.
Cleanup
()
}
func
listLabels
(
cmd
*
Command
,
args
*
Args
)
{
localRepo
,
err
:=
github
.
LocalRepo
()
utils
.
Check
(
err
)
project
,
err
:=
localRepo
.
MainProject
()
utils
.
Check
(
err
)
gh
:=
github
.
NewClient
(
project
.
Host
)
args
.
NoForward
()
if
args
.
Noop
{
ui
.
Printf
(
"Would request list of labels for %s
\n
"
,
project
)
return
}
labels
,
err
:=
gh
.
FetchLabels
(
project
)
utils
.
Check
(
err
)
for
_
,
label
:=
range
labels
{
ui
.
Printf
(
formatLabel
(
label
,
flagLabelsColorize
))
}
}
func
formatLabel
(
label
github
.
IssueLabel
,
colorize
bool
)
string
{
if
colorize
{
if
color
,
err
:=
utils
.
NewColor
(
label
.
Color
);
err
==
nil
{
return
fmt
.
Sprintf
(
"%s
\n
"
,
colorizeLabel
(
label
,
color
))
}
}
return
fmt
.
Sprintf
(
"%s
\n
"
,
label
.
Name
)
}
func
colorizeLabel
(
label
github
.
IssueLabel
,
color
*
utils
.
Color
)
string
{
return
fmt
.
Sprintf
(
"
\0
33[38;5;%d;48;2;%d;%d;%dm %s
\0
33[m"
,
getSuitableLabelTextColor
(
color
),
color
.
Red
,
color
.
Green
,
color
.
Blue
,
label
.
Name
)
}
func
getSuitableLabelTextColor
(
color
*
utils
.
Color
)
int
{
if
color
.
Brightness
()
<
0.65
{
return
15
// white text
}
return
16
// black text
}
features/issue.feature
浏览文件 @
f894442e
...
...
@@ -452,3 +452,24 @@ Feature: hub issue
"""
https://github.com/github/hub/issues/1337\n
"""
Scenario
:
Fetch issue labels
Given the GitHub API server
:
"""
get('/repos/github/hub/labels') {
json [
{ :name => "bug",
:color => "ff0000",
},
{ :name => "feature",
:color => "00ff00",
},
]
}
"""
When
I successfully run `hub issue labels`
Then the output should contain exactly
:
"""
bug
feature\n
"""
github/client.go
浏览文件 @
f894442e
...
...
@@ -607,6 +607,34 @@ func (client *Client) UpdateIssue(project *Project, issueNumber int, params map[
return
}
func
(
client
*
Client
)
FetchLabels
(
project
*
Project
)
(
labels
[]
IssueLabel
,
err
error
)
{
api
,
err
:=
client
.
simpleApi
()
if
err
!=
nil
{
return
}
path
:=
fmt
.
Sprintf
(
"repos/%s/%s/labels?per_page=100"
,
project
.
Owner
,
project
.
Name
)
labels
=
[]
IssueLabel
{}
var
res
*
simpleResponse
for
path
!=
""
{
res
,
err
=
api
.
Get
(
path
)
if
err
=
checkStatus
(
200
,
"fetching labels"
,
res
,
err
);
err
!=
nil
{
return
}
path
=
res
.
Link
(
"next"
)
labelsPage
:=
[]
IssueLabel
{}
if
err
=
res
.
Unmarshal
(
&
labelsPage
);
err
!=
nil
{
return
}
labels
=
append
(
labels
,
labelsPage
...
)
}
return
}
func
(
client
*
Client
)
CurrentUser
()
(
user
*
User
,
err
error
)
{
api
,
err
:=
client
.
simpleApi
()
if
err
!=
nil
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录