mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-08 07:20:05 +00:00
feat: append to previous comment message
This commit is contained in:
parent
dd253e3148
commit
168a45153d
4 changed files with 19 additions and 3 deletions
|
|
@ -10,11 +10,11 @@ export async function findPreviousComment(octokit, repo, issue_number, header) {
|
|||
const h = headerComment(header);
|
||||
return comments.find(comment => comment.body.startsWith(h));
|
||||
}
|
||||
export async function updateComment(octokit, repo, comment_id, body, header) {
|
||||
export async function updateComment(octokit, repo, comment_id, body, header, previousBody?) {
|
||||
await octokit.issues.updateComment({
|
||||
...repo,
|
||||
comment_id,
|
||||
body: `${headerComment(header)}\n${body}`
|
||||
body: previousBody ? `${previousBody}\n${body}` : `${headerComment(header)}\n${body}`
|
||||
});
|
||||
}
|
||||
export async function createComment(octokit, repo, issue_number, body, header) {
|
||||
|
|
|
|||
|
|
@ -15,11 +15,16 @@ async function run() {
|
|||
const repo = context.repo;
|
||||
const body = core.getInput("message", { required: true });
|
||||
const header = core.getInput("header", { required: false }) || "";
|
||||
const append = core.getInput("append", { required: false }) || false;
|
||||
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||
const octokit = new GitHub(githubToken);
|
||||
const previous = await findPreviousComment(octokit, repo, number, header);
|
||||
if (previous) {
|
||||
await updateComment(octokit, repo, previous.id, body, header);
|
||||
if (append) {
|
||||
await updateComment(octokit, repo, previous.id, body, header, previous.body);
|
||||
} else {
|
||||
await updateComment(octokit, repo, previous.id, body, header);
|
||||
}
|
||||
} else {
|
||||
await createComment(octokit, repo, number, body, header);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue