mirror of
https://github.com/actions/labeler.git
synced 2026-01-18 11:41:00 +08: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:
@@ -22,7 +22,7 @@ export const run = () =>
|
||||
core.setFailed(error.message);
|
||||
});
|
||||
|
||||
async function labeler() {
|
||||
export async function labeler() {
|
||||
const {token, configPath, syncLabels, dot, prNumbers} = getInputs();
|
||||
|
||||
if (!prNumbers.length) {
|
||||
@@ -65,6 +65,15 @@ async function labeler() {
|
||||
}
|
||||
} catch (error: any) {
|
||||
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'
|
||||
) {
|
||||
@@ -72,7 +81,8 @@ async function labeler() {
|
||||
}
|
||||
|
||||
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`,
|
||||
`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`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user