mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-11 08:50:04 +00:00
feat: add ability to set custom header
This commit is contained in:
parent
ee22346016
commit
c873eaf14f
4 changed files with 56 additions and 18 deletions
|
|
@ -1,23 +1,26 @@
|
|||
const HEADER = "<!-- Sticky Pull Request Comment -->";
|
||||
|
||||
export async function findPreviousComment(octokit, repo, issue_number) {
|
||||
export async function findPreviousComment(octokit, repo, issue_number, header) {
|
||||
const { data: comments } = await octokit.issues.listComments({
|
||||
...repo,
|
||||
issue_number
|
||||
});
|
||||
return comments.find(comment => comment.body.startsWith(HEADER));
|
||||
const h = headerComment(header);
|
||||
return comments.find(comment => comment.body.startsWith(h));
|
||||
}
|
||||
export async function updateComment(octokit, repo, comment_id, body) {
|
||||
export async function updateComment(octokit, repo, comment_id, body, header) {
|
||||
await octokit.issues.updateComment({
|
||||
...repo,
|
||||
comment_id,
|
||||
body: `${HEADER}\n${body}`
|
||||
body: `${headerComment(header)}\n${body}`
|
||||
});
|
||||
}
|
||||
export async function createComment(octokit, repo, issue_number, body) {
|
||||
export async function createComment(octokit, repo, issue_number, body, header) {
|
||||
await octokit.issues.createComment({
|
||||
...repo,
|
||||
issue_number,
|
||||
body: `${HEADER}\n${body}`
|
||||
body: `${headerComment(header)}\n${body}`
|
||||
});
|
||||
}
|
||||
|
||||
function headerComment(header) {
|
||||
return `<!-- Sticky Pull Request Comment${header} -->`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,14 @@ async function run() {
|
|||
try {
|
||||
const repo = context.repo;
|
||||
const body = core.getInput("message", { required: true });
|
||||
const header = core.getInput("header", { required: false }) || "";
|
||||
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||
const octokit = new GitHub(githubToken);
|
||||
const previous = await findPreviousComment(octokit, repo, number);
|
||||
const previous = await findPreviousComment(octokit, repo, number, header);
|
||||
if (previous) {
|
||||
await updateComment(octokit, repo, previous.id, body);
|
||||
await updateComment(octokit, repo, previous.id, body, header);
|
||||
} else {
|
||||
await createComment(octokit, repo, number, body);
|
||||
await createComment(octokit, repo, number, body, header);
|
||||
}
|
||||
} catch ({ message }) {
|
||||
core.setFailed(message);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue