Skip to content

Commit

Permalink
(refactor) BranchPushed pull out FindProject call and put more inform…
Browse files Browse the repository at this point in the history
…ation into calling error message
  • Loading branch information
zaquestion committed Jan 6, 2018
1 parent fbfde98 commit fd87602
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions cmd/mergeRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
// mrCmd represents the mr command
var mergeRequestCmd = &cobra.Command{
Use: "merge-request [remote]",
Short: "Open a merge request on GitLab",
Long: `Currently only supports MRs into master`,
Args: cobra.ExactArgs(0),
Short: mrCreateCmd.Short,
Long: mrCreateCmd.Long,
Args: mrCreateCmd.Args,
Run: runMRCreate,
}

Expand Down
8 changes: 6 additions & 2 deletions cmd/mrCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ func runMRCreate(cmd *cobra.Command, args []string) {
log.Fatal(err)
}

if !lab.BranchPushed(sourceProjectName, branch) {
log.Fatal("aborting MR, branch not present on remote: ", sourceRemote)
p, err := lab.FindProject(sourceProjectName)
if err != nil {
log.Fatal(err)
}
if !lab.BranchPushed(p.ID, branch) {
log.Fatalf("aborting MR, branch %s not present on remote %s. did you forget to push?", branch, sourceRemote)
}

targetRemote := forkedFromRemote
Expand Down
9 changes: 2 additions & 7 deletions internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,8 @@ func IssueClose(pid interface{}, id int) error {
}

// BranchPushed checks if a branch exists on a GitLab project
func BranchPushed(project, branch string) bool {
p, err := FindProject(project)
if err != nil {
return false
}

b, _, err := lab.Branches.GetBranch(p.ID, branch)
func BranchPushed(pid interface{}, branch string) bool {
b, _, err := lab.Branches.GetBranch(pid, branch)
if err != nil {
return false
}
Expand Down

0 comments on commit fd87602

Please sign in to comment.