Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #31 from profclems/deepsource-transform-af1fd911
Browse files Browse the repository at this point in the history
Format code with Go fmt
  • Loading branch information
profclems authored Aug 3, 2020
2 parents 9211a46 + 4c8c374 commit 136624b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 47 deletions.
24 changes: 12 additions & 12 deletions commands/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func displayIssue(hm *gitlab.Issue) {
}

func createIssue(cmdArgs map[string]string, _ map[int]string) {
l := &gitlab.CreateIssueOptions {}
l := &gitlab.CreateIssueOptions{}
reader := bufio.NewReader(os.Stdin)
var issueTitle string
var issueLabel string
Expand Down Expand Up @@ -99,7 +99,7 @@ func createIssue(cmdArgs map[string]string, _ map[int]string) {
l.MilestoneID = gitlab.Int(stringToInt(cmdArgs["milestone"]))
}
if CommandArgExists(cmdArgs, "resolved-by-merge-request") {
l.MergeRequestToResolveDiscussionsOf = gitlab.Int(stringToInt(cmdArgs["resolved-by-merge"]))
l.MergeRequestToResolveDiscussionsOf = gitlab.Int(stringToInt(cmdArgs["resolved-by-merge"]))
}
if CommandArgExists(cmdArgs, "assigns") {
assignID := cmdArgs["assigns"]
Expand Down Expand Up @@ -128,7 +128,7 @@ func listIssues(cmdArgs map[string]string, _ map[int]string) {
state = "opened"
}

l := &gitlab.ListProjectIssuesOptions {
l := &gitlab.ListProjectIssuesOptions{
State: gitlab.String(state),
}
if CommandArgExists(cmdArgs, "label") || CommandArgExists(cmdArgs, "labels") {
Expand Down Expand Up @@ -269,15 +269,15 @@ func changeIssueState(cmdArgs map[string]string, arrFlags map[int]string) {
// ExecIssue is exported
func ExecIssue(cmdArgs map[string]string, arrCmd map[int]string) {
commandList := map[interface{}]func(map[string]string, map[int]string){
"create": createIssue,
"list": listIssues,
"ls": listIssues,
"delete": deleteIssue,
"subscribe": subscribeIssue,
"unsubscribe": unsubscribeIssue,
"open": changeIssueState,
"reopen": changeIssueState,
"close": changeIssueState,
"create": createIssue,
"list": listIssues,
"ls": listIssues,
"delete": deleteIssue,
"subscribe": subscribeIssue,
"unsubscribe": unsubscribeIssue,
"open": changeIssueState,
"reopen": changeIssueState,
"close": changeIssueState,
}
if _, ok := commandList[arrCmd[0]]; ok {
commandList[arrCmd[0]](cmdArgs, arrCmd)
Expand Down
8 changes: 3 additions & 5 deletions commands/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func createLabel(cmdArgs map[string]string, _ map[int]string) {
log.Printf("Created label: %s\nWith color: %s\n", label.Name, label.Color)
}


func listLabels(cmdArgs map[string]string, _ map[int]string) {
git, repo := InitGitlabClient()
// List all labels
Expand All @@ -57,14 +56,13 @@ func listLabels(cmdArgs map[string]string, _ map[int]string) {
// ExecRepo is ...
func ExecLabel(cmdArgs map[string]string, arrCmd map[int]string) {
commandList := map[interface{}]func(map[string]string, map[int]string){
"create": createLabel,
"new": createLabel,
"list": listLabels,
"create": createLabel,
"new": createLabel,
"list": listLabels,
}
if _, ok := commandList[arrCmd[0]]; ok {
commandList[arrCmd[0]](cmdArgs, arrCmd)
} else {
fmt.Println(arrCmd[0]+":", "Invalid Command")
}
}

15 changes: 6 additions & 9 deletions commands/mr.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ func displayMergeRequest(hm *gitlab.MergeRequest) {
}
}



func displayAllMergeRequests(m []*gitlab.MergeRequest) {
// initialize tabwriter
w := new(tabwriter.Writer)
Expand All @@ -48,7 +46,7 @@ func displayAllMergeRequests(m []*gitlab.MergeRequest) {
}

func createMergeRequest(cmdArgs map[string]string, _ map[int]string) {
l := &gitlab.CreateMergeRequestOptions {}
l := &gitlab.CreateMergeRequestOptions{}
reader := bufio.NewReader(os.Stdin)
var sourceBranch string
var targetBranch string
Expand Down Expand Up @@ -136,13 +134,13 @@ func createMergeRequest(cmdArgs map[string]string, _ map[int]string) {
git, repo := InitGitlabClient()
if CommandArgExists(cmdArgs, "create-branch") {
lb := &gitlab.CreateBranchOptions{
Branch: gitlab.String(sourceBranch),
Ref: gitlab.String(targetBranch),
Branch: gitlab.String(sourceBranch),
Ref: gitlab.String(targetBranch),
}
fmt.Println("Creating related branch...")
branch, resp, _ := git.Branches.CreateBranch(repo, lb)
if resp.StatusCode == 201 {
fmt.Println("Branch created: ",branch.WebURL)
fmt.Println("Branch created: ", branch.WebURL)
} else {
fmt.Println("Error creating branch: ", resp.Status)
}
Expand Down Expand Up @@ -233,7 +231,7 @@ func listMergeRequests(cmdArgs map[string]string, _ map[int]string) {
state = "opened"
}

l := &gitlab.ListProjectMergeRequestsOptions {
l := &gitlab.ListProjectMergeRequestsOptions{
State: gitlab.String(state),
}
if CommandArgExists(cmdArgs, "label") || CommandArgExists(cmdArgs, "labels") {
Expand All @@ -257,7 +255,7 @@ func listMergeRequests(cmdArgs map[string]string, _ map[int]string) {

func issuesRelatedMergeRequest(cmdArgs map[string]string, arrFlags map[int]string) {
mergeID := strings.Trim(arrFlags[1], " ")
l := &gitlab.GetIssuesClosedOnMergeOptions {}
l := &gitlab.GetIssuesClosedOnMergeOptions{}
git, repo := InitGitlabClient()
mr, _, err := git.MergeRequests.GetIssuesClosedOnMerge(repo, stringToInt(mergeID), l)
if err != nil {
Expand All @@ -266,7 +264,6 @@ func issuesRelatedMergeRequest(cmdArgs map[string]string, arrFlags map[int]strin
displayAllIssues(mr)
}


func deleteMergeRequest(cmdArgs map[string]string, arrFlags map[int]string) {
mergeID := strings.Trim(arrFlags[1], " ")
git, repo := InitGitlabClient()
Expand Down
18 changes: 9 additions & 9 deletions commands/univ.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ import (
var (
// UseGlobalConfig : use the global configuration file
UseGlobalConfig bool
globalPathDir = ""
globalPathDir = ""
configFileFileParentDir = ".glab-cli"
configFileFileDir = configFileFileParentDir + "/config"
configFile = configFileFileDir + "/.env"
globalConfigFile = configFile
)

func SetGlobalPathDir() string {
func SetGlobalPathDir() string {
usr, err := user.Current()
if err != nil {
log.Fatal( err )
log.Fatal(err)
}
globalPathDir = usr.HomeDir
globalConfigFile = globalPathDir + "/" + globalConfigFile
globalConfigFile = globalPathDir + "/" + globalConfigFile
return globalPathDir
}

func getRepo() string {
gitlab, err := gitconfig.Entire("remote."+GetEnv("GIT_REMOTE_URL_VAR")+".url")
gitlab, err := gitconfig.Entire("remote." + GetEnv("GIT_REMOTE_URL_VAR") + ".url")
if err != nil {
log.Fatal("Could not find remote url for gitlab")
}
repoBaseUrl := strings.Trim(GetEnv("GITLAB_URI"), "/ ")
repoBaseUrl = strings.TrimPrefix(repoBaseUrl, "https://")
repoBaseUrl = strings.TrimPrefix(repoBaseUrl, "http://")
repo := strings.TrimSuffix(gitlab, ".git")
repo := strings.TrimSuffix(gitlab, ".git")
repo = strings.TrimPrefix(repo, repoBaseUrl)
repo = strings.TrimPrefix(repo, "https://"+repoBaseUrl)
repo = strings.TrimPrefix(repo, "http://"+repoBaseUrl)
Expand All @@ -56,15 +56,15 @@ func getRepo() string {
}

// InitGitlabClient : creates client
func InitGitlabClient() (*gitlab.Client, string) {
git, err := gitlab.NewClient(GetEnv("GITLAB_TOKEN"), gitlab.WithBaseURL(strings.TrimRight(GetEnv("GITLAB_URI"),"/") + "/api/v4"))
func InitGitlabClient() (*gitlab.Client, string) {
git, err := gitlab.NewClient(GetEnv("GITLAB_TOKEN"), gitlab.WithBaseURL(strings.TrimRight(GetEnv("GITLAB_URI"), "/")+"/api/v4"))
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
return git, getRepo()
}

func VariableExists(key string) string {
func VariableExists(key string) string {
return GetKeyValueInFile(configFile, key)
}

Expand Down
24 changes: 12 additions & 12 deletions glab.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ func Help(args map[string]string, arrCmd map[int]string) {

func config(cmdArgs map[string]string, arrCmd map[int]string) {
cmdHelpList := map[string]string{
"uri": "GITLAB_URI",
"url": "GITLAB_URI",
"token": "GITLAB_TOKEN",
"repo": "GITLAB_REPO",
"pid": "GITLAB_PROJECT_ID",
"remote-var": "GIT_REMOTE_URL_VAR",
"origin": "GIT_REMOTE_URL_VAR",
"origin-var": "GIT_REMOTE_URL_VAR",
"uri": "GITLAB_URI",
"url": "GITLAB_URI",
"token": "GITLAB_TOKEN",
"repo": "GITLAB_REPO",
"pid": "GITLAB_PROJECT_ID",
"remote-var": "GIT_REMOTE_URL_VAR",
"origin": "GIT_REMOTE_URL_VAR",
"origin-var": "GIT_REMOTE_URL_VAR",
}

commands.UseGlobalConfig = true
if commands.VariableExists("GITLAB_URI")=="NOTFOUND" || commands.VariableExists("GITLAB_URI")=="OK" {
if commands.VariableExists("GITLAB_URI") == "NOTFOUND" || commands.VariableExists("GITLAB_URI") == "OK" {
commands.SetEnv("GITLAB_URI", "https://gitlab.com")
}
if commands.VariableExists("GIT_REMOTE_URL_VAR")=="NOTFOUND" || commands.VariableExists("GIT_REMOTE_URL_VAR")=="OK" {
if commands.VariableExists("GIT_REMOTE_URL_VAR") == "NOTFOUND" || commands.VariableExists("GIT_REMOTE_URL_VAR") == "OK" {
commands.SetEnv("GIT_REMOTE_URL_VAR", "origin")
}
commands.UseGlobalConfig = false
Expand All @@ -73,7 +73,7 @@ func config(cmdArgs map[string]string, arrCmd map[int]string) {

// Exec is exported
func Exec(cmd string, cmdArgs map[string]string, arrCmd map[int]string) {
commandList := map[string]func(map[string]string, map[int]string) {
commandList := map[string]func(map[string]string, map[int]string){
"issue": commands.ExecIssue,
"mr": commands.ExecMergeRequest,
"label": commands.ExecLabel,
Expand All @@ -91,7 +91,7 @@ func Exec(cmd string, cmdArgs map[string]string, arrCmd map[int]string) {

if len(cmdArgs) > 0 {
if cmdArgs["help"] == "true" {
cmdHelpList := map[string]func() {
cmdHelpList := map[string]func(){
"help": utils.PrintHelpHelp,
"issue": utils.PrintHelpIssue,
"mr": utils.PrintHelpMr,
Expand Down

0 comments on commit 136624b

Please sign in to comment.