Skip to content

Commit

Permalink
mr_show: Display approvals
Browse files Browse the repository at this point in the history
Currently there is no way to use lab to view the list of contributors that
have approved an MR.  It would be nice if the users that approved an MR
were displayed in the 'mr show' output.

Display the approvers in a 'Approved By:' section of 'mr show'.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
  • Loading branch information
prarit committed Dec 1, 2020
1 parent 0fd88fc commit 46cef78
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/mr_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func printMR(mr *gitlab.MergeRequest, project string, renderMarkdown bool) {
assignee := "None"
milestone := "None"
labels := "None"
approvedByUsers := "None"
state := map[string]string{
"opened": "Open",
"closed": "Closed",
Expand Down Expand Up @@ -145,6 +146,14 @@ func printMR(mr *gitlab.MergeRequest, project string, renderMarkdown bool) {
log.Fatal(err)
}

approvedBys, err := lab.GetMRApprovedBys(project, mr.IID)
if err != nil {
log.Fatal(err)
}
if len(approvedBys) > 0 {
approvedByUsers = strings.Join(approvedBys, ", ")
}

fmt.Printf(`
#%d %s
===================================
Expand All @@ -155,14 +164,15 @@ Branches: %s->%s
Status: %s
Assignee: %s
Author: %s
Approved By: %s
Milestone: %s
Labels: %s
Issues Closed by this MR: %s
WebURL: %s
`,
mr.IID, mr.Title, mr.Description, project, mr.SourceBranch,
mr.TargetBranch, state, assignee,
mr.Author.Username, milestone, labels,
mr.Author.Username, approvedByUsers, milestone, labels,
strings.Trim(strings.Replace(fmt.Sprint(closingIssues), " ", ",", -1), "[]"),
mr.WebURL,
)
Expand Down
1 change: 1 addition & 0 deletions cmd/mr_show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Branches: mrtest->master
Status: Open
Assignee: zaquestion
Author: zaquestion
Approved By: None
Milestone: 1.0
Labels: documentation
Issues Closed by this MR:
Expand Down
20 changes: 20 additions & 0 deletions internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,3 +1102,23 @@ func MoveIssue(project string, issueNum int, dest string) (string, error) {
}
return fmt.Sprintf("%s/issues/%d", destProject.WebURL, issue.IID), nil
}

func GetMRApprovedBys(project string, mrNum int) ([]string, error) {
var retArray []string

p, err := FindProject(project)
if err != nil {
return retArray, err
}

configuration, _, err := lab.MergeRequestApprovals.GetConfiguration(p.ID, mrNum)
if err != nil {
return retArray, err
}

for _, approvedby := range configuration.ApprovedBy {
retArray = append(retArray, approvedby.User.Username)
}

return retArray, err
}

0 comments on commit 46cef78

Please sign in to comment.