mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-16 21:18:27 +00:00
30 lines
925 B
TypeScript
30 lines
925 B
TypeScript
import * as core from "@actions/core";
|
|
import { context, GitHub } from "@actions/github";
|
|
import { findPreviousComment, createComment, updateComment } from "./comment";
|
|
|
|
async function run() {
|
|
const number =
|
|
context?.payload?.pull_request?.number ||
|
|
+core.getInput("number", { required: false });
|
|
if (isNaN(number) || number < 1) {
|
|
core.info("no numbers given: skip step");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const repo = context.repo;
|
|
const body = core.getInput("message", { required: true });
|
|
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
|
const octokit = new GitHub(githubToken);
|
|
const previous = await findPreviousComment(octokit, repo, number);
|
|
if (previous) {
|
|
await updateComment(octokit, repo, previous.id, body);
|
|
} else {
|
|
await createComment(octokit, repo, number, body);
|
|
}
|
|
} catch ({ message }) {
|
|
core.setFailed(message);
|
|
}
|
|
}
|
|
|
|
run();
|