update hidden identifier comment to come last instead of first

This commit is contained in:
Jake Hiller 2020-06-24 10:38:30 -04:00
parent 587f474c3a
commit 1ee5fc7fa0
2 changed files with 27 additions and 14 deletions

View file

@ -2,25 +2,31 @@ 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,
issue_number
});
const h = headerComment(header);
return comments.find(comment => comment.body.startsWith(h));
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: previousBody ? `${previousBody}\n${body}` : `${headerComment(header)}\n${body}`
body: `${updatedBody}\n${headerIdentifier}`
});
}
export async function createComment(octokit, repo, issue_number, body, header) {
await octokit.issues.createComment({
...repo,
issue_number,
body: `${headerComment(header)}\n${body}`
body: `${body}\n${headerComment(header)}`
});
}