提交 d2de3094 编写于 作者: M Michael Kaiser

Add limit flag for issue and release commands

上级 cbcc349e
...@@ -17,7 +17,7 @@ var ( ...@@ -17,7 +17,7 @@ var (
cmdIssue = &Command{ cmdIssue = &Command{
Run: listIssues, Run: listIssues,
Usage: ` Usage: `
issue [-a <ASSIGNEE>] [-c <CREATOR>] [-@ <USER>] [-s <STATE>] [-f <FORMAT>] [-M <MILESTONE>] [-l <LABELS>] [-d <DATE>] [-o <SORT_KEY> [-^]] 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 create [-oc] [-m <MESSAGE>|-F <FILE>] [-a <USERS>] [-M <MILESTONE>] [-l <LABELS>]
`, `,
Long: `Manage GitHub issues for the current project. Long: `Manage GitHub issues for the current project.
...@@ -131,6 +131,9 @@ With no arguments, show a list of open issues. ...@@ -131,6 +131,9 @@ With no arguments, show a list of open issues.
-^ --sort-ascending -^ --sort-ascending
Sort by ascending dates instead of descending. Sort by ascending dates instead of descending.
-L, --limit <LIMIT>
Display only the first <LIMIT> issues.
--include-pulls --include-pulls
Include pull requests as well as issues. Include pull requests as well as issues.
`, `,
...@@ -165,6 +168,8 @@ With no arguments, show a list of open issues. ...@@ -165,6 +168,8 @@ With no arguments, show a list of open issues.
flagIssueAssignees, flagIssueAssignees,
flagIssueLabels listFlag flagIssueLabels listFlag
flagIssueLimit int
) )
func init() { func init() {
...@@ -188,6 +193,7 @@ func init() { ...@@ -188,6 +193,7 @@ func init() {
cmdIssue.Flag.StringVarP(&flagIssueSort, "sort", "o", "created", "SORT_KEY") cmdIssue.Flag.StringVarP(&flagIssueSort, "sort", "o", "created", "SORT_KEY")
cmdIssue.Flag.BoolVarP(&flagIssueSortAscending, "sort-ascending", "^", false, "SORT_KEY") cmdIssue.Flag.BoolVarP(&flagIssueSortAscending, "sort-ascending", "^", false, "SORT_KEY")
cmdIssue.Flag.BoolVarP(&flagIssueIncludePulls, "include-pulls", "", false, "INCLUDE_PULLS") cmdIssue.Flag.BoolVarP(&flagIssueIncludePulls, "include-pulls", "", false, "INCLUDE_PULLS")
cmdIssue.Flag.IntVarP(&flagIssueLimit, "limit", "L", -1, "LIMIT")
cmdIssue.Use(cmdCreateIssue) cmdIssue.Use(cmdCreateIssue)
CmdRunner.Use(cmdIssue) CmdRunner.Use(cmdIssue)
...@@ -244,12 +250,17 @@ func listIssues(cmd *Command, args *Args) { ...@@ -244,12 +250,17 @@ func listIssues(cmd *Command, args *Args) {
} }
colorize := ui.IsTerminal(os.Stdout) colorize := ui.IsTerminal(os.Stdout)
c := 0
for _, issue := range issues { for _, issue := range issues {
if !flagIssueIncludePulls && issue.PullRequest != nil { if !flagIssueIncludePulls && issue.PullRequest != nil {
continue continue
} }
ui.Printf(formatIssue(issue, flagIssueFormat, colorize)) ui.Printf(formatIssue(issue, flagIssueFormat, colorize))
c++
if c == flagIssueLimit {
break
}
} }
} }
......
...@@ -17,7 +17,7 @@ var ( ...@@ -17,7 +17,7 @@ var (
cmdRelease = &Command{ cmdRelease = &Command{
Run: listReleases, Run: listReleases,
Usage: ` Usage: `
release [--include-drafts] [--exclude-prereleases] release [--include-drafts] [--exclude-prereleases] [-L <LIMIT>]
release show <TAG> release show <TAG>
release create [-dpoc] [-a <FILE>] [-m <MESSAGE>|-F <FILE>] [-t <TARGET>] <TAG> release create [-dpoc] [-a <FILE>] [-m <MESSAGE>|-F <FILE>] [-t <TARGET>] <TAG>
release edit [<options>] <TAG> release edit [<options>] <TAG>
...@@ -56,6 +56,9 @@ With '--exclude-prereleases', exclude non-stable releases from the listing. ...@@ -56,6 +56,9 @@ With '--exclude-prereleases', exclude non-stable releases from the listing.
Delete the release and associated assets for the specified <TAG>. Delete the release and associated assets for the specified <TAG>.
## Options: ## Options:
-L, --limit
Display only the first <LIMIT> releases.
-d, --draft -d, --draft
Create a draft release. Create a draft release.
...@@ -135,11 +138,14 @@ hub(1), git-tag(1) ...@@ -135,11 +138,14 @@ hub(1), git-tag(1)
flagReleaseCommitish string flagReleaseCommitish string
flagReleaseAssets stringSliceValue flagReleaseAssets stringSliceValue
flagReleaseLimit int
) )
func init() { func init() {
cmdRelease.Flag.BoolVarP(&flagReleaseIncludeDrafts, "include-drafts", "d", false, "DRAFTS") cmdRelease.Flag.BoolVarP(&flagReleaseIncludeDrafts, "include-drafts", "d", false, "DRAFTS")
cmdRelease.Flag.BoolVarP(&flagReleaseExcludePrereleases, "exclude-prereleases", "p", false, "PRERELEASE") cmdRelease.Flag.BoolVarP(&flagReleaseExcludePrereleases, "exclude-prereleases", "p", false, "PRERELEASE")
cmdRelease.Flag.IntVarP(&flagReleaseLimit, "limit", "L", -1, "LIMIT")
cmdShowRelease.Flag.BoolVarP(&flagReleaseShowDownloads, "show-downloads", "d", false, "DRAFTS") cmdShowRelease.Flag.BoolVarP(&flagReleaseShowDownloads, "show-downloads", "d", false, "DRAFTS")
...@@ -184,10 +190,15 @@ func listReleases(cmd *Command, args *Args) { ...@@ -184,10 +190,15 @@ func listReleases(cmd *Command, args *Args) {
releases, err := gh.FetchReleases(project) releases, err := gh.FetchReleases(project)
utils.Check(err) utils.Check(err)
c := 0
for _, release := range releases { for _, release := range releases {
if (!release.Draft || flagReleaseIncludeDrafts) && if (!release.Draft || flagReleaseIncludeDrafts) &&
(!release.Prerelease || !flagReleaseExcludePrereleases) { (!release.Prerelease || !flagReleaseExcludePrereleases) {
ui.Println(release.TagName) ui.Println(release.TagName)
c++
if c == flagReleaseLimit {
break
}
} }
} }
} }
......
...@@ -38,6 +38,37 @@ Feature: hub issue ...@@ -38,6 +38,37 @@ Feature: hub issue
#13 Second issue\n #13 Second issue\n
""" """
Scenario: List limited number of issues
Given the GitHub API server:
"""
get('/repos/github/hub/issues') {
json [
{ :number => 102,
:title => "First issue",
:state => "open",
:user => { :login => "octocat" },
},
{ :number => 13,
:title => "Second issue",
:state => "open",
:user => { :login => "octocat" },
},
{ :number => 999,
:title => "Third issue",
:state => "open",
:user => { :login => "octocat" },
},
]
}
"""
When I successfully run `hub issue -L 2`
Then the output should contain exactly:
"""
#102 First issue
#13 Second issue\n
"""
Scenario: Fetch issues and pull requests Scenario: Fetch issues and pull requests
Given the GitHub API server: Given the GitHub API server:
""" """
......
...@@ -147,6 +147,36 @@ Feature: hub release ...@@ -147,6 +147,36 @@ Feature: hub release
v1.0.0\n v1.0.0\n
""" """
Scenario: List limited number of releases
Given the GitHub API server:
"""
get('/repos/mislav/will_paginate/releases') {
json [
{ tag_name: 'v1.2.0',
name: 'will_paginate 1.2.0',
draft: false,
prerelease: false,
},
{ tag_name: 'v1.2.0-pre',
name: 'will_paginate 1.2.0-pre',
draft: false,
prerelease: true,
},
{ tag_name: 'v1.0.2',
name: 'will_paginate 1.0.2',
draft: false,
prerelease: false,
},
]
}
"""
When I successfully run `hub release -L 2`
Then the output should contain exactly:
"""
v1.2.0
v1.2.0-pre\n
"""
Scenario: Repository not found when listing releases Scenario: Repository not found when listing releases
Given the GitHub API server: Given the GitHub API server:
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册