Avoid crash around "DISMISSED" or "PENDING" reviewer states
This commit is contained in:
parent
45dec1b3e0
commit
fb63efcf05
3 changed files with 32 additions and 3 deletions
|
|
@ -623,6 +623,8 @@ const (
|
|||
approvedReviewState = "APPROVED"
|
||||
changesRequestedReviewState = "CHANGES_REQUESTED"
|
||||
commentedReviewState = "COMMENTED"
|
||||
dismissedReviewState = "DISMISSED"
|
||||
pendingReviewState = "PENDING"
|
||||
)
|
||||
|
||||
type reviewerState struct {
|
||||
|
|
@ -648,8 +650,14 @@ func colorFuncForReviewerState(state string) func(string) string {
|
|||
|
||||
// formattedReviewerState formats a reviewerState with state color
|
||||
func formattedReviewerState(reviewer *reviewerState) string {
|
||||
stateColorFunc := colorFuncForReviewerState(reviewer.State)
|
||||
return fmt.Sprintf("%s (%s)", reviewer.Name, stateColorFunc(strings.ReplaceAll(strings.Title(strings.ToLower(reviewer.State)), "_", " ")))
|
||||
state := reviewer.State
|
||||
if state == dismissedReviewState {
|
||||
// Show "DISMISSED" review as "COMMENTED", since "dimissed" only makes
|
||||
// sense when displayed in an events timeline but not in the final tally.
|
||||
state = commentedReviewState
|
||||
}
|
||||
stateColorFunc := colorFuncForReviewerState(state)
|
||||
return fmt.Sprintf("%s (%s)", reviewer.Name, stateColorFunc(strings.ReplaceAll(strings.Title(strings.ToLower(state)), "_", " ")))
|
||||
}
|
||||
|
||||
// prReviewerList generates a reviewer list with their last state
|
||||
|
|
@ -705,6 +713,9 @@ func parseReviewers(pr api.PullRequest) []*reviewerState {
|
|||
// Convert map to slice for ease of sort
|
||||
result := make([]*reviewerState, 0, len(reviewerStates))
|
||||
for _, reviewer := range reviewerStates {
|
||||
if reviewer.State == pendingReviewState {
|
||||
continue
|
||||
}
|
||||
result = append(result, reviewer)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -477,7 +477,7 @@ func TestPRView_Preview(t *testing.T) {
|
|||
fixture: "../test/fixtures/prViewPreviewWithReviewersByNumber.json",
|
||||
expectedOutputs: []string{
|
||||
`Blueberries are from a fork`,
|
||||
`Reviewers: DEF \(Commented\), def \(Changes requested\), ghost \(Approved\), xyz \(Approved\), 123 \(Requested\), Team 1 \(Requested\), abc \(Requested\)\n`,
|
||||
`Reviewers: DEF \(Commented\), def \(Changes requested\), ghost \(Approved\), hubot \(Commented\), xyz \(Approved\), 123 \(Requested\), Team 1 \(Requested\), abc \(Requested\)\n`,
|
||||
`blueberries taste good`,
|
||||
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12\n`,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -70,6 +70,24 @@
|
|||
"login": ""
|
||||
},
|
||||
"state": "APPROVED"
|
||||
},
|
||||
{
|
||||
"author": {
|
||||
"login": "hubot"
|
||||
},
|
||||
"state": "CHANGES_REQUESTED"
|
||||
},
|
||||
{
|
||||
"author": {
|
||||
"login": "hubot"
|
||||
},
|
||||
"state": "DISMISSED"
|
||||
},
|
||||
{
|
||||
"author": {
|
||||
"login": "monalisa"
|
||||
},
|
||||
"state": "PENDING"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue