forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
714 changed files
with
5,165 additions
and
1,376 deletions.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
.ci/containers/membership-checker/REVIEWER_ASSIGNMENT_COMMENT.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
Hello! I am a robot. It looks like you are a community contributor. @{{reviewer}}, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look. | ||
Hello! I am a robot. It looks like you are a: {{if eq .authorUserType "Community Contributor"}}Community Contributor{{else}}~Community Contributor~{{end}} {{if eq .authorUserType "Googler"}}Googler{{else}}~Googler~{{end}} {{if eq .authorUserType "Core Contributor"}}Core Contributor{{else}}~Core Contributor~{{end}}. {{if .trusted}}Tests will run automatically.{{else}}Tests will require approval to run.{{end}} | ||
|
||
@{{.reviewer}}, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look. | ||
|
||
You can help make sure that review is quick by [doing a self-review](https://googlecloudplatform.github.io/magic-modules/contribute/review-pr/) and by [running impacted tests locally](https://googlecloudplatform.github.io/magic-modules/get-started/run-provider-tests/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
.ci/containers/membership-checker/reviewer_assignment_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"golang.org/x/exp/slices" | ||
) | ||
|
||
func TestChooseReviewers(t *testing.T) { | ||
cases := map[string]struct { | ||
FirstRequestedReviewer string | ||
PreviouslyInvolvedReviewers []string | ||
ExpectReviewersFromList, ExpectSpecificReviewers []string | ||
ExpectPrimaryReviewer bool | ||
}{ | ||
"no previous review requests assigns new reviewer from team": { | ||
FirstRequestedReviewer: "", | ||
PreviouslyInvolvedReviewers: []string{}, | ||
ExpectReviewersFromList: removes(reviewerRotation, onVacationReviewers), | ||
ExpectPrimaryReviewer: true, | ||
}, | ||
"first requested reviewer means that primary reviewer was already selected": { | ||
FirstRequestedReviewer: "foobar", | ||
PreviouslyInvolvedReviewers: []string{}, | ||
ExpectPrimaryReviewer: false, | ||
}, | ||
"previously involved team member reviewers should have review requested and mean that primary reviewer was already selected": { | ||
FirstRequestedReviewer: "", | ||
PreviouslyInvolvedReviewers: []string{reviewerRotation[0]}, | ||
ExpectSpecificReviewers: []string{reviewerRotation[0]}, | ||
ExpectPrimaryReviewer: false, | ||
}, | ||
"previously involved reviewers that are not team members are ignored": { | ||
FirstRequestedReviewer: "", | ||
PreviouslyInvolvedReviewers: []string{"foobar"}, | ||
ExpectReviewersFromList: removes(reviewerRotation, onVacationReviewers), | ||
ExpectPrimaryReviewer: true, | ||
}, | ||
"only previously involved team member reviewers will have review requested": { | ||
FirstRequestedReviewer: "", | ||
PreviouslyInvolvedReviewers: []string{reviewerRotation[0], "foobar", reviewerRotation[1]}, | ||
ExpectSpecificReviewers: []string{reviewerRotation[0], reviewerRotation[1]}, | ||
ExpectPrimaryReviewer: false, | ||
}, | ||
"primary reviewer will not have review requested even if other team members previously reviewed": { | ||
FirstRequestedReviewer: reviewerRotation[1], | ||
PreviouslyInvolvedReviewers: []string{reviewerRotation[0]}, | ||
ExpectSpecificReviewers: []string{reviewerRotation[0]}, | ||
ExpectPrimaryReviewer: false, | ||
}, | ||
} | ||
|
||
for tn, tc := range cases { | ||
tc := tc | ||
t.Run(tn, func(t *testing.T) { | ||
t.Parallel() | ||
reviewers, primaryReviewer := chooseReviewers(tc.FirstRequestedReviewer, tc.PreviouslyInvolvedReviewers) | ||
if tc.ExpectPrimaryReviewer && primaryReviewer == "" { | ||
t.Error("wanted primary reviewer to be returned; got none") | ||
} | ||
if !tc.ExpectPrimaryReviewer && primaryReviewer != "" { | ||
t.Errorf("wanted no primary reviewer; got %s", primaryReviewer) | ||
} | ||
if len(tc.ExpectReviewersFromList) > 0 { | ||
for _, reviewer := range reviewers { | ||
if !slices.Contains(tc.ExpectReviewersFromList, reviewer) { | ||
t.Errorf("wanted reviewer %s to be in list %v but they were not", reviewer, tc.ExpectReviewersFromList) | ||
} | ||
} | ||
} | ||
if len(tc.ExpectSpecificReviewers) > 0 { | ||
if !slices.Equal(reviewers, tc.ExpectSpecificReviewers) { | ||
t.Errorf("wanted reviewers to be %v; instead got %v", tc.ExpectSpecificReviewers, reviewers) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestFormatReviewerComment(t *testing.T) { | ||
cases := map[string]struct { | ||
Reviewer string | ||
AuthorUserType userType | ||
Trusted bool | ||
}{ | ||
"community contributor": { | ||
Reviewer: "foobar", | ||
AuthorUserType: communityUserType, | ||
Trusted: false, | ||
}, | ||
"googler": { | ||
Reviewer: "foobar", | ||
AuthorUserType: googlerUserType, | ||
Trusted: true, | ||
}, | ||
"core contributor": { | ||
Reviewer: "foobar", | ||
AuthorUserType: coreContributorUserType, | ||
Trusted: true, | ||
}, | ||
} | ||
|
||
for tn, tc := range cases { | ||
tc := tc | ||
t.Run(tn, func(t *testing.T) { | ||
t.Parallel() | ||
comment := formatReviewerComment(tc.Reviewer, tc.AuthorUserType, tc.Trusted) | ||
t.Log(comment) | ||
if !strings.Contains(comment, fmt.Sprintf("@%s", tc.Reviewer)) { | ||
t.Errorf("wanted comment to contain @%s; does not.", tc.Reviewer) | ||
} | ||
if !strings.Contains(comment, tc.AuthorUserType.String()) { | ||
t.Errorf("wanted comment to contain user type (%s); does not.", tc.AuthorUserType.String()) | ||
} | ||
if strings.Contains(comment, fmt.Sprintf("~%s~", tc.AuthorUserType.String())) { | ||
t.Errorf("wanted user type (%s) in comment to not be crossed out, but it is", tc.AuthorUserType.String()) | ||
} | ||
for _, ut := range []userType{communityUserType, googlerUserType, coreContributorUserType} { | ||
if ut != tc.AuthorUserType && !strings.Contains(comment, fmt.Sprintf("~%s~", ut.String())) { | ||
t.Errorf("wanted other user type (%s) in comment to be crossed out, but it is not", ut) | ||
} | ||
} | ||
|
||
if tc.Trusted && !strings.Contains(comment, "Tests will run automatically") { | ||
t.Errorf("wanted comment to say tests will run automatically; does not") | ||
} | ||
if !tc.Trusted && !strings.Contains(comment, "Tests will require approval") { | ||
t.Errorf("wanted comment to say tests will require approval; does not") | ||
} | ||
}) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.