mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-17 05:28:28 +00:00
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import * as core from "@actions/core";
|
|
|
|
function headerComment(header) {
|
|
return `<!-- Sticky Pull Request Comment${header} -->`;
|
|
}
|
|
|
|
export async function findPreviousComment(octokit, repo, issue_number, header) {
|
|
const { data: comments } = await octokit.issues.listComments({
|
|
...repo,
|
|
issue_number
|
|
});
|
|
const h = headerComment(header);
|
|
return comments.find(comment => comment.body.includes(h));
|
|
}
|
|
export async function updateComment(octokit, repo, comment_id, body, header, previousBody?) {
|
|
if (!body && !previousBody) return core.warning('Comment body cannot be blank');
|
|
|
|
await octokit.issues.updateComment({
|
|
...repo,
|
|
comment_id,
|
|
body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}`
|
|
});
|
|
}
|
|
export async function createComment(octokit, repo, issue_number, body, header, previousBody?) {
|
|
if (!body && !previousBody) return core.warning('Comment body cannot be blank');
|
|
|
|
await octokit.issues.createComment({
|
|
...repo,
|
|
issue_number,
|
|
body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}`
|
|
});
|
|
}
|
|
export async function deleteComment(octokit, repo, comment_id) {
|
|
await octokit.issues.deleteComment({
|
|
...repo,
|
|
comment_id,
|
|
});
|
|
}
|