Skip to content

Commit

Permalink
Added quickaction to files
Browse files Browse the repository at this point in the history
Added quickaction to the end of file when using -F;
Removed unessary reverse bool;

Signed-off-by: Lucas Zampieri <[email protected]>
  • Loading branch information
zampierilucas committed Sep 23, 2021
1 parent 983b32d commit 3ea4cc3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/mr_approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var mrApproveCmd = &cobra.Command{
}

msgs = append(msgs, "/approve")
createNote(rn, true, int(id), msgs, filename, linebreak, "", !note)
createNote(rn, true, int(id), msgs, filename, linebreak, "", note)

fmt.Printf("Merge Request !%d approved\n", id)
},
Expand Down
9 changes: 3 additions & 6 deletions cmd/mr_unapprove.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ var mrUnapproveCmd = &cobra.Command{
lab mr unapprove upstream -m "A helpfull\nComment" --force-linebreak`),
PersistentPreRun: labPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
var (
linebreak = false
canUnapprove = false
)

rn, id, err := parseArgsWithGitBranchMR(args)
if err != nil {
log.Fatal(err)
Expand All @@ -38,6 +33,7 @@ var mrUnapproveCmd = &cobra.Command{
log.Fatal(err)
}

canUnapprove := false
for _, approvers := range approvalConfig.ApprovedBy {
if approvers.User.Username == lab.User() {
canUnapprove = true
Expand Down Expand Up @@ -65,6 +61,7 @@ var mrUnapproveCmd = &cobra.Command{
}

note := comment || len(msgs) > 0 || filename != ""
linebreak := false
if note {
linebreak, err = cmd.Flags().GetBool("force-linebreak")
if err != nil {
Expand All @@ -73,7 +70,7 @@ var mrUnapproveCmd = &cobra.Command{
}

msgs = append(msgs, "/unapprove")
createNote(rn, true, int(id), msgs, filename, linebreak, "", !note)
createNote(rn, true, int(id), msgs, filename, linebreak, "", note)

fmt.Printf("Merge Request !%d unapproved\n", id)
},
Expand Down
10 changes: 7 additions & 3 deletions cmd/note_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func noteRunFn(cmd *cobra.Command, args []string) {
return
}

createNote(rn, isMR, int(idNum), msgs, filename, linebreak, commit, false)
createNote(rn, isMR, int(idNum), msgs, filename, linebreak, commit, true)
}

func createCommitNote(rn string, mrID int, sha string, newFile string, oldFile string, oldline int, newline int, comment string, block bool) {
Expand Down Expand Up @@ -231,7 +231,8 @@ func noteGetState(rn string, isMR bool, idNum int) (state string) {
return state
}

func createNote(rn string, isMR bool, idNum int, msgs []string, filename string, linebreak bool, commit string, quickaction bool) {
func createNote(rn string, isMR bool, idNum int, msgs []string, filename string, linebreak bool, commit string, hasNote bool) {
// hasNote is used by action that take advantage of Gitlab 'quick-action' notes, which do not create a noteURL
var err error

body := ""
Expand All @@ -241,6 +242,9 @@ func createNote(rn string, isMR bool, idNum int, msgs []string, filename string,
log.Fatal(err)
}
body = string(content)
if hasNote {
body += msgs[0]
}
} else {
state := noteGetState(rn, isMR, idNum)

Expand Down Expand Up @@ -283,7 +287,7 @@ func createNote(rn string, isMR bool, idNum int, msgs []string, filename string,
if err != nil {
log.Fatal(err)
}
if !quickaction {
if hasNote {
fmt.Println(noteURL)
}
}
Expand Down

0 comments on commit 3ea4cc3

Please sign in to comment.