提交 08342b83 编写于 作者: J Jingwen Owen Ou

Return octokit.PullRequest

上级 0e0e61d7
......@@ -55,10 +55,7 @@ func init() {
[ attached pull request to issue #123 ]
*/
func pullRequest(cmd *Command, args *Args) {
var (
title, body string
err error
)
var title, body string
if args.ParamsSize() == 1 {
title = args.RemoveParam(0)
}
......@@ -66,7 +63,10 @@ func pullRequest(cmd *Command, args *Args) {
gh := github.New()
repo := gh.Project.LocalRepoWith(flagPullRequestBase, flagPullRequestHead)
if title == "" && flagPullRequestIssue == "" {
title, body, err = writePullRequestTitleAndBody(repo)
t, b, err := writePullRequestTitleAndBody(repo)
utils.Check(err)
title = t
body = b
}
if title == "" && flagPullRequestIssue == "" {
......@@ -79,14 +79,16 @@ func pullRequest(cmd *Command, args *Args) {
pullRequestURL = "PULL_REQUEST_URL"
} else {
if title != "" {
pullRequestURL, err = gh.CreatePullRequest(repo.Base, repo.Head, title, body)
pr, err := gh.CreatePullRequest(repo.Base, repo.Head, title, body)
utils.Check(err)
pullRequestURL = pr.HTMLURL
}
utils.Check(err)
if flagPullRequestIssue != "" {
pullRequestURL, err = gh.CreatePullRequestForIssue(repo.Base, repo.Head, flagPullRequestIssue)
pr, err := gh.CreatePullRequestForIssue(repo.Base, repo.Head, flagPullRequestIssue)
utils.Check(err)
pullRequestURL = pr.HTMLURL
}
utils.Check(err)
}
args.Replace("echo", "", pullRequestURL)
......
......@@ -31,7 +31,7 @@ func (gh *GitHub) PullRequest(id string) (pr *octokit.PullRequest, err error) {
return
}
func (gh *GitHub) CreatePullRequest(base, head, title, body string) (url string, err error) {
func (gh *GitHub) CreatePullRequest(base, head, title, body string) (pr *octokit.PullRequest, err error) {
client := gh.octokit()
prService, err := client.PullRequests(&octokit.PullRequestsURL, octokit.M{"owner": gh.Project.Owner, "repo": gh.Project.Name})
if err != nil {
......@@ -44,12 +44,10 @@ func (gh *GitHub) CreatePullRequest(base, head, title, body string) (url string,
err = result.Err
}
url = pr.HTMLURL
return
}
func (gh *GitHub) CreatePullRequestForIssue(base, head, issue string) (url string, err error) {
func (gh *GitHub) CreatePullRequestForIssue(base, head, issue string) (pr *octokit.PullRequest, err error) {
client := gh.octokit()
prService, err := client.PullRequests(&octokit.PullRequestsURL, octokit.M{"owner": gh.Project.Owner, "repo": gh.Project.Name})
if err != nil {
......@@ -62,8 +60,6 @@ func (gh *GitHub) CreatePullRequestForIssue(base, head, issue string) (url strin
err = result.Err
}
url = pr.HTMLURL
return
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册