Skip to content

Commit 92cb217

Browse files
committed
Merge branch 'integrate_with_octokit'
2 parents dfad420 + 9fc9fe3 commit 92cb217

File tree

7 files changed

+157
-106
lines changed

7 files changed

+157
-106
lines changed

commands/checkout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package commands
33
import (
44
"fmt"
55
"github.com/jingweno/gh/utils"
6-
"github.com/jingweno/octokat"
6+
"github.com/octokit/go-octokit/octokit"
77
)
88

99
var cmdCheckout = &Command{
@@ -46,7 +46,7 @@ func transformCheckoutArgs(args *Args) error {
4646
return nil
4747
}
4848

49-
func buildArgsFromPullRequest(args *Args, pullRequest *octokat.PullRequest) error {
49+
func buildArgsFromPullRequest(args *Args, pullRequest *octokit.PullRequest) error {
5050
user, branch := parseUserBranchFromPR(pullRequest)
5151

5252
args.RemoveParam(0) // Remove the pull request URL

commands/ci_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func ciStatus(cmd *Command, args *Args) {
6161

6262
func fetchCiStatus(ref string) (state, targetURL, desc string, exitCode int, err error) {
6363
gh := github.New()
64-
status, err := gh.CiStatus(ref)
64+
status, err := gh.CIStatus(ref)
6565
if err != nil {
6666
return
6767
}

commands/merge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package commands
33
import (
44
"fmt"
55
"github.com/jingweno/gh/utils"
6-
"github.com/jingweno/octokat"
6+
"github.com/octokit/go-octokit/octokit"
77
)
88

99
var cmdMerge = &Command{
@@ -45,7 +45,7 @@ func transformMergeArgs(args *Args) error {
4545
return nil
4646
}
4747

48-
func fetchAndMerge(args *Args, pullRequest *octokat.PullRequest) error {
48+
func fetchAndMerge(args *Args, pullRequest *octokit.PullRequest) error {
4949
user, branch := parseUserBranchFromPR(pullRequest)
5050
url, err := convertToGitURL(pullRequest.HTMLURL, user, pullRequest.Head.Repo.Private)
5151
if err != nil {

commands/merge_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package commands
22

33
import (
44
"github.com/bmizerany/assert"
5-
"github.com/jingweno/octokat"
5+
"github.com/octokit/go-octokit/octokit"
66
"testing"
77
)
88

@@ -14,15 +14,15 @@ func TestFetchAndMerge(t *testing.T) {
1414
args := NewArgs([]string{"merge", url})
1515

1616
userLogin := "jingweno"
17-
user := octokat.User{Login: userLogin}
17+
user := octokit.User{Login: userLogin}
1818

1919
repoPrivate := true
20-
repo := octokat.Repository{Private: repoPrivate}
20+
repo := octokit.Repository{Private: repoPrivate}
2121

2222
headRef := "new-feature"
23-
head := octokat.Commit{Ref: headRef, Repo: repo, Label: "jingweno:new-feature"}
23+
head := octokit.Commit{Ref: headRef, Repo: repo, Label: "jingweno:new-feature"}
2424

25-
pullRequest := octokat.PullRequest{Number: number, Title: title, HTMLURL: url, User: user, Head: head}
25+
pullRequest := octokit.PullRequest{Number: number, Title: title, HTMLURL: url, User: user, Head: head}
2626

2727
err := fetchAndMerge(args, &pullRequest)
2828
assert.Equal(t, nil, err)

commands/pull_request.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ func init() {
5555
[ attached pull request to issue #123 ]
5656
*/
5757
func pullRequest(cmd *Command, args *Args) {
58-
var (
59-
title, body string
60-
err error
61-
)
58+
var title, body string
6259
if args.ParamsSize() == 1 {
6360
title = args.RemoveParam(0)
6461
}
6562

6663
gh := github.New()
6764
repo := gh.Project.LocalRepoWith(flagPullRequestBase, flagPullRequestHead)
6865
if title == "" && flagPullRequestIssue == "" {
69-
title, body, err = writePullRequestTitleAndBody(repo)
66+
t, b, err := writePullRequestTitleAndBody(repo)
67+
utils.Check(err)
68+
title = t
69+
body = b
7070
}
7171

7272
if title == "" && flagPullRequestIssue == "" {
@@ -79,14 +79,16 @@ func pullRequest(cmd *Command, args *Args) {
7979
pullRequestURL = "PULL_REQUEST_URL"
8080
} else {
8181
if title != "" {
82-
pullRequestURL, err = gh.CreatePullRequest(repo.Base, repo.Head, title, body)
82+
pr, err := gh.CreatePullRequest(repo.Base, repo.Head, title, body)
83+
utils.Check(err)
84+
pullRequestURL = pr.HTMLURL
8385
}
84-
utils.Check(err)
8586

8687
if flagPullRequestIssue != "" {
87-
pullRequestURL, err = gh.CreatePullRequestForIssue(repo.Base, repo.Head, flagPullRequestIssue)
88+
pr, err := gh.CreatePullRequestForIssue(repo.Base, repo.Head, flagPullRequestIssue)
89+
utils.Check(err)
90+
pullRequestURL = pr.HTMLURL
8891
}
89-
utils.Check(err)
9092
}
9193

9294
args.Replace("echo", "", pullRequestURL)

commands/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/jingweno/gh/git"
66
"github.com/jingweno/gh/github"
77
"github.com/jingweno/gh/utils"
8-
"github.com/jingweno/octokat"
8+
"github.com/octokit/go-octokit/octokit"
99
"os"
1010
"regexp"
1111
"strings"
@@ -41,7 +41,7 @@ func parsePullRequestId(rawurl string) (id string) {
4141
return
4242
}
4343

44-
func fetchPullRequest(id string) (*octokat.PullRequest, error) {
44+
func fetchPullRequest(id string) (*octokit.PullRequest, error) {
4545
gh := github.New()
4646
pullRequest, err := gh.PullRequest(id)
4747
if err != nil {
@@ -65,7 +65,7 @@ func convertToGitURL(pullRequestURL, user string, isSSH bool) (string, error) {
6565
return url.GitURL("", user, isSSH), nil
6666
}
6767

68-
func parseUserBranchFromPR(pullRequest *octokat.PullRequest) (user string, branch string) {
68+
func parseUserBranchFromPR(pullRequest *octokit.PullRequest) (user string, branch string) {
6969
userBranch := strings.SplitN(pullRequest.Head.Label, ":", 2)
7070
user = userBranch[0]
7171
if len(userBranch) > 1 {

0 commit comments

Comments
 (0)