Skip to content

Commit

Permalink
feat: cleanup procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
Firgrep committed Sep 18, 2024
1 parent 97458dc commit bc7aeb8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ app.post("/gh", (req: Request, res: Response) => {
console.info(`PR #${prNumber} is ready for action!`);
}

checkoutRepoPR(repo, ref);
runPrettier();
commitAndPushChanges();
try {
checkoutRepoPR(repo, ref);
runPrettier();
commitAndPushChanges();
} catch (error) {
console.error("Failed to process PR:", error);
} finally {
deleteRepo(repo);
}
// todo add cleanup
}

Expand All @@ -72,6 +78,15 @@ app.listen(port, () => {
console.info(`Server is running on http://localhost:${port}`);
});

function deleteRepo(repo: string) {
try {
execSync(`rm -rf ${repo}`, { stdio: "inherit" });
console.info(`Deleted repo ${repo}`);
} catch (error) {
console.error(`Failed to delete repo ${repo}:`, error);
}
}

function checkoutRepoPR(repo: string, ref: string) {
try {
// Checkout the pull request
Expand Down

0 comments on commit bc7aeb8

Please sign in to comment.