.github/helpers/github-api/create-and-close-existing-issue.js
const { createIssue, closeIssue, findIssueByTitle } = require('./github-api-requests');
const { ISSUE_TITLE, ISSUE_BODY } = process.env;
(async () => {
// Check for existing Issue.
const existingIssueNumber = await findIssueByTitle(ISSUE_TITLE);
if (existingIssueNumber && !Number.isNaN(Number(existingIssueNumber))) {
// Close old Issue.
await closeIssue(Number(existingIssueNumber));
}
// Create new Issue.
await createIssue(ISSUE_TITLE, decodeURIComponent(ISSUE_BODY));
})();