diff --git a/server/handler/frontend.go b/server/handler/frontend.go index a1772b27..2f4bc17e 100644 --- a/server/handler/frontend.go +++ b/server/handler/frontend.go @@ -15,6 +15,7 @@ package handler import ( + "fmt" "html/template" "net/http" "path" @@ -95,40 +96,54 @@ func Static(prefix string, c *FilesConfig) http.Handler { } func getMethods(result *common.Result) map[string][]string { + const ( + commentKey = "Comments containing" + commentPatternKey = "Comments matching patterns" + bodyPatternKey = "The pull request body matching patterns" + reviewKey = "GitHub reviews with status" + ) + patternInfo := make(map[string][]string) for _, comment := range result.Methods.Comments { - patternInfo["Comments"] = append(patternInfo["Comments"], comment) + patternInfo[commentKey] = append(patternInfo[commentKey], comment) } for _, commentPattern := range result.Methods.CommentPatterns { - patternInfo["Comment Patterns"] = append(patternInfo["Comment Patterns"], commentPattern.String()) + patternInfo[commentPatternKey] = append(patternInfo[commentPatternKey], commentPattern.String()) } for _, bodyPattern := range result.Methods.BodyPatterns { - patternInfo["Body Patterns"] = append(patternInfo["Body Patterns"], bodyPattern.String()) + patternInfo[bodyPatternKey] = append(patternInfo[bodyPatternKey], bodyPattern.String()) } if result.Methods.GithubReview != nil && *result.Methods.GithubReview { + reviewPatternKey := reviewKey + fmt.Sprintf(" %s matching patterns", result.Methods.GithubReviewState) if len(result.Methods.GithubReviewCommentPatterns) > 0 { for _, githubReviewCommentPattern := range result.Methods.GithubReviewCommentPatterns { - patternInfo["Github Review Comment Patterns + Github Review Approval"] = append(patternInfo["Github Review Comment Patterns + Github Review Approval"], githubReviewCommentPattern.String()) + patternInfo[reviewPatternKey] = append(patternInfo[reviewPatternKey], githubReviewCommentPattern.String()) } } else { - patternInfo["Github Review State"] = append(patternInfo["Github Review State"], string(result.Methods.GithubReviewState)) + patternInfo[reviewKey] = append(patternInfo[reviewKey], string(result.Methods.GithubReviewState)) } } return patternInfo } func getActors(result *common.Result, githubURL string) map[string][]Membership { + const ( + orgKey = "Members of the organizations" + teamKey = "Members of the teams" + userKey = "Users" + ) + membershipInfo := make(map[string][]Membership) for _, org := range result.Requires.Actors.Organizations { - membershipInfo["Organizations"] = append(membershipInfo["Organizations"], Membership{Name: org, Link: githubURL + "/orgs/" + org + "/people"}) + membershipInfo[orgKey] = append(membershipInfo[orgKey], Membership{Name: org, Link: githubURL + "/orgs/" + org + "/people"}) } for _, team := range result.Requires.Actors.Teams { teamName := strings.Split(team, "/") - membershipInfo["Teams"] = append(membershipInfo["Teams"], Membership{Name: team, Link: githubURL + "/orgs/" + teamName[0] + "/teams/" + teamName[1] + "/members"}) + membershipInfo[teamKey] = append(membershipInfo[teamKey], Membership{Name: team, Link: githubURL + "/orgs/" + teamName[0] + "/teams/" + teamName[1] + "/members"}) } for _, user := range result.Requires.Actors.Users { - membershipInfo["Users"] = append(membershipInfo["Users"], Membership{Name: user, Link: githubURL + "/" + user}) + membershipInfo[userKey] = append(membershipInfo[userKey], Membership{Name: user, Link: githubURL + "/" + user}) } return membershipInfo } diff --git a/server/templates/details.html.tmpl b/server/templates/details.html.tmpl index 08efed9e..0995942c 100644 --- a/server/templates/details.html.tmpl +++ b/server/templates/details.html.tmpl @@ -60,27 +60,25 @@
Details
- {{if .PredicateResults}} + {{if .PredicateResults}}
{{template "result-predicates-details" .}}
{{end}} -
- {{template "result-requires-count" .}} -
- {{if (hasActors .Requires)}} -
- {{template "result-actors-details" .}} -
- {{end}} - {{if (hasActorsPermissions .Requires)}} -
- {{template "result-actors-permissions-details" .}} -
+ {{if ne $s "skipped"}}{{/* only show approval details for active rules */}} + {{if gt .Requires.Count 0 }}{{/* only show approval details if they're required */}} +
+ {{template "result-approver-details" .}} +
+
+ {{template "result-methods-details" .}} +
+ {{else}} +
+ This rule is automatically approved and requires no reviews +
+ {{end}} {{end}} -
- {{template "result-methods-details" .}} -
{{end}} @@ -148,40 +146,42 @@ {{end}} -{{define "result-requires-count"}} - This rule requires at least this many reviews -
-
{{.Requires.Count}}
-
-{{end}} - {{define "result-methods-details"}} - This rule requires review using any of these methods + Approvals may use any of these methods:
{{range $k, $v := getMethods .}} -
{{$k}}
+
{{$k}}:
- +
{{end}}
{{end}} -{{define "result-actors-details"}} - This rule requires review from -
- {{range $k, $v := getActors .}} -
{{$k}}
-
+{{define "result-approver-details"}} + {{$hasActors := hasActors .Requires}} + {{$hasPerms := hasActorsPermissions .Requires}} + {{if or $hasActors $hasPerms}} + {{template "result-reviews-count" .Requires}} from: +
+ {{if $hasActors}} + {{range $k, $v := getActors .}} +
{{$k}}:
+
-
+
+ {{end}} + {{end}} + {{if $hasPerms}} +
Users with the permissions:
+
+ +
+ {{end}} +
+ {{else}} + {{template "result-reviews-count" .Requires}} {{end}} - {{end}} -{{define "result-actors-permissions-details"}} - This rule requires review from users with these permissions - -{{end}} +{{define "result-reviews-count"}}This rule requires at least {{.Count}} approval{{if gt .Count 1}}s{{end}}{{end}}