mirror of
https://github.com/actions/labeler.git
synced 2025-12-10 11:41:56 +00:00
Improve Labeler Action Documentation and Error Handling for Permissions (#897)
* Update README.md and labeler.ts to clarify permissions for GitHub Labeler Action * Update dist/index.js with latest build changes * Update README.md to clarify manual label creation as an alternative to granting issues write permission * Fix labeler error handling to ensure case-insensitive check for unauthorized access * Refactor error handling in labeler to throw an error for unauthorized access instead of logging * Add tests for labeler error handling and improve error reporting
This commit is contained in:
12
dist/index.js
vendored
12
dist/index.js
vendored
@@ -1028,6 +1028,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.run = void 0;
|
||||
exports.labeler = labeler;
|
||||
exports.checkMatchConfigs = checkMatchConfigs;
|
||||
exports.checkAny = checkAny;
|
||||
exports.checkAll = checkAll;
|
||||
@@ -1083,11 +1084,18 @@ function labeler() {
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
if (error.name !== 'HttpError' ||
|
||||
if (error.name === 'HttpError' &&
|
||||
error.status === 403 &&
|
||||
error.message.toLowerCase().includes('unauthorized')) {
|
||||
throw new Error(`Failed to set labels for PR #${pullRequest.number}. The workflow does not have permission to create labels. ` +
|
||||
`Ensure the 'issues: write' permission is granted in the workflow file or manually create the missing labels in the repository before running the action.`);
|
||||
}
|
||||
else if (error.name !== 'HttpError' ||
|
||||
error.message !== 'Resource not accessible by integration') {
|
||||
throw error;
|
||||
}
|
||||
core.warning(`The action requires write permission to add labels to pull requests. For more information please refer to the action documentation: https://github.com/actions/labeler#recommended-permissions`, {
|
||||
core.warning(`The action requires 'issues: write' permission to create new labels or 'pull-requests: write' permission to add existing labels to pull requests. ` +
|
||||
`For more information, refer to the action documentation: https://github.com/actions/labeler#recommended-permissions`, {
|
||||
title: `${process.env['GITHUB_ACTION_REPOSITORY']} running under '${github.context.eventName}' is misconfigured`
|
||||
});
|
||||
core.setFailed(error.message);
|
||||
|
||||
Reference in New Issue
Block a user