@@ -49,45 +49,29 @@ jobs:
49
49
console.log('oldPrAssignees: ', oldPrAssignees);
50
50
const prAuthor = context.payload.pull_request.user.login;
51
51
52
- // Check if the PR is opened by a collaborator on the repo (aka a committer).
53
- // We use the /repos/{owner}/{repo}/collaborators/{username} endpoint to avoid
54
- // neeing org scope permissions.
55
- const isCollaboratorResponseObj = await github.request('GET /repos/{owner}/{repo}/collaborators/{username}', {
56
- owner: context.repo.owner,
57
- repo: context.repo.repo,
58
- username: prAuthor,
59
- headers: {
60
- 'X-GitHub-Api-Version': '2022-11-28'
61
- }
62
- }).catch((error) => {
63
- // So, I'm not sure if the error is being thrown by `@octokit/request.js` or
64
- // `@octokit/plugin-retry.js`. I suspect that the initial error is thrown by
65
- // `request.js`, and is subsequently propagated by `plugin-retry.js`.
66
- //
67
- // Anyway, the docs for `request.js` say the following:
68
- //
69
- // > If an error occurs, the promise is rejected with an `error` object
70
- //> containing 3 keys to help with debugging:
71
- // >
72
- // > - `error.status` The http response status code
73
- // > - `error.request` The request options such as `method`, `url` and `data`
74
- // > - `error.response` The http response object with `url`, `headers`, and `data`
75
- //
76
- // Source: https://github.com/octokit/request.js/blob/main/README.md#request
77
- //
78
- // So, inside this `.catch()`, we simply return that `error` object.
79
-
80
- return error;
81
- });
82
- if (isCollaboratorResponseObj.status == 204) {
83
- var isCollaborator = true;
84
- } else if (isCollaboratorResponseObj.status == 404) {
85
- var isCollaborator = false;
86
- } else {
87
- console.error('Unable to process the response from checkCollaborator');
88
- console.error('isCollaboratorResponseObj: ', isCollaboratorResponseObj);
89
- var isCollaborator = false;
90
- }
52
+ // Check if the PR is opened by a collaborator on the repo, aka someone with write (commit) permissions or higher.
53
+ const relevantPerms = [
54
+ // 'triage', // Uncomment this line if you don't want PRs from triagers to get auto-assignees.
55
+ 'push',
56
+ 'maintain',
57
+ 'admin',
58
+ ]
59
+ const allCollaboratorsNestedPromises = relevantPerms.map(
60
+ (perm) => github.paginate(
61
+ // We use the `/repos/{owner}/{repo}/collaborators` endpoint to avoid needing org scope permissions:
62
+ '/repos/{owner}/{repo}/collaborators',
63
+ {
64
+ owner: context.repo.owner,
65
+ repo: context.repo.repo,
66
+ per_page: 100,
67
+ permission: perm,
68
+ },
69
+ (response) => response.data.map((collaboratorInfo) => collaboratorInfo.login),
70
+ )
71
+ )
72
+ const allCollaboratorsNested = await Promise.all(allCollaboratorsNestedPromises);
73
+ const allCollaboratorsFlattened = allCollaboratorsNested.flat();
74
+ const isCollaborator = allCollaboratorsFlattened.includes(prAuthor);
91
75
92
76
console.log('prAuthor: ', prAuthor);
93
77
console.log('isCollaborator: ', isCollaborator);
0 commit comments