Skip to content

Commit

Permalink
Added flag to create source branch for merge request profclems#18
Browse files Browse the repository at this point in the history
  • Loading branch information
profclems committed Jul 29, 2020
1 parent 5de77de commit c78600f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ ifndef CGO_LDFLAGS
export CGO_LDFLAGS := $(LDFLAGS)
endif

GO_LDFLAGS := -X github.com/cli/cli/command.Version=$(GLAB_VERSION) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/cli/cli/command.BuildDate=$(BUILD_DATE) $(GO_LDFLAGS)
GO_LDFLAGS := -X glab.version=$(GLAB_VERSION) $(GO_LDFLAGS)
GO_LDFLAGS := -X glab.build=$(BUILD_DATE) $(GO_LDFLAGS)

build:
go build -trimpath -ldflags "$(GO_LDFLAGS)" -o ./bin/glab ./cmd/glab
Expand Down
18 changes: 15 additions & 3 deletions commands/mr.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ func CreateMergeRequest(cmdArgs map[string]string, _ map[int]string) {
mergeDescription = strings.Trim(cmdArgs["description"], " ")
}
if !CommandArgExists(cmdArgs, "source") {
fmt.Print(aurora.Cyan("Source Branch"))
fmt.Print(aurora.Yellow("-> "))
sourceBranch, _ = reader.ReadString('\n')
if CommandArgExists(cmdArgs, "create-branch") {
sourceBranch = ReplaceNonAlphaNumericChars(mergeTitle, "-")
} else {
fmt.Print(aurora.Cyan("Source Branch"))
fmt.Print(aurora.Yellow("-> "))
sourceBranch, _ = reader.ReadString('\n')
}
} else {
sourceBranch = strings.Trim(cmdArgs["source"], "[] ")
}
Expand Down Expand Up @@ -137,6 +141,14 @@ func CreateMergeRequest(cmdArgs map[string]string, _ map[int]string) {
}
}


if CommandArgExists(cmdArgs, "create-branch") {
minParams := url.Values{}
minParams.Add("branch",sourceBranch)
minParams.Add("ref",targetBranch)
MakeRequest(minParams.Encode(), "projects/" + GetEnv("GITLAB_PROJECT_ID") + "/repository/branches", "POST")
}

reqBody := params.Encode()
fmt.Println(aurora.Yellow("Creating Merge Request {" + mergeTitle + "}..."))
resp := MakeRequest(reqBody, "projects/"+GetEnv("GITLAB_PROJECT_ID")+"/merge_requests", "POST")
Expand Down
4 changes: 4 additions & 0 deletions commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ func getRepoContributors() {
MakeRequest(`{}`,"projects/20131402/issues/1","GET")
}

func NewBranch() {

}

func ExecRepo(cmdArgs map[string]string) {
}
11 changes: 11 additions & 0 deletions commands/univ.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/http"
_ "net/http"
"os"
"regexp"
"time"
)

Expand Down Expand Up @@ -42,6 +43,15 @@ func SetEnv(key, value string) string {
return value
}

func ReplaceNonAlphaNumericChars(words, replaceWith string) string {
reg, err := regexp.Compile("[^A-Za-z0-9]+")
if err != nil {
log.Fatal(err)
}
newStr := reg.ReplaceAllString(words, replaceWith)
return newStr
}

func CommandExists(mapArr map[string]func(map[string]string, map[int]string), key string) bool {
if _, ok := mapArr[key]; ok {
return true
Expand Down Expand Up @@ -106,5 +116,6 @@ func MakeRequest(payload, url, method string) map[string]interface{} {
m := make(map[string]interface{})
m["responseCode"] = resp.StatusCode
m["responseMessage"] = bodyString

return m
}
4 changes: 2 additions & 2 deletions glab.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

var (
version string
build string
version string
build string
commit string
)

Expand Down

0 comments on commit c78600f

Please sign in to comment.