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

Support empty body and only remove existing labels #62

Merged
merged 6 commits into from
Mar 26, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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