Merge pull request #187 from SvanBoxel/master

Add support for deleting previously created comments
This commit is contained in:
marocchino 2020-10-12 08:25:09 +09:00 committed by GitHub
commit 061f72bd8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View file

@ -20,6 +20,8 @@ inputs:
number: number:
description: "pull request number for push event" description: "pull request number for push event"
required: false required: false
delete:
description: "delete the previously created comment"
GITHUB_TOKEN: GITHUB_TOKEN:
description: "set secrets.GITHUB_TOKEN here" description: "set secrets.GITHUB_TOKEN here"
required: true required: true

View file

@ -48,12 +48,16 @@ function run() {
const header = core.getInput("header", { required: false }) || ""; const header = core.getInput("header", { required: false }) || "";
const append = core.getInput("append", { required: false }) || false; const append = core.getInput("append", { required: false }) || false;
const recreate = core.getInput("recreate", { 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 githubToken = core.getInput("GITHUB_TOKEN", { required: true });
const octokit = new github_1.GitHub(githubToken); const octokit = new github_1.GitHub(githubToken);
const previous = yield comment_1.findPreviousComment(octokit, repo, number, header); const previous = yield comment_1.findPreviousComment(octokit, repo, number, header);
if (!message && !path) { if (!message && !path) {
throw { message: 'Either message or path input is required' }; 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; let body;
if (path) { if (path) {
body = fs_1.readFileSync(path); body = fs_1.readFileSync(path);
@ -63,7 +67,10 @@ function run() {
} }
if (previous) { if (previous) {
const previousBody = append && previous.body; 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.deleteComment(octokit, repo, previous.id);
yield comment_1.createComment(octokit, repo, number, body, header, previousBody); yield comment_1.createComment(octokit, repo, number, body, header, previousBody);
} }

View file

@ -19,6 +19,7 @@ async function run() {
const header = core.getInput("header", { required: false }) || ""; const header = core.getInput("header", { required: false }) || "";
const append = core.getInput("append", { required: false }) || false; const append = core.getInput("append", { required: false }) || false;
const recreate = core.getInput("recreate", { 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 githubToken = core.getInput("GITHUB_TOKEN", { required: true });
const octokit = new GitHub(githubToken); const octokit = new GitHub(githubToken);
const previous = await findPreviousComment(octokit, repo, number, header); const previous = await findPreviousComment(octokit, repo, number, header);
@ -27,6 +28,10 @@ async function run() {
throw { message: 'Either message or path input is required' }; 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; let body;
if (path) { if (path) {
@ -37,7 +42,9 @@ async function run() {
if (previous) { if (previous) {
const previousBody = append && previous.body; 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 deleteComment(octokit, repo, previous.id);
await createComment(octokit, repo, number, body, header, previousBody); await createComment(octokit, repo, number, body, header, previousBody);
} else { } else {