зеркало из https://github.com/mislav/hub.git
Коммит
9da3d1773a
|
@ -97,6 +97,9 @@ With no arguments, show a list of open issues.
|
|||
-F, --file <FILE>
|
||||
Read the issue title and description from <FILE>.
|
||||
|
||||
-e, --edit
|
||||
Further edit the contents of <FILE> in a text editor before submitting.
|
||||
|
||||
-o, --browse
|
||||
Open the new issue in a web browser.
|
||||
|
||||
|
@ -121,6 +124,7 @@ With no arguments, show a list of open issues.
|
|||
flagIssueMessage,
|
||||
flagIssueFile string
|
||||
|
||||
flagIssueEdit,
|
||||
flagIssueBrowse bool
|
||||
|
||||
flagIssueMilestone uint64
|
||||
|
@ -136,6 +140,7 @@ func init() {
|
|||
cmdCreateIssue.Flag.VarP(&flagIssueLabels, "label", "l", "LABEL")
|
||||
cmdCreateIssue.Flag.VarP(&flagIssueAssignees, "assign", "a", "ASSIGNEE")
|
||||
cmdCreateIssue.Flag.BoolVarP(&flagIssueBrowse, "browse", "o", false, "BROWSE")
|
||||
cmdCreateIssue.Flag.BoolVarP(&flagIssueEdit, "edit", "e", false, "EDIT")
|
||||
|
||||
cmdIssue.Flag.StringVarP(&flagIssueAssignee, "assignee", "a", "", "ASSIGNEE")
|
||||
cmdIssue.Flag.StringVarP(&flagIssueState, "state", "s", "", "STATE")
|
||||
|
@ -296,7 +301,7 @@ func createIssue(cmd *Command, args *Args) {
|
|||
if cmd.FlagPassed("message") {
|
||||
title, body = readMsg(flagIssueMessage)
|
||||
} else if cmd.FlagPassed("file") {
|
||||
title, body, err = readMsgFromFile(flagIssueFile)
|
||||
title, body, editor, err = readMsgFromFile(flagIssueFile, flagIssueEdit, "ISSUE", "issue")
|
||||
utils.Check(err)
|
||||
} else {
|
||||
cs := git.CommentChar()
|
||||
|
|
|
@ -16,7 +16,7 @@ var cmdPullRequest = &Command{
|
|||
Usage: `
|
||||
pull-request [-fo] [-b <BASE>] [-h <HEAD>] [-a <USERS>] [-M <MILESTONE>] [-l <LABELS>]
|
||||
pull-request -m <MESSAGE>
|
||||
pull-request -F <FILE>
|
||||
pull-request -F <FILE> [--edit]
|
||||
pull-request -i <ISSUE>
|
||||
`,
|
||||
Long: `Create a GitHub pull request.
|
||||
|
@ -32,6 +32,9 @@ pull-request -i <ISSUE>
|
|||
-F, --file <FILE>
|
||||
Read the pull request title and description from <FILE>.
|
||||
|
||||
-e, --edit
|
||||
Further edit the contents of <FILE> in a text editor before submitting.
|
||||
|
||||
-i, --issue <ISSUE>, <ISSUE-URL>
|
||||
(Deprecated) Convert <ISSUE> to a pull request.
|
||||
|
||||
|
@ -68,6 +71,7 @@ var (
|
|||
flagPullRequestFile string
|
||||
|
||||
flagPullRequestBrowse,
|
||||
flagPullRequestEdit,
|
||||
flagPullRequestForce bool
|
||||
|
||||
flagPullRequestMilestone uint64
|
||||
|
@ -82,6 +86,7 @@ func init() {
|
|||
cmdPullRequest.Flag.StringVarP(&flagPullRequestIssue, "issue", "i", "", "ISSUE")
|
||||
cmdPullRequest.Flag.BoolVarP(&flagPullRequestBrowse, "browse", "o", false, "BROWSE")
|
||||
cmdPullRequest.Flag.StringVarP(&flagPullRequestMessage, "message", "m", "", "MESSAGE")
|
||||
cmdPullRequest.Flag.BoolVarP(&flagPullRequestEdit, "edit", "e", false, "EDIT")
|
||||
cmdPullRequest.Flag.BoolVarP(&flagPullRequestForce, "force", "f", false, "FORCE")
|
||||
cmdPullRequest.Flag.StringVarP(&flagPullRequestFile, "file", "F", "", "FILE")
|
||||
cmdPullRequest.Flag.VarP(&flagPullRequestAssignees, "assign", "a", "USERS")
|
||||
|
@ -157,9 +162,6 @@ func pullRequest(cmd *Command, args *Args) {
|
|||
}
|
||||
}
|
||||
|
||||
title, body, err := getTitleAndBodyFromFlags(flagPullRequestMessage, flagPullRequestFile)
|
||||
utils.Check(err)
|
||||
|
||||
if headRepo, err := client.Repository(headProject); err == nil {
|
||||
headProject.Owner = headRepo.Owner.Login
|
||||
headProject.Name = headRepo.Name
|
||||
|
@ -178,7 +180,14 @@ func pullRequest(cmd *Command, args *Args) {
|
|||
}
|
||||
|
||||
var editor *github.Editor
|
||||
if title == "" && flagPullRequestIssue == "" {
|
||||
var title, body string
|
||||
|
||||
if cmd.FlagPassed("message") {
|
||||
title, body = readMsg(flagPullRequestMessage)
|
||||
} else if cmd.FlagPassed("file") {
|
||||
title, body, editor, err = readMsgFromFile(flagPullRequestFile, flagPullRequestEdit, "PULLREQ", "pull request")
|
||||
utils.Check(err)
|
||||
} else if flagPullRequestIssue == "" {
|
||||
baseTracking := base
|
||||
headTracking := head
|
||||
|
||||
|
|
|
@ -69,6 +69,9 @@ With '--include-drafts', include draft releases in the listing.
|
|||
-F, --file <FILE>
|
||||
Read the release title and description from <FILE>.
|
||||
|
||||
-e, --edit
|
||||
Further edit the contents of <FILE> in a text editor before submitting.
|
||||
|
||||
-c, --commitish <TARGET>
|
||||
A SHA, tag, or branch name to attach the release to (default: current branch).
|
||||
|
||||
|
@ -104,6 +107,7 @@ hub(1), git-tag(1)
|
|||
flagReleaseIncludeDrafts,
|
||||
flagReleaseShowDownloads,
|
||||
flagReleaseDraft,
|
||||
flagReleaseEdit,
|
||||
flagReleasePrerelease bool
|
||||
|
||||
flagReleaseMessage,
|
||||
|
@ -118,6 +122,7 @@ func init() {
|
|||
|
||||
cmdShowRelease.Flag.BoolVarP(&flagReleaseShowDownloads, "show-downloads", "d", false, "DRAFTS")
|
||||
|
||||
cmdCreateRelease.Flag.BoolVarP(&flagReleaseEdit, "edit", "e", false, "EDIT")
|
||||
cmdCreateRelease.Flag.BoolVarP(&flagReleaseDraft, "draft", "d", false, "DRAFT")
|
||||
cmdCreateRelease.Flag.BoolVarP(&flagReleasePrerelease, "prerelease", "p", false, "PRERELEASE")
|
||||
cmdCreateRelease.Flag.VarP(&flagReleaseAssets, "attach", "a", "ATTACH_ASSETS")
|
||||
|
@ -125,6 +130,7 @@ func init() {
|
|||
cmdCreateRelease.Flag.StringVarP(&flagReleaseFile, "file", "F", "", "FILE")
|
||||
cmdCreateRelease.Flag.StringVarP(&flagReleaseCommitish, "commitish", "c", "", "COMMITISH")
|
||||
|
||||
cmdEditRelease.Flag.BoolVarP(&flagReleaseEdit, "edit", "e", false, "EDIT")
|
||||
cmdEditRelease.Flag.BoolVarP(&flagReleaseDraft, "draft", "d", false, "DRAFT")
|
||||
cmdEditRelease.Flag.BoolVarP(&flagReleasePrerelease, "prerelease", "p", false, "PRERELEASE")
|
||||
cmdEditRelease.Flag.VarP(&flagReleaseAssets, "attach", "a", "ATTACH_ASSETS")
|
||||
|
@ -280,7 +286,7 @@ func createRelease(cmd *Command, args *Args) {
|
|||
if cmd.FlagPassed("message") {
|
||||
title, body = readMsg(flagReleaseMessage)
|
||||
} else if cmd.FlagPassed("file") {
|
||||
title, body, err = readMsgFromFile(flagReleaseFile)
|
||||
title, body, editor, err = readMsgFromFile(flagReleaseFile, flagReleaseEdit, "RELEASE", "release")
|
||||
utils.Check(err)
|
||||
} else {
|
||||
cs := git.CommentChar()
|
||||
|
@ -367,7 +373,7 @@ func editRelease(cmd *Command, args *Args) {
|
|||
if cmd.FlagPassed("message") {
|
||||
title, body = readMsg(flagReleaseMessage)
|
||||
} else if cmd.FlagPassed("file") {
|
||||
title, body, err = readMsgFromFile(flagReleaseFile)
|
||||
title, body, editor, err = readMsgFromFile(flagReleaseFile, flagReleaseEdit, "RELEASE", "release")
|
||||
utils.Check(err)
|
||||
|
||||
if title == "" {
|
||||
|
|
|
@ -76,30 +76,39 @@ func isEmptyDir(path string) bool {
|
|||
return match == nil
|
||||
}
|
||||
|
||||
func getTitleAndBodyFromFlags(messageFlag, fileFlag string) (title, body string, err error) {
|
||||
if messageFlag != "" {
|
||||
title, body = readMsg(messageFlag)
|
||||
} else if fileFlag != "" {
|
||||
title, body, err = readMsgFromFile(fileFlag)
|
||||
func readMsgFromFile(filename string, edit bool, editorPrefix, editorTopic string) (title, body string, editor *github.Editor, err error) {
|
||||
message, err := msgFromFile(filename)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
if edit {
|
||||
editor, err = github.NewEditor(editorPrefix, editorTopic, message)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
title, body, err = editor.EditTitleAndBody()
|
||||
return
|
||||
} else {
|
||||
title, body = readMsg(message)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func readMsgFromFile(filename string) (title, body string, err error) {
|
||||
func msgFromFile(filename string) (string, error) {
|
||||
var content []byte
|
||||
var err error
|
||||
|
||||
if filename == "-" {
|
||||
content, err = ioutil.ReadAll(os.Stdin)
|
||||
} else {
|
||||
content, err = ioutil.ReadFile(filename)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
return "", err
|
||||
}
|
||||
|
||||
text := strings.Replace(string(content), "\r\n", "\n", -1)
|
||||
title, body = readMsg(text)
|
||||
return
|
||||
return strings.Replace(string(content), "\r\n", "\n", -1), nil
|
||||
}
|
||||
|
||||
func readMsg(message string) (title, body string) {
|
||||
|
|
|
@ -325,6 +325,29 @@ BODY
|
|||
Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
|
||||
And the file ".git/PULLREQ_EDITMSG" should not exist
|
||||
|
||||
Scenario: Edit title and body from file
|
||||
Given the GitHub API server:
|
||||
"""
|
||||
post('/repos/mislav/coral/pulls') {
|
||||
assert :title => 'Hello from editor',
|
||||
:body => "Title from file\n\nBody from file as well."
|
||||
status 201
|
||||
json :html_url => "https://github.com/mislav/coral/pull/12"
|
||||
}
|
||||
"""
|
||||
And a file named "pullreq-msg" with:
|
||||
"""
|
||||
Title from file
|
||||
|
||||
Body from file as well.
|
||||
"""
|
||||
And the text editor adds:
|
||||
"""
|
||||
Hello from editor
|
||||
"""
|
||||
When I successfully run `hub pull-request -F pullreq-msg --edit`
|
||||
Then the file ".git/PULLREQ_EDITMSG" should not exist
|
||||
|
||||
Scenario: Title and body from stdin
|
||||
Given the GitHub API server:
|
||||
"""
|
||||
|
|
Загрузка…
Ссылка в новой задаче