Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain misconfigured workflow #405

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,25 @@ function run() {
labelsToRemove.push(label);
}
}
if (labels.length > 0) {
yield addLabels(client, prNumber, labels);
try {
if (labels.length > 0) {
yield addLabels(client, prNumber, labels);
}
if (syncLabels && labelsToRemove.length) {
yield removeLabels(client, prNumber, labelsToRemove);
}
}
if (syncLabels && labelsToRemove.length) {
yield removeLabels(client, prNumber, labelsToRemove);
catch (error) {
if (error.name === 'HttpError' &&
error.message === 'Resource not accessible by integration') {
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#permissions`, {
title: `${process.env['GITHUB_ACTION_REPOSITORY']} running under '${github.context.eventName}' is misconfigured`
});
core.setFailed(error.message);
}
else {
throw error;
}
}
}
catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "labeler",
"version": "4.0.1",
"version": "4.1.0",
"description": "Labels pull requests by files altered",
"main": "lib/main.js",
"scripts": {
Expand Down
27 changes: 22 additions & 5 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,29 @@ export async function run() {
}
}

if (labels.length > 0) {
await addLabels(client, prNumber, labels);
}
try {
if (labels.length > 0) {
await addLabels(client, prNumber, labels);
}

if (syncLabels && labelsToRemove.length) {
await removeLabels(client, prNumber, labelsToRemove);
if (syncLabels && labelsToRemove.length) {
await removeLabels(client, prNumber, labelsToRemove);
}
} catch (error: any) {
if (
error.name === 'HttpError' &&
error.message === 'Resource not accessible by integration'
) {
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#permissions`,
{
title: `${process.env['GITHUB_ACTION_REPOSITORY']} running under '${github.context.eventName}' is misconfigured`
}
);
core.setFailed(error.message);
} else {
throw error;
}
}
} catch (error: any) {
core.error(error);
Expand Down