提交 d5761b71 编写于 作者: M Mislav Marohnić

Add `--format=<FORMAT>` functionality to `issue show`, `release show`

上级 5285804c
......@@ -18,9 +18,9 @@ var (
Run: listIssues,
Usage: `
issue [-a <ASSIGNEE>] [-c <CREATOR>] [-@ <USER>] [-s <STATE>] [-f <FORMAT>] [-M <MILESTONE>] [-l <LABELS>] [-d <DATE>] [-o <SORT_KEY> [-^]] [-L <LIMIT>]
issue show [-f <FORMAT>] <NUMBER>
issue create [-oc] [-m <MESSAGE>|-F <FILE>] [--edit] [-a <USERS>] [-M <MILESTONE>] [-l <LABELS>]
issue labels [--color]
issue show <NUMBER>
`,
Long: `Manage GitHub issues for the current project.
......@@ -174,6 +174,7 @@ With no arguments, show a list of open issues.
flagIssueAssignee,
flagIssueState,
flagIssueFormat,
flagShowIssueFormat,
flagIssueMessage,
flagIssueMilestoneFilter,
flagIssueCreator,
......@@ -200,6 +201,8 @@ With no arguments, show a list of open issues.
)
func init() {
cmdShowIssue.Flag.StringVarP(&flagShowIssueFormat, "format", "f", "", "FORMAT")
cmdCreateIssue.Flag.StringVarP(&flagIssueMessage, "message", "m", "", "MESSAGE")
cmdCreateIssue.Flag.StringVarP(&flagIssueFile, "file", "F", "", "FILE")
cmdCreateIssue.Flag.Uint64VarP(&flagIssueMilestone, "milestone", "M", 0, "MILESTONE")
......@@ -401,6 +404,14 @@ func showIssue(cmd *Command, args *Args) {
issue, err = gh.FetchIssue(project, issueNumber)
utils.Check(err)
args.NoForward()
colorize := ui.IsTerminal(os.Stdout)
if flagShowIssueFormat != "" {
ui.Printf(formatIssue(*issue, flagShowIssueFormat, colorize))
return
}
var closed = ""
if issue.State != "open" {
closed = "[CLOSED] "
......@@ -428,7 +439,6 @@ func showIssue(cmd *Command, args *Args) {
}
}
args.NoForward()
return
}
......
......@@ -17,8 +17,8 @@ var (
cmdRelease = &Command{
Run: listReleases,
Usage: `
release [--include-drafts] [--exclude-prereleases] [-L <LIMIT>]
release show <TAG>
release [--include-drafts] [--exclude-prereleases] [-L <LIMIT>] [-f <FORMAT>]
release show [-f <FORMAT>] <TAG>
release create [-dpoc] [-a <FILE>] [-m <MESSAGE>|-F <FILE>] [-t <TARGET>] <TAG>
release edit [<options>] <TAG>
release download <TAG>
......@@ -178,6 +178,7 @@ hub(1), git-tag(1)
flagReleaseMessage,
flagReleaseFile,
flagReleaseFormat,
flagShowReleaseFormat,
flagReleaseCommitish string
flagReleaseAssets stringSliceValue
......@@ -192,6 +193,7 @@ func init() {
cmdRelease.Flag.StringVarP(&flagReleaseFormat, "format", "f", "%T%n", "FORMAT")
cmdShowRelease.Flag.BoolVarP(&flagReleaseShowDownloads, "show-downloads", "d", false, "DRAFTS")
cmdShowRelease.Flag.StringVarP(&flagShowReleaseFormat, "format", "f", "", "FORMAT")
cmdCreateRelease.Flag.BoolVarP(&flagReleaseEdit, "edit", "e", false, "EDIT")
cmdCreateRelease.Flag.BoolVarP(&flagReleaseDraft, "draft", "d", false, "DRAFT")
......@@ -315,6 +317,8 @@ func showRelease(cmd *Command, args *Args) {
gh := github.NewClient(project.Host)
args.NoForward()
if args.Noop {
ui.Printf("Would display information for `%s' release\n", tagName)
} else {
......@@ -323,6 +327,12 @@ func showRelease(cmd *Command, args *Args) {
body := strings.TrimSpace(release.Body)
colorize := ui.IsTerminal(os.Stdout)
if flagShowReleaseFormat != "" {
ui.Printf(formatRelease(*release, flagShowReleaseFormat, colorize))
return
}
ui.Println(release.Name)
if body != "" {
ui.Printf("\n%s\n", body)
......@@ -338,8 +348,6 @@ func showRelease(cmd *Command, args *Args) {
}
}
}
args.NoForward()
}
func downloadRelease(cmd *Command, args *Args) {
......
......@@ -579,6 +579,41 @@ Feature: hub issue
I did the thing\n
"""
Scenario: Format single issue
Given the GitHub API server:
"""
get('/repos/github/hub/issues/102') {
json \
:number => 102,
:state => "open",
:body => "I want this feature",
:title => "Feature request for hub issue show",
:created_at => "2017-04-14T16:00:49Z",
:user => { :login => "royels" },
:assignees => [{:login => "royels"}],
:comments => 1
}
get('/repos/github/hub/issues/102/comments') {
json [
{ :body => "I am from the future",
:created_at => "2011-04-14T16:00:49Z",
:user => { :login => "octocat" }
},
{ :body => "I did the thing",
:created_at => "2013-10-30T22:20:00Z",
:user => { :login => "hubot" }
},
]
}
"""
When I successfully run `hub issue show 102 --format='%I %t%n%n%b%n'`
Then the output should contain exactly:
"""
102 Feature request for hub issue show
I want this feature\n
"""
Scenario: Did not supply an issue number
When I run `hub issue show`
Then the exit status should be 1
......
......@@ -325,6 +325,43 @@ MARKDOWN
https://github.com/mislav/will_paginate/archive/v1.2.0.tar.gz\n
"""
Scenario: Format specific release
Given the GitHub API server:
"""
get('/repos/mislav/will_paginate/releases') {
json [
{ tag_name: 'v1.2.0',
name: 'will_paginate 1.2.0',
draft: true,
prerelease: false,
tarball_url: "https://github.com/mislav/will_paginate/archive/v1.2.0.tar.gz",
zipball_url: "https://github.com/mislav/will_paginate/archive/v1.2.0.zip",
assets: [
{ browser_download_url: "https://github.com/mislav/will_paginate/releases/download/v1.2.0/example.zip",
},
],
body: <<MARKDOWN
### Hello to my release
Here is what's broken:
- everything
MARKDOWN
},
]
}
"""
When I successfully run `hub release show v1.2.0 --format='%t (%T)%n%as%n%n%b%n'`
Then the output should contain exactly:
"""
will_paginate 1.2.0 (v1.2.0)
https://github.com/mislav/will_paginate/releases/download/v1.2.0/example.zip
### Hello to my release
Here is what's broken:
- everything\n\n
"""
Scenario: Show release no tag
When I run `hub release show`
Then the exit status should be 1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册