simplify comment logic

This commit is contained in:
Jake Hiller 2020-06-25 01:25:52 -04:00
parent 2015926b3a
commit 7a2cc8a3dc

View file

@ -2,10 +2,6 @@ function headerComment(header) {
return `<!-- Sticky Pull Request Comment${header} -->`;
}
function removeHeaderComment(body, header) {
return body.replace(`\n${header}`, '');
}
export async function findPreviousComment(octokit, repo, issue_number, header) {
const { data: comments } = await octokit.issues.listComments({
...repo,
@ -15,12 +11,10 @@ export async function findPreviousComment(octokit, repo, issue_number, header) {
return comments.find(comment => comment.body.includes(h));
}
export async function updateComment(octokit, repo, comment_id, body, header, previousBody?) {
const headerIdentifier = headerComment(header);
const updatedBody = previousBody ? `${removeHeaderComment(previousBody, headerIdentifier)}\n${body}` : body;
await octokit.issues.updateComment({
...repo,
comment_id,
body: `${updatedBody}\n${headerIdentifier}`
body: previousBody ? `${previousBody}\n${body}` : `${body}\n${headerComment(header)}`
});
}
export async function createComment(octokit, repo, issue_number, body, header) {