Skip to content

Commit e24a3eb

Browse files
Support empty body and only remove existing labels (#62)
* replace null body to empty character * fixed: check body is undefined * Build project * Guard removal of label if label isn't set * Typo * Add some debug logging --------- Co-authored-by: stephanmiehe <[email protected]>
1 parent cd54a96 commit e24a3eb

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

lib/index.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

+24-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function run() {
2929
}
3030

3131
const issue_body = getIssueOrPRBody();
32-
if (!issue_body) {
32+
if (issue_body === undefined) {
3333
console.log("Could not get issue or PR body from context, exiting");
3434
return;
3535
}
@@ -48,6 +48,22 @@ async function run() {
4848
/** List of labels to remove */
4949
const toRemove: string[] = [];
5050

51+
const issue = await client.issues.get({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
issue_number,
55+
});
56+
57+
const labels: String[] = []
58+
issue.data.labels.forEach((label) => {
59+
if (typeof label === 'string') {
60+
} else {
61+
labels.push(<String>label.name);
62+
}
63+
});
64+
65+
debug(`Issue has the following labels #${labels}`);
66+
5167
if (enableVersionedRegex === 1) {
5268
const regexVersion = versionedRegex.exec(issue_body);
5369
if (!regexVersion || !regexVersion[1]) {
@@ -66,11 +82,6 @@ async function run() {
6682

6783
// If the notBefore parameter has been set to a valid timestamp, exit if the current issue was created before notBefore
6884
if (notBefore) {
69-
const issue = await client.issues.get({
70-
owner: context.repo.owner,
71-
repo: context.repo.repo,
72-
issue_number,
73-
});
7485
const issueCreatedAt = Date.parse(issue.data.created_at);
7586
if (issueCreatedAt < notBefore) {
7687
console.log(
@@ -91,7 +102,10 @@ async function run() {
91102
if (checkRegexes(issueContent, globs)) {
92103
toAdd.push(label);
93104
} else if (syncLabels === 1) {
94-
toRemove.push(label);
105+
if (labels.includes(label)) {
106+
debug(`Marking #${label} label for removal`);
107+
toRemove.push(label);
108+
}
95109
}
96110
}
97111

@@ -118,6 +132,9 @@ function getIssueOrPRNumber() {
118132

119133
function getIssueOrPRBody() {
120134
const { issue, pull_request } = context.payload;
135+
if (issue?.body === null || pull_request?.body === null) {
136+
return '';
137+
}
121138
return issue?.body ?? pull_request?.body;
122139
}
123140

0 commit comments

Comments
 (0)