Skip to content

Commit

Permalink
Merge branch 'integrate_with_octokit'
Browse files Browse the repository at this point in the history
  • Loading branch information
owenthereal committed Nov 8, 2013
2 parents dfad420 + 9fc9fe3 commit 92cb217
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 106 deletions.
4 changes: 2 additions & 2 deletions commands/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package commands
import (
"fmt"
"github.com/jingweno/gh/utils"
"github.com/jingweno/octokat"
"github.com/octokit/go-octokit/octokit"
)

var cmdCheckout = &Command{
Expand Down Expand Up @@ -46,7 +46,7 @@ func transformCheckoutArgs(args *Args) error {
return nil
}

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

args.RemoveParam(0) // Remove the pull request URL
Expand Down
2 changes: 1 addition & 1 deletion commands/ci_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func ciStatus(cmd *Command, args *Args) {

func fetchCiStatus(ref string) (state, targetURL, desc string, exitCode int, err error) {
gh := github.New()
status, err := gh.CiStatus(ref)
status, err := gh.CIStatus(ref)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions commands/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package commands
import (
"fmt"
"github.com/jingweno/gh/utils"
"github.com/jingweno/octokat"
"github.com/octokit/go-octokit/octokit"
)

var cmdMerge = &Command{
Expand Down Expand Up @@ -45,7 +45,7 @@ func transformMergeArgs(args *Args) error {
return nil
}

func fetchAndMerge(args *Args, pullRequest *octokat.PullRequest) error {
func fetchAndMerge(args *Args, pullRequest *octokit.PullRequest) error {
user, branch := parseUserBranchFromPR(pullRequest)
url, err := convertToGitURL(pullRequest.HTMLURL, user, pullRequest.Head.Repo.Private)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions commands/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package commands

import (
"github.com/bmizerany/assert"
"github.com/jingweno/octokat"
"github.com/octokit/go-octokit/octokit"
"testing"
)

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

userLogin := "jingweno"
user := octokat.User{Login: userLogin}
user := octokit.User{Login: userLogin}

repoPrivate := true
repo := octokat.Repository{Private: repoPrivate}
repo := octokit.Repository{Private: repoPrivate}

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

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

err := fetchAndMerge(args, &pullRequest)
assert.Equal(t, nil, err)
Expand Down
20 changes: 11 additions & 9 deletions commands/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ 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)
}

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 == "" {
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions commands/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/jingweno/gh/git"
"github.com/jingweno/gh/github"
"github.com/jingweno/gh/utils"
"github.com/jingweno/octokat"
"github.com/octokit/go-octokit/octokit"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -41,7 +41,7 @@ func parsePullRequestId(rawurl string) (id string) {
return
}

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

func parseUserBranchFromPR(pullRequest *octokat.PullRequest) (user string, branch string) {
func parseUserBranchFromPR(pullRequest *octokit.PullRequest) (user string, branch string) {
userBranch := strings.SplitN(pullRequest.Head.Label, ":", 2)
user = userBranch[0]
if len(userBranch) > 1 {
Expand Down
Loading

0 comments on commit 92cb217

Please sign in to comment.