Skip to content

Commit

Permalink
going back to this format
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorFries committed Nov 8, 2024
1 parent c079e89 commit 934fc6f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
33 changes: 29 additions & 4 deletions .github/helpers/github-api/update-issue-and-comment.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const findIssueNumberByTitle = async (issueTitle) => {
return null;
};

export async function closeAndCreateIssue(issueTitle, issueBody) {
const closeAndCreateIssue = async (issueTitle, issueBody) => {
// try to get number of old issue
const issueNumber = await findIssueNumberByTitle(issueTitle);

Expand Down Expand Up @@ -114,9 +114,9 @@ export async function closeAndCreateIssue(issueTitle, issueBody) {

// return new issue number
return newIssue.body.number;
}
};

export async function createAndCloseComment(issueNumber, issueComment) {
const createAndCloseComment = async (issueNumber, issueComment) => {
// Add comment to Issue.
const newComment = await addComment(
issueNumber,
Expand Down Expand Up @@ -145,4 +145,29 @@ export async function createAndCloseComment(issueNumber, issueComment) {
}
// all good if we make it here.
return SUCCESS;
}
};

export const updateIssueAndComment = async (
issueTitle,
issueBody,
issueComment,
) => {
// Await the completion of create and close existing issue.
const newIssueNumber = await closeAndCreateIssue(issueTitle, issueBody);
// if we dont get a number back we hit an error somewhere.
if (Number.isNaN(Number(newIssueNumber))) {
throw new Error("Unexpected response: ", newIssueNumber, "\nQuitting.");
}

// Await the completion of create and close comment
const commentRes = await createAndCloseComment(
Number(newIssueNumber),
issueComment,
);
if (Number.isNaN(Number(commentRes))) {
// if we dont get a number back we hit an error at some point.
throw new Error("Unexpected response: ", commentRes, "\nQuitting.");
}
};

export default updateIssueAndComment;
28 changes: 4 additions & 24 deletions .github/helpers/npm-deps/create-report-issues.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const packageJsonPaths = JSON.parse(process.env.packageJsonPaths);
const commentIn = JSON.parse(process.env.commentContents);

(async () => {
const module = await import("../github-api/update-issue-and-comment.mjs");
const updateIssueAndComment = module.default;
// Create an array of promises for each packageJsonPath.
const promises = packageJsonPaths.map(async (packagePath) => {
// get the comment for this folder
Expand All @@ -24,32 +26,10 @@ const commentIn = JSON.parse(process.env.commentContents);
packagePath !== "."
? `${packagePath} NPM Dependency Report`
: "NPM Dependency Report";
// Await the completion of create and close existing issue.
const newIssueNumber = await updateIssueAndComment.closeAndCreateIssue(
issueTitle,
outputText[packagePath],
);
// if we dont get a number back we hit an error somewhere.
if (Number.isNaN(Number(newIssueNumber))) {
throw error("Unexpected response: ", newIssueNumber, "\nQuitting.");
}

// Await the completion of create and close comment
const commentRes = await updateIssueAndComment.createAndCloseComment(
Number(newIssueNumber),
comment,
);
if (Number.isNaN(Number(commentRes))) {
// if we dont get a number back we hit an error at some point.
throw error("Unexpected response: ", commentRes, "\nQuitting.");
}
await updateIssueAndComment(issueTitle, outputText[packagePath], comment);
});

// Wait for all issues to be created.
try {
await Promise.all(promises);
} catch (e) {
console.error("END WITH ERROR:\n ", e);
exit();
}
await Promise.all(promises);
})();

0 comments on commit 934fc6f

Please sign in to comment.