fix(api): handle non-collaborator reviewer validation error

This commit is contained in:
BLACKBOX Agent 2025-11-06 16:28:51 +00:00
parent 0edc001d28
commit 5b61f95373
2 changed files with 45 additions and 4 deletions

18
dist/index.js vendored
View File

@ -1320,6 +1320,7 @@ const utils = __importStar(__nccwpck_require__(9277));
const ERROR_PR_ALREADY_EXISTS = 'A pull request already exists for';
const ERROR_PR_REVIEW_TOKEN_SCOPE = 'Validation Failed: "Could not resolve to a node with the global id of';
const ERROR_PR_FORK_COLLAB = `Fork collab can't be granted by someone without permission`;
const ERROR_PR_REVIEWER_NOT_COLLABORATOR = 'Reviews may only be requested from collaborators';
const blobCreationLimit = (0, p_limit_1.default)(8);
class GitHubHelper {
constructor(githubServerHostname, token) {
@ -1433,10 +1434,23 @@ class GitHubHelper {
yield this.octokit.rest.pulls.requestReviewers(Object.assign(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pull.number }), requestReviewersParams));
}
catch (e) {
if (utils.getErrorMessage(e).includes(ERROR_PR_REVIEW_TOKEN_SCOPE)) {
const errorMessage = utils.getErrorMessage(e);
if (errorMessage.includes(ERROR_PR_REVIEW_TOKEN_SCOPE)) {
core.error(`Unable to request reviewers. If requesting team reviewers a 'repo' scoped PAT is required.`);
throw e;
}
else if (errorMessage.includes(ERROR_PR_REVIEWER_NOT_COLLABORATOR)) {
core.warning(`Unable to request reviewers. One or more of the users or teams you specified is not a collaborator of this repository.`);
core.warning(`Reviews may only be requested from collaborators. To resolve this issue, you can:`);
core.warning(` 1. Add the user(s) as collaborators to the repository`);
core.warning(` 2. Add the user(s) to a team with repository access and use 'team-reviewers' instead`);
core.warning(` 3. Remove the non-collaborator user(s) from the 'reviewers' input`);
core.warning(`The pull request was created/updated successfully, but reviewer requests were not applied.`);
core.warning(`See: https://docs.github.com/rest/pulls/review-requests#request-reviewers-for-a-pull-request`);
}
else {
throw e;
}
throw e;
}
}
return pull;

View File

@ -9,6 +9,8 @@ const ERROR_PR_ALREADY_EXISTS = 'A pull request already exists for'
const ERROR_PR_REVIEW_TOKEN_SCOPE =
'Validation Failed: "Could not resolve to a node with the global id of'
const ERROR_PR_FORK_COLLAB = `Fork collab can't be granted by someone without permission`
const ERROR_PR_REVIEWER_NOT_COLLABORATOR =
'Reviews may only be requested from collaborators'
const blobCreationLimit = pLimit(8)
@ -207,12 +209,37 @@ export class GitHubHelper {
...requestReviewersParams
})
} catch (e) {
if (utils.getErrorMessage(e).includes(ERROR_PR_REVIEW_TOKEN_SCOPE)) {
const errorMessage = utils.getErrorMessage(e)
if (errorMessage.includes(ERROR_PR_REVIEW_TOKEN_SCOPE)) {
core.error(
`Unable to request reviewers. If requesting team reviewers a 'repo' scoped PAT is required.`
)
throw e
} else if (errorMessage.includes(ERROR_PR_REVIEWER_NOT_COLLABORATOR)) {
core.warning(
`Unable to request reviewers. One or more of the users or teams you specified is not a collaborator of this repository.`
)
core.warning(
`Reviews may only be requested from collaborators. To resolve this issue, you can:`
)
core.warning(
` 1. Add the user(s) as collaborators to the repository`
)
core.warning(
` 2. Add the user(s) to a team with repository access and use 'team-reviewers' instead`
)
core.warning(
` 3. Remove the non-collaborator user(s) from the 'reviewers' input`
)
core.warning(
`The pull request was created/updated successfully, but reviewer requests were not applied.`
)
core.warning(
`See: https://docs.github.com/rest/pulls/review-requests#request-reviewers-for-a-pull-request`
)
} else {
throw e
}
throw e
}
}