提交 5cd5882c 编写于 作者: D Darren Wee

Merge branch 'elj/label-list' of https://github.com/eljobe/hub into implement-label-list-color

......@@ -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 label
`,
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.
* _label_:
List the labels available in this repository.
## Options:
-a, --assignee <ASSIGNEE>
Display only issues assigned to <ASSIGNEE>.
......@@ -196,6 +200,7 @@ func init() {
cmdIssue.Flag.IntVarP(&flagIssueLimit, "limit", "L", -1, "LIMIT")
cmdIssue.Use(cmdCreateIssue)
cmdIssue.Use(cmdLabel)
CmdRunner.Use(cmdIssue)
}
......
package commands
import (
"github.com/github/hub/github"
"github.com/github/hub/ui"
"github.com/github/hub/utils"
)
var (
cmdLabel = &Command{
Key: "label",
Run: listLabels,
Usage: "issue label",
Long: "List the labels available in this repository.",
}
)
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)
if args.Noop {
ui.Printf("Would request list of labels for %s\n", project)
} else {
labels, err := gh.FetchLabels(project)
utils.Check(err)
for _, label := range labels {
ui.Printf(formatLabel(label))
}
}
args.NoForward()
}
func formatLabel(label github.IssueLabel) string {
format := "%l%n"
placeholders := map[string]string{
"l": label.Name,
}
return ui.Expand(format, placeholders, false)
}
Feature: hub label
Background:
Given I am in "git://github.com/github/hub.git" git repo
And I am "testeroni" on github.com with OAuth token "OTOKEN"
Scenario: Fetch issues
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 label`
Then the output should contain exactly:
"""
bug
feature\n
"""
......@@ -561,6 +561,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.
先完成此消息的编辑!
想要评论请 注册