Skip to content

Commit b5ff161

Browse files
authored
Explain misconfigured workflow (#405)
Fixes #136
1 parent fe87e60 commit b5ff161

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

dist/index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,25 @@ function run() {
7676
labelsToRemove.push(label);
7777
}
7878
}
79-
if (labels.length > 0) {
80-
yield addLabels(client, prNumber, labels);
79+
try {
80+
if (labels.length > 0) {
81+
yield addLabels(client, prNumber, labels);
82+
}
83+
if (syncLabels && labelsToRemove.length) {
84+
yield removeLabels(client, prNumber, labelsToRemove);
85+
}
8186
}
82-
if (syncLabels && labelsToRemove.length) {
83-
yield removeLabels(client, prNumber, labelsToRemove);
87+
catch (error) {
88+
if (error.name === 'HttpError' &&
89+
error.message === 'Resource not accessible by integration') {
90+
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`, {
91+
title: `${process.env['GITHUB_ACTION_REPOSITORY']} running under '${github.context.eventName}' is misconfigured`
92+
});
93+
core.setFailed(error.message);
94+
}
95+
else {
96+
throw error;
97+
}
8498
}
8599
}
86100
catch (error) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "labeler",
3-
"version": "4.0.1",
3+
"version": "4.1.0",
44
"description": "Labels pull requests by files altered",
55
"main": "lib/main.js",
66
"scripts": {

src/labeler.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,29 @@ export async function run() {
5050
}
5151
}
5252

53-
if (labels.length > 0) {
54-
await addLabels(client, prNumber, labels);
55-
}
53+
try {
54+
if (labels.length > 0) {
55+
await addLabels(client, prNumber, labels);
56+
}
5657

57-
if (syncLabels && labelsToRemove.length) {
58-
await removeLabels(client, prNumber, labelsToRemove);
58+
if (syncLabels && labelsToRemove.length) {
59+
await removeLabels(client, prNumber, labelsToRemove);
60+
}
61+
} catch (error: any) {
62+
if (
63+
error.name === 'HttpError' &&
64+
error.message === 'Resource not accessible by integration'
65+
) {
66+
core.warning(
67+
`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`,
68+
{
69+
title: `${process.env['GITHUB_ACTION_REPOSITORY']} running under '${github.context.eventName}' is misconfigured`
70+
}
71+
);
72+
core.setFailed(error.message);
73+
} else {
74+
throw error;
75+
}
5976
}
6077
} catch (error: any) {
6178
core.error(error);

0 commit comments

Comments
 (0)