Skip to content

Commit 8c8e502

Browse files
committed
mr show: Display output for approvers and reviewers
Several users have requested that the list of approvers and reviewers be added to the output of the 'lab mr show' command. This list is useful for authors to know who to request reviews from, and to see the eligible list of approvers. Add Approvers, Approval Groups, and Reviewers to the output of 'lab mr show'. Signed-off-by: Prarit Bhargava <prarit@redhat.com>
1 parent 73fd2bc commit 8c8e502

3 files changed

Lines changed: 55 additions & 15 deletions

File tree

cmd/mr_show.go

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,18 @@ func printMR(mr *gitlab.MergeRequest, project string, renderMarkdown bool) {
124124
milestone := "None"
125125
labels := "None"
126126
approvedByUsers := "None"
127+
approvers := "None"
128+
approverGroups := "None"
129+
reviewers := "None"
127130
subscribed := "No"
128131
state := map[string]string{
129132
"opened": "Open",
130133
"closed": "Closed",
131134
"merged": "Merged",
132135
}[mr.State]
133136

137+
var _tmpStringArray []string
138+
134139
if state == "Open" && mr.MergeStatus == "cannot_be_merged" {
135140
state = "Open (Needs Rebase)"
136141
}
@@ -158,12 +163,47 @@ func printMR(mr *gitlab.MergeRequest, project string, renderMarkdown bool) {
158163
log.Fatal(err)
159164
}
160165

161-
approvedBys, err := lab.GetMRApprovedBys(project, mr.IID)
166+
approvalConfig, err := lab.GetMRApprovalsConfiguration(project, mr.IID)
162167
if err != nil {
163168
log.Fatal(err)
164169
}
165-
if len(approvedBys) > 0 {
166-
approvedByUsers = strings.Join(approvedBys, ", ")
170+
171+
for _, approvedby := range approvalConfig.ApprovedBy {
172+
_tmpStringArray = append(_tmpStringArray, approvedby.User.Username)
173+
}
174+
if len(_tmpStringArray) > 0 {
175+
approvedByUsers = strings.Join(_tmpStringArray, ", ")
176+
_tmpStringArray = nil
177+
}
178+
179+
// An argument could be made to separate these two fields into their own
180+
// entries, however, at a high level they essentially the users that can
181+
// approve the MR
182+
for _, approvers := range approvalConfig.Approvers {
183+
_tmpStringArray = append(_tmpStringArray, approvers.User.Username)
184+
}
185+
for _, suggestedApprovers := range approvalConfig.SuggestedApprovers {
186+
_tmpStringArray = append(_tmpStringArray, suggestedApprovers.Username)
187+
}
188+
if len(_tmpStringArray) > 0 {
189+
approvers = strings.Join(_tmpStringArray, ", ")
190+
_tmpStringArray = nil
191+
}
192+
193+
for _, approversGroups := range approvalConfig.ApproverGroups {
194+
_tmpStringArray = append(_tmpStringArray, approversGroups.Group.Name)
195+
}
196+
if len(_tmpStringArray) > 0 {
197+
approverGroups = strings.Join(_tmpStringArray, ", ")
198+
_tmpStringArray = nil
199+
}
200+
201+
for _, reviewerUsers := range mr.Reviewers {
202+
_tmpStringArray = append(_tmpStringArray, reviewerUsers.Name)
203+
}
204+
if len(_tmpStringArray) > 0 {
205+
reviewers = strings.Join(_tmpStringArray, ", ")
206+
_tmpStringArray = nil
167207
}
168208

169209
if mr.Subscribed {
@@ -181,15 +221,18 @@ Status: %s
181221
Assignee: %s
182222
Author: %s
183223
Approved By: %s
224+
Approvers: %s
225+
Approval Groups: %s
226+
Reviewers: %s
184227
Milestone: %s
185228
Labels: %s
186229
Issues Closed by this MR: %s
187230
Subscribed: %s
188231
WebURL: %s
189232
`,
190233
mr.IID, mr.Title, mr.Description, project, mr.SourceBranch,
191-
mr.TargetBranch, state, assignee,
192-
mr.Author.Username, approvedByUsers, milestone, labels,
234+
mr.TargetBranch, state, assignee, mr.Author.Username,
235+
approvedByUsers, approvers, approverGroups, reviewers, milestone, labels,
193236
strings.Trim(strings.Replace(fmt.Sprint(closingIssues), " ", ",", -1), "[]"),
194237
subscribed, mr.WebURL,
195238
)

cmd/mr_show_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Status: Open
3535
Assignee: zaquestion
3636
Author: zaquestion
3737
Approved By: None
38+
Approvers: None
39+
Approval Groups: None
40+
Reviewers: None
3841
Milestone: 1.0
3942
Labels: documentation
4043
Issues Closed by this MR:

internal/gitlab/gitlab.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,24 +1635,18 @@ func MoveIssue(project string, issueNum int, dest string) (string, error) {
16351635
return fmt.Sprintf("%s/issues/%d", destProject.WebURL, issue.IID), nil
16361636
}
16371637

1638-
func GetMRApprovedBys(project string, mrNum int) ([]string, error) {
1639-
var retArray []string
1640-
1638+
func GetMRApprovalsConfiguration(project string, mrNum int) (*gitlab.MergeRequestApprovals, error) {
16411639
p, err := FindProject(project)
16421640
if err != nil {
1643-
return retArray, err
1641+
return nil, err
16441642
}
16451643

16461644
configuration, _, err := lab.MergeRequestApprovals.GetConfiguration(p.ID, mrNum)
16471645
if err != nil {
1648-
return retArray, err
1649-
}
1650-
1651-
for _, approvedby := range configuration.ApprovedBy {
1652-
retArray = append(retArray, approvedby.User.Username)
1646+
return nil, err
16531647
}
16541648

1655-
return retArray, err
1649+
return configuration, err
16561650
}
16571651

16581652
func ResolveMRDiscussion(project string, mrNum int, discussionID string, noteID int) (string, error) {

0 commit comments

Comments
 (0)