Skip to content

Commit

Permalink
feat(generated-files-bot): configurable list of PR authors to ignore (#…
Browse files Browse the repository at this point in the history
…1254)

Fixes #1096
  • Loading branch information
chingor13 committed Dec 16, 2020
1 parent 8f86abb commit d3c42d5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/generated-files-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ options:
| ---- | ----------- | ---- | ------- |
| `generatedFiles` | An explicit list of files which are considered templates. | `string[]` | `[]` |
| `externalManifests` | List of external manifest files to parse. | `ExternalManifest[]` | `[]` |
| `ignoreAuthors` | List of PR authors to ignore. | `string[]` | `[]` |

External Manifest:

Expand Down
7 changes: 7 additions & 0 deletions packages/generated-files-bot/src/generated-files-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface ExternalManifest {
export interface Configuration {
generatedFiles?: string[];
externalManifests?: ExternalManifest[];
ignoreAuthors?: string[];
}

/**
Expand Down Expand Up @@ -165,6 +166,12 @@ export function handler(app: Application) {
const owner = context.payload.repository.owner.login;
const repo = context.payload.repository.name;
const pullNumber = context.payload.pull_request.number;
const prAuthor = context.payload.pull_request.user.login;

// ignore PRs from a configurable list of authors
if (config.ignoreAuthors?.includes(prAuthor)) {
return;
}

// Read the list of templated files
const templatedFiles = new Set(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatedFiles:
- 'file1.txt'
externalManifests:
- type: json
file: 'manifest.json'
jsonpath: '$.key1[*]'
- type: 'yaml'
file: 'manifest.yaml'
jsonpath: '$.key2.key3[*]'
ignoreAuthors:
- testuser2
17 changes: 17 additions & 0 deletions packages/generated-files-bot/test/generated-files-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,23 @@ describe('generated-files-bot', () => {
});
requests.done();
});

it('ignores PRs from configured autors', async () => {
const validConfig = fs.readFileSync(
resolve(fixturesPath, 'config', 'ignore-authors.yml')
);
requests = requests
.get(
'/repos/testOwner/testRepo/contents/.github%2Fgenerated-files-bot.yml'
)
.reply(200, validConfig);
await probot.receive({
name: 'pull_request',
payload: payload,
id: 'abc123',
});
requests.done();
});
});
});
});

0 comments on commit d3c42d5

Please sign in to comment.