Skip to content

Commit

Permalink
Support empty body and only remove existing labels (#62)
Browse files Browse the repository at this point in the history
* 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 <stephanmiehe@github.com>
  • Loading branch information
dokimiki and stephanmiehe authored Mar 26, 2023
1 parent cd54a96 commit e24a3eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/index.js

Large diffs are not rendered by default.

31 changes: 24 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function run() {
}

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

const issue = await client.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
});

const labels: String[] = []
issue.data.labels.forEach((label) => {
if (typeof label === 'string') {
} else {
labels.push(<String>label.name);
}
});

debug(`Issue has the following labels #${labels}`);

if (enableVersionedRegex === 1) {
const regexVersion = versionedRegex.exec(issue_body);
if (!regexVersion || !regexVersion[1]) {
Expand All @@ -66,11 +82,6 @@ async function run() {

// If the notBefore parameter has been set to a valid timestamp, exit if the current issue was created before notBefore
if (notBefore) {
const issue = await client.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
});
const issueCreatedAt = Date.parse(issue.data.created_at);
if (issueCreatedAt < notBefore) {
console.log(
Expand All @@ -91,7 +102,10 @@ async function run() {
if (checkRegexes(issueContent, globs)) {
toAdd.push(label);
} else if (syncLabels === 1) {
toRemove.push(label);
if (labels.includes(label)) {
debug(`Marking #${label} label for removal`);
toRemove.push(label);
}
}
}

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

function getIssueOrPRBody() {
const { issue, pull_request } = context.payload;
if (issue?.body === null || pull_request?.body === null) {
return '';
}
return issue?.body ?? pull_request?.body;
}

Expand Down

0 comments on commit e24a3eb

Please sign in to comment.