Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[owners] Allow bots to be listed in reviewerPool #1287

Merged
merged 2 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions owners/OWNERS.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
* the directory containing the OWNERS file.
*
* Example OWNERS file definition for a directory owned by the team
* `ampproject/wg-ui-and-a11y` and `rcebulko`, who should always be notified of
* `ampproject/wg-components` and `rcebulko`, who should always be notified of
* changes:
*
* {
* rules: [{
* owners: [
* { name: 'ampproject/wg-ui-and-a11y' },
* { name: 'ampproject/wg-components' },
* {
* name: 'rcebulko',
* notify: true,
Expand All @@ -41,8 +41,8 @@
* }
*/

// All owners files must contain a single `rules` key containing a list of owners
// rules.
// All owners files must contain a single `rules` key containing a list of
// owners rules.
{
rules: [
{
Expand Down Expand Up @@ -101,19 +101,20 @@
},

{
// To apply a filename or pattern to all subdirectories as well, prefix the
// pattern with `**/`. The pattern `**/.eslintrc` applies to `./.eslintrc`
// as well as `./foo/.eslintrc`. The pattern `**/*.protoascii` applies to
// `./test.protoascii` as well as `./foo/example.protoascii`.
// To apply a filename or pattern to all subdirectories as well, prefix
// the pattern with `**/`. The pattern `**/.eslintrc` applies to
// `./.eslintrc` as well as `./foo/.eslintrc`. The pattern
// `**/*.protoascii` applies to `./test.protoascii` as well as
// `./foo/example.protoascii`.
pattern: "**/*.protoascii",
owners: [{ name: "ampproject/wg-caching" }],
},

{
// Any other use of `/` in a pattern is forbidden (ie. no directory
// traversal). Patterns using `/` will be ignored. If rules are needed in a
// subdirectory, the appropriate OWNERS file should be created/updated in
// that subdirectory. This rule will be ignored since the pattern is
// traversal). Patterns using `/` will be ignored. If rules are needed in
// a subdirectory, the appropriate OWNERS file should be created/updated
// in that subdirectory. This rule will be ignored since the pattern is
// illegal.
pattern: "foo*/*.js",
owners: [{ name: "doesntmatter" }],
Expand All @@ -132,15 +133,21 @@

// The root-level owners file--and ONLY the root-level owners file--may
// specify an optional `reviewerPool` property, providing a list of GitHub
// users/teams. If present, the owners check will require that at least one
// member of this team has given approval. It is possible that one reviewer
// is both a member of this reviewer team and provides owners coverage.
reviewerPool: ["ampproject/reviewers-amphtml", "approver-bot"]
// teams/users/bots. If present, the owners check will require that at least
// one member of this pool has given approval. It is possible that a given
// reviewer is both a member of this reviewer pool and provides owners
// coverage.
reviewerPool: [
"ampproject/reviewers-amphtml",
"user-approver",
"bot-approver[bot]",
]
}

// The result of parsing this file would be a tree with these rules:
//
// Reviewers: ampproject/reviewers-amphtml [members...]
// Reviewers: ampproject/reviewers-amphtml [members...], user-approver,
// bot-approver[bot]
// **/*: someuser, dontdothis, ampproject/wg-cool-team [members...],
// dvoytenko (never notify), rcebulko (always notify), rando
// ./{package.json}: packager
Expand Down
5 changes: 5 additions & 0 deletions owners/src/ownership/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"minItems": 1,
"items": {
"oneOf": [
{"$ref": "#/definitions/Bot"},
{"$ref": "#/definitions/User"},
{"$ref": "#/definitions/Team"}
]
Expand All @@ -26,6 +27,10 @@
},

"definitions": {
"Bot": {
"type": "string",
"pattern": "^[a-zA-Z\\d][a-zA-Z\\d-_.]{2,37}[a-zA-Z\\d]\\[bot\\]$"
},
"User": {
"type": "string",
"pattern": "^[a-zA-Z\\d][a-zA-Z\\d-_.]{2,37}[a-zA-Z\\d]$"
Expand Down
12 changes: 9 additions & 3 deletions owners/test/ownership/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ describe('owners parser', () => {
const rule = rules.reviewerPool;
expect(rule.owners.map(owner => owner.name)).toEqual([
'ampproject/reviewers-amphtml',
'approver-bot',
'user-approver',
'bot-approver[bot]',
]);
});

Expand Down Expand Up @@ -539,14 +540,19 @@ describe('owners parser', () => {
it('records the reviewer set from "reviewerPool', () => {
const fileDef = {
rules,
reviewerPool: ['ampproject/reviewers-amphtml', 'approver-bot'],
reviewerPool: [
'ampproject/reviewers-amphtml',
'user-approver',
'bot-approver[bot]',
],
};
const {result} = parser.parseOwnersFileDefinition('OWNERS', fileDef);

expect(result[0]).toEqual(
new ReviewerSetRule('OWNERS', [
new TeamOwner(reviewerTeam),
new UserOwner('approver-bot'),
new UserOwner('user-approver'),
new UserOwner('bot-approver[bot]'),
])
);
});
Expand Down