mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-16 11:05:44 +00:00
fix: add rootDir and types to tsconfig.json to resolve TS5011 build error
Agent-Logs-Url: https://github.com/marocchino/sticky-pull-request-comment/sessions/c726777d-ddec-4ced-8af3-0bafb048ce2f Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
This commit is contained in:
parent
6ef1707d4b
commit
c4fbe28317
9 changed files with 546 additions and 0 deletions
117
dist/comment.js
generated
vendored
Normal file
117
dist/comment.js
generated
vendored
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
import * as core from "@actions/core";
|
||||
function headerComment(header) {
|
||||
return `<!-- Sticky Pull Request Comment${header} -->`;
|
||||
}
|
||||
function bodyWithHeader(body, header) {
|
||||
return `${body}\n${headerComment(header)}`;
|
||||
}
|
||||
function bodyWithoutHeader(body, header) {
|
||||
return body.replace(`\n${headerComment(header)}`, "");
|
||||
}
|
||||
export async function findPreviousComment(octokit, repo, number, header) {
|
||||
let after = null;
|
||||
let hasNextPage = true;
|
||||
const h = headerComment(header);
|
||||
while (hasNextPage) {
|
||||
const data = await octokit.graphql(`
|
||||
query($repo: String! $owner: String! $number: Int! $after: String) {
|
||||
viewer { login }
|
||||
repository(name: $repo owner: $owner) {
|
||||
pullRequest(number: $number) {
|
||||
comments(first: 100 after: $after) {
|
||||
nodes {
|
||||
id
|
||||
author {
|
||||
login
|
||||
}
|
||||
isMinimized
|
||||
body
|
||||
}
|
||||
pageInfo {
|
||||
endCursor
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`, { ...repo, after, number });
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||
const viewer = data.viewer;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||
const repository = data.repository;
|
||||
const target = repository.pullRequest?.comments?.nodes?.find((node) => node?.author?.login === viewer.login.replace("[bot]", "") &&
|
||||
!node?.isMinimized &&
|
||||
node?.body?.includes(h));
|
||||
if (target) {
|
||||
return target;
|
||||
}
|
||||
after = repository.pullRequest?.comments?.pageInfo?.endCursor;
|
||||
hasNextPage = repository.pullRequest?.comments?.pageInfo?.hasNextPage ?? false;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
export async function updateComment(octokit, id, body, header, previousBody) {
|
||||
if (!body && !previousBody)
|
||||
return core.warning("Comment body cannot be blank");
|
||||
const rawPreviousBody = previousBody ? bodyWithoutHeader(previousBody, header) : "";
|
||||
await octokit.graphql(`
|
||||
mutation($input: UpdateIssueCommentInput!) {
|
||||
updateIssueComment(input: $input) {
|
||||
issueComment {
|
||||
id
|
||||
body
|
||||
}
|
||||
}
|
||||
}
|
||||
`, {
|
||||
input: {
|
||||
id,
|
||||
body: previousBody
|
||||
? bodyWithHeader(`${rawPreviousBody}\n${body}`, header)
|
||||
: bodyWithHeader(body, header),
|
||||
},
|
||||
});
|
||||
}
|
||||
export async function createComment(octokit, repo, issue_number, body, header, previousBody) {
|
||||
if (!body && !previousBody) {
|
||||
core.warning("Comment body cannot be blank");
|
||||
return;
|
||||
}
|
||||
return await octokit.rest.issues.createComment({
|
||||
...repo,
|
||||
issue_number,
|
||||
body: previousBody ? `${previousBody}\n${body}` : bodyWithHeader(body, header),
|
||||
});
|
||||
}
|
||||
export async function deleteComment(octokit, id) {
|
||||
await octokit.graphql(`
|
||||
mutation($id: ID!) {
|
||||
deleteIssueComment(input: { id: $id }) {
|
||||
clientMutationId
|
||||
}
|
||||
}
|
||||
`, { id });
|
||||
}
|
||||
export async function minimizeComment(octokit, subjectId, classifier) {
|
||||
await octokit.graphql(`
|
||||
mutation($input: MinimizeCommentInput!) {
|
||||
minimizeComment(input: $input) {
|
||||
clientMutationId
|
||||
}
|
||||
}
|
||||
`, { input: { subjectId, classifier } });
|
||||
}
|
||||
export function getBodyOf(previous, append, hideDetails) {
|
||||
if (!append) {
|
||||
return undefined;
|
||||
}
|
||||
if (!hideDetails || !previous.body) {
|
||||
return previous.body;
|
||||
}
|
||||
return previous.body.replace(/(<details.*?)\s*\bopen\b(.*>)/g, "$1$2");
|
||||
}
|
||||
export function commentsEqual(body, previous, header) {
|
||||
const newBody = bodyWithHeader(body, header);
|
||||
return newBody === previous;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue