From c116c20c11380fe2ba397af258662232fcac5d37 Mon Sep 17 00:00:00 2001 From: Sebass van Boxel Date: Sun, 11 Oct 2020 19:29:41 +0200 Subject: [PATCH] Add support for deleting previously created comments --- action.yml | 2 ++ lib/main.js | 9 ++++++++- src/main.ts | 9 ++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 27ab183..16754ea 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,8 @@ inputs: number: description: "pull request number for push event" required: false + delete: + description: "delete the previously created comment" GITHUB_TOKEN: description: "set secrets.GITHUB_TOKEN here" required: true diff --git a/lib/main.js b/lib/main.js index 33d7274..d359b95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -48,12 +48,16 @@ function run() { const header = core.getInput("header", { required: false }) || ""; const append = core.getInput("append", { required: false }) || false; const recreate = core.getInput("recreate", { required: false }) || false; + const deleteOldComment = core.getInput("delete", { required: false }) || false; const githubToken = core.getInput("GITHUB_TOKEN", { required: true }); const octokit = new github_1.GitHub(githubToken); const previous = yield comment_1.findPreviousComment(octokit, repo, number, header); if (!message && !path) { throw { message: 'Either message or path input is required' }; } + if (deleteOldComment && recreate) { + throw { message: 'delete and recreate cannot be both set to true' }; + } let body; if (path) { body = fs_1.readFileSync(path); @@ -63,7 +67,10 @@ function run() { } if (previous) { const previousBody = append && previous.body; - if (recreate) { + if (deleteOldComment) { + yield comment_1.deleteComment(octokit, repo, previous.id); + } + else if (recreate) { yield comment_1.deleteComment(octokit, repo, previous.id); yield comment_1.createComment(octokit, repo, number, body, header, previousBody); } diff --git a/src/main.ts b/src/main.ts index 5a82f92..d254c3f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,6 +19,7 @@ async function run() { const header = core.getInput("header", { required: false }) || ""; const append = core.getInput("append", { required: false }) || false; const recreate = core.getInput("recreate", { required: false }) || false; + const deleteOldComment = core.getInput("delete", { required: false }) || false; const githubToken = core.getInput("GITHUB_TOKEN", { required: true }); const octokit = new GitHub(githubToken); const previous = await findPreviousComment(octokit, repo, number, header); @@ -27,6 +28,10 @@ async function run() { throw { message: 'Either message or path input is required' }; } + if (deleteOldComment && recreate) { + throw { message: 'delete and recreate cannot be both set to true' }; + } + let body; if (path) { @@ -37,7 +42,9 @@ async function run() { if (previous) { const previousBody = append && previous.body; - if (recreate) { + if (deleteOldComment) { + await deleteComment(octokit, repo, previous.id); + } else if (recreate) { await deleteComment(octokit, repo, previous.id); await createComment(octokit, repo, number, body, header, previousBody); } else {