Skip to content

Commit

Permalink
util: move filterCommentArg to util file
Browse files Browse the repository at this point in the history
filterCommentArg() is being used in two places (issue_note and mr_edit), since
this function is not restricted to issue_note, where it was being declared,
move it to util.

Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
  • Loading branch information
bmeneg committed Jan 25, 2021
1 parent 7183bba commit ea207ca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
32 changes: 0 additions & 32 deletions cmd/issue_note.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,38 +311,6 @@ func replyNote(rn string, isMR bool, idNum int, reply int, quote bool, update bo
}
}

func filterCommentArg(args []string) (int, []string, error) {
branchArgs := []string{}
idString := ""

if len(args) == 1 {
ok, err := git.IsRemote(args[0])
if err != nil {
return 0, branchArgs, err
}
if ok {
branchArgs = append(branchArgs, args[0])
} else {
idString = args[0]
}
} else if len(args) > 1 {
branchArgs = append(branchArgs, args[0])
idString = args[1]
}

if strings.Contains(idString, ":") {
ps := strings.Split(idString, ":")
branchArgs = append(branchArgs, ps[0])
idString = ps[1]
} else {
branchArgs = append(branchArgs, idString)
idString = ""
}

idNum, _ := strconv.Atoi(idString)
return idNum, branchArgs, nil
}

func init() {
issueNoteCmd.Flags().StringArrayP("message", "m", []string{}, "use the given <msg>; multiple -m are concatenated as separate paragraphs")
issueNoteCmd.Flags().StringP("file", "F", "", "use the given file as the message")
Expand Down
32 changes: 32 additions & 0 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,38 @@ func parseArgsWithGitBranchMR(args []string) (string, int64, error) {
return s, i, nil
}

func filterCommentArg(args []string) (int, []string, error) {
branchArgs := []string{}
idString := ""

if len(args) == 1 {
ok, err := git.IsRemote(args[0])
if err != nil {
return 0, branchArgs, err
}
if ok {
branchArgs = append(branchArgs, args[0])
} else {
idString = args[0]
}
} else if len(args) > 1 {
branchArgs = append(branchArgs, args[0])
idString = args[1]
}

if strings.Contains(idString, ":") {
ps := strings.Split(idString, ":")
branchArgs = append(branchArgs, ps[0])
idString = ps[1]
} else {
branchArgs = append(branchArgs, idString)
idString = ""
}

idNum, _ := strconv.Atoi(idString)
return idNum, branchArgs, nil
}

// setCommandPrefix returns a concatenated value of some of the commandline.
// For example, 'lab mr show' would return 'mr_show.', and 'lab issue list'
// would return 'issue_list.'
Expand Down

0 comments on commit ea207ca

Please sign in to comment.