Skip to content

Commit 24ca77b

Browse files
author
Lucas Bento
committed
Correctly log issues when applying labels
1 parent b194bbd commit 24ca77b

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
2-
node_modules
2+
node_modules
3+
.idea

dist/index.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11915,16 +11915,10 @@ const getLabelToBeApplied = (version) =>
1191511915
const getIsIssueLabelAVersion = (label) => label.startsWith(versionLabel);
1191611916

1191711917
(async () => {
11918-
const githubToken = process.env.GITHUB_TOKEN || core.getInput("github-token", { required: true });
11918+
const githubToken = core.getInput("github-token", { required: true });
1191911919
const octokit = github.getOctokit(githubToken);
1192011920

11921-
// const { issue } = github.context;
11922-
11923-
const issue = {
11924-
owner: "lucasbento",
11925-
repo: "test-issue-forms",
11926-
number: 4
11927-
}
11921+
const { issue } = github.context;
1192811922

1192911923
// This fetches the issue again as it can have different data after running the other actions
1193011924
const { data: updatedIssue } = await octokit.rest.issues.get({
@@ -11952,8 +11946,8 @@ const getIsIssueLabelAVersion = (label) => label.startsWith(versionLabel);
1195211946

1195311947
// Loop through all labels and remove the version label if it exists
1195411948
// and is not the same as the version from the issue body
11955-
await Promise.all(
11956-
labels.map(({ name }) => {
11949+
try {
11950+
await Promise.all(labels.map(({ name }) => {
1195711951
const isLabelAVersion = getIsIssueLabelAVersion(name);
1195811952

1195911953
if (!isLabelAVersion || name === labelToBeApplied) {
@@ -11966,9 +11960,13 @@ const getIsIssueLabelAVersion = (label) => label.startsWith(versionLabel);
1196611960
issue_number: issue.number,
1196711961
name,
1196811962
});
11969-
})
11970-
);
11971-
console.log("LABEL", labelToBeApplied)
11963+
}));
11964+
} catch (error) {
11965+
core.error(error);
11966+
11967+
core.setFailed("Failed to remove version labels")
11968+
}
11969+
1197211970
try {
1197311971
// Make sure that the label to be added exists
1197411972
await octokit.rest.issues.getLabel({
@@ -11984,9 +11982,10 @@ console.log("LABEL", labelToBeApplied)
1198411982
issue_number: issue.number,
1198511983
labels: [labelToBeApplied],
1198611984
});
11987-
} catch (_error) {
11988-
// Label does not exist, log it and move on
11989-
core.debug(`Label ${versionAsIssueLabel} does not exist`);
11985+
} catch (error) {
11986+
core.error(error);
11987+
11988+
core.setFailed(`Label ${labelToBeApplied} doesn't seem to exist`)
1199011989
}
1199111990
})();
1199211991

index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ const getIsIssueLabelAVersion = (label) => label.startsWith(versionLabel);
109109

110110
// Loop through all labels and remove the version label if it exists
111111
// and is not the same as the version from the issue body
112-
await Promise.all(
113-
labels.map(({ name }) => {
112+
try {
113+
await Promise.all(labels.map(({ name }) => {
114114
const isLabelAVersion = getIsIssueLabelAVersion(name);
115115

116116
if (!isLabelAVersion || name === labelToBeApplied) {
@@ -123,8 +123,12 @@ const getIsIssueLabelAVersion = (label) => label.startsWith(versionLabel);
123123
issue_number: issue.number,
124124
name,
125125
});
126-
})
127-
);
126+
}));
127+
} catch (error) {
128+
core.error(error);
129+
130+
core.setFailed("Failed to remove version labels")
131+
}
128132

129133
try {
130134
// Make sure that the label to be added exists
@@ -141,8 +145,9 @@ const getIsIssueLabelAVersion = (label) => label.startsWith(versionLabel);
141145
issue_number: issue.number,
142146
labels: [labelToBeApplied],
143147
});
144-
} catch (_error) {
145-
// Label does not exist, log it and move on
146-
core.debug(`Label ${versionAsIssueLabel} does not exist`);
148+
} catch (error) {
149+
core.error(error);
150+
151+
core.setFailed(`Label ${labelToBeApplied} doesn't seem to exist`)
147152
}
148153
})();

0 commit comments

Comments
 (0)