Add limit flag for issue and release commands

This commit is contained in:
Michael Kaiser 2017-10-03 12:28:17 +02:00
Родитель cbcc349e39
Коммит d2de3094a0
4 изменённых файлов: 85 добавлений и 2 удалений

Просмотреть файл

@ -17,7 +17,7 @@ var (
cmdIssue = &Command{
Run: listIssues,
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>]
`,
Long: `Manage GitHub issues for the current project.
@ -131,6 +131,9 @@ With no arguments, show a list of open issues.
-^ --sort-ascending
Sort by ascending dates instead of descending.
-L, --limit <LIMIT>
Display only the first <LIMIT> issues.
--include-pulls
Include pull requests as well as issues.
`,
@ -165,6 +168,8 @@ With no arguments, show a list of open issues.
flagIssueAssignees,
flagIssueLabels listFlag
flagIssueLimit int
)
func init() {
@ -188,6 +193,7 @@ func init() {
cmdIssue.Flag.StringVarP(&flagIssueSort, "sort", "o", "created", "SORT_KEY")
cmdIssue.Flag.BoolVarP(&flagIssueSortAscending, "sort-ascending", "^", false, "SORT_KEY")
cmdIssue.Flag.BoolVarP(&flagIssueIncludePulls, "include-pulls", "", false, "INCLUDE_PULLS")
cmdIssue.Flag.IntVarP(&flagIssueLimit, "limit", "L", -1, "LIMIT")
cmdIssue.Use(cmdCreateIssue)
CmdRunner.Use(cmdIssue)
@ -244,12 +250,17 @@ func listIssues(cmd *Command, args *Args) {
}
colorize := ui.IsTerminal(os.Stdout)
c := 0
for _, issue := range issues {
if !flagIssueIncludePulls && issue.PullRequest != nil {
continue
}
ui.Printf(formatIssue(issue, flagIssueFormat, colorize))
c++
if c == flagIssueLimit {
break
}
}
}

Просмотреть файл

@ -17,7 +17,7 @@ var (
cmdRelease = &Command{
Run: listReleases,
Usage: `
release [--include-drafts] [--exclude-prereleases]
release [--include-drafts] [--exclude-prereleases] [-L <LIMIT>]
release show <TAG>
release create [-dpoc] [-a <FILE>] [-m <MESSAGE>|-F <FILE>] [-t <TARGET>] <TAG>
release edit [<options>] <TAG>
@ -56,6 +56,9 @@ With '--exclude-prereleases', exclude non-stable releases from the listing.
Delete the release and associated assets for the specified <TAG>.
## Options:
-L, --limit
Display only the first <LIMIT> releases.
-d, --draft
Create a draft release.
@ -135,11 +138,14 @@ hub(1), git-tag(1)
flagReleaseCommitish string
flagReleaseAssets stringSliceValue
flagReleaseLimit int
)
func init() {
cmdRelease.Flag.BoolVarP(&flagReleaseIncludeDrafts, "include-drafts", "d", false, "DRAFTS")
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")
@ -184,10 +190,15 @@ func listReleases(cmd *Command, args *Args) {
releases, err := gh.FetchReleases(project)
utils.Check(err)
c := 0
for _, release := range releases {
if (!release.Draft || flagReleaseIncludeDrafts) &&
(!release.Prerelease || !flagReleaseExcludePrereleases) {
ui.Println(release.TagName)
c++
if c == flagReleaseLimit {
break
}
}
}
}

Просмотреть файл

@ -38,6 +38,37 @@ Feature: hub issue
#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
Given the GitHub API server:
"""

Просмотреть файл

@ -147,6 +147,36 @@ Feature: hub release
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
Given the GitHub API server:
"""