🔧 Update ts config

This commit is contained in:
marocchino 2025-04-09 21:56:19 +09:00
parent 67d0dec7b0
commit 0dbe58c83e
No known key found for this signature in database
GPG key ID: F54107506CCF18D0
5 changed files with 160 additions and 189 deletions

316
dist/index.js generated vendored
View file

@ -39,15 +39,6 @@ var __importStar = (this && this.__importStar) || (function () {
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.findPreviousComment = findPreviousComment;
exports.updateComment = updateComment;
@ -66,14 +57,12 @@ function bodyWithHeader(body, header) {
function bodyWithoutHeader(body, header) {
return body.replace(`\n${headerComment(header)}`, "");
}
function findPreviousComment(octokit, repo, number, header) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
let after = null;
let hasNextPage = true;
const h = headerComment(header);
while (hasNextPage) {
const data = yield octokit.graphql(`
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) {
@ -95,32 +84,27 @@ function findPreviousComment(octokit, repo, number, header) {
}
}
}
`, Object.assign(Object.assign({}, 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 = (_c = (_b = (_a = repository.pullRequest) === null || _a === void 0 ? void 0 : _a.comments) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.find((node) => {
var _a, _b;
return ((_a = node === null || node === void 0 ? void 0 : node.author) === null || _a === void 0 ? void 0 : _a.login) === viewer.login.replace("[bot]", "") &&
!(node === null || node === void 0 ? void 0 : node.isMinimized) &&
((_b = node === null || node === void 0 ? void 0 : node.body) === null || _b === void 0 ? void 0 : _b.includes(h));
});
if (target) {
return target;
}
after = (_f = (_e = (_d = repository.pullRequest) === null || _d === void 0 ? void 0 : _d.comments) === null || _e === void 0 ? void 0 : _e.pageInfo) === null || _f === void 0 ? void 0 : _f.endCursor;
hasNextPage = (_k = (_j = (_h = (_g = repository.pullRequest) === null || _g === void 0 ? void 0 : _g.comments) === null || _h === void 0 ? void 0 : _h.pageInfo) === null || _j === void 0 ? void 0 : _j.hasNextPage) !== null && _k !== void 0 ? _k : false;
`, { ...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;
}
return undefined;
});
after = repository.pullRequest?.comments?.pageInfo?.endCursor;
hasNextPage = repository.pullRequest?.comments?.pageInfo?.hasNextPage ?? false;
}
return undefined;
}
function updateComment(octokit, id, body, header, previousBody) {
return __awaiter(this, void 0, void 0, function* () {
if (!body && !previousBody)
return core.warning("Comment body cannot be blank");
const rawPreviousBody = previousBody ? bodyWithoutHeader(previousBody, header) : "";
yield octokit.graphql(`
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 {
@ -130,45 +114,42 @@ function updateComment(octokit, id, body, header, previousBody) {
}
}
`, {
input: {
id,
body: previousBody
? bodyWithHeader(`${rawPreviousBody}\n${body}`, header)
: bodyWithHeader(body, header)
}
});
});
}
function createComment(octokit, repo, issue_number, body, header, previousBody) {
return __awaiter(this, void 0, void 0, function* () {
if (!body && !previousBody) {
core.warning("Comment body cannot be blank");
return;
input: {
id,
body: previousBody
? bodyWithHeader(`${rawPreviousBody}\n${body}`, header)
: bodyWithHeader(body, header)
}
return yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: previousBody ? `${previousBody}\n${body}` : bodyWithHeader(body, header) }));
});
}
function deleteComment(octokit, id) {
return __awaiter(this, void 0, void 0, function* () {
yield octokit.graphql(`
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)
});
}
async function deleteComment(octokit, id) {
await octokit.graphql(`
mutation($id: ID!) {
deleteIssueComment(input: { id: $id }) {
clientMutationId
}
}
`, { id });
});
}
function minimizeComment(octokit, subjectId, classifier) {
return __awaiter(this, void 0, void 0, function* () {
yield octokit.graphql(`
async function minimizeComment(octokit, subjectId, classifier) {
await octokit.graphql(`
mutation($input: MinimizeCommentInput!) {
minimizeComment(input: $input) {
clientMutationId
}
}
`, { input: { subjectId, classifier } });
});
}
function getBodyOf(previous, append, hideDetails) {
if (!append) {
@ -225,16 +206,6 @@ var __importStar = (this && this.__importStar) || (function () {
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var _a, _b;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ignoreEmpty = exports.githubToken = exports.hideOldComment = exports.skipUnchanged = exports.onlyUpdateComment = exports.onlyCreateComment = exports.deleteOldComment = exports.hideClassify = exports.hideAndRecreate = exports.recreate = exports.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
exports.getBody = getBody;
@ -242,7 +213,7 @@ const node_fs_1 = __nccwpck_require__(3024);
const core = __importStar(__nccwpck_require__(7484));
const github_1 = __nccwpck_require__(3228);
const glob_1 = __nccwpck_require__(7206);
exports.pullRequestNumber = ((_b = (_a = github_1.context === null || github_1.context === void 0 ? void 0 : github_1.context.payload) === null || _a === void 0 ? void 0 : _a.pull_request) === null || _b === void 0 ? void 0 : _b.number) || +core.getInput("number", { required: false });
exports.pullRequestNumber = github_1.context?.payload?.pull_request?.number || +core.getInput("number", { required: false });
exports.repo = buildRepo();
exports.header = core.getInput("header", { required: false });
exports.append = core.getBooleanInput("append", { required: true });
@ -277,31 +248,29 @@ function buildRepo() {
repo: core.getInput("repo", { required: false }) || github_1.context.repo.repo
};
}
function getBody() {
return __awaiter(this, void 0, void 0, function* () {
const pathInput = core.getMultilineInput("path", { required: false });
const followSymbolicLinks = core.getBooleanInput("follow_symbolic_links", {
required: true
});
if (pathInput && pathInput.length > 0) {
try {
const globber = yield (0, glob_1.create)(pathInput.join("\n"), {
followSymbolicLinks,
matchDirectories: false
});
return (yield globber.glob()).map(path => (0, node_fs_1.readFileSync)(path, "utf-8")).join("\n");
}
catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
}
return "";
}
}
else {
return core.getInput("message", { required: false });
}
async function getBody() {
const pathInput = core.getMultilineInput("path", { required: false });
const followSymbolicLinks = core.getBooleanInput("follow_symbolic_links", {
required: true
});
if (pathInput && pathInput.length > 0) {
try {
const globber = await (0, glob_1.create)(pathInput.join("\n"), {
followSymbolicLinks,
matchDirectories: false
});
return (await globber.glob()).map(path => (0, node_fs_1.readFileSync)(path, "utf-8")).join("\n");
}
catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
}
return "";
}
}
else {
return core.getInput("message", { required: false });
}
}
@ -345,95 +314,84 @@ var __importStar = (this && this.__importStar) || (function () {
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(7484));
const github = __importStar(__nccwpck_require__(3228));
const comment_1 = __nccwpck_require__(9661);
const config_1 = __nccwpck_require__(6472);
function run() {
return __awaiter(this, void 0, void 0, function* () {
if (Number.isNaN(config_1.pullRequestNumber) || config_1.pullRequestNumber < 1) {
core.info("no pull request numbers given: skip step");
async function run() {
if (Number.isNaN(config_1.pullRequestNumber) || config_1.pullRequestNumber < 1) {
core.info("no pull request numbers given: skip step");
return;
}
try {
const body = await (0, config_1.getBody)();
if (!body && config_1.ignoreEmpty) {
core.info("no body given: skip step by ignoreEmpty");
return;
}
try {
const body = yield (0, config_1.getBody)();
if (!body && config_1.ignoreEmpty) {
core.info("no body given: skip step by ignoreEmpty");
return;
}
if (!config_1.deleteOldComment && !config_1.hideOldComment && !body) {
throw new Error("Either message or path input is required");
}
if (config_1.deleteOldComment && config_1.recreate) {
throw new Error("delete and recreate cannot be both set to true");
}
if (config_1.onlyCreateComment && config_1.onlyUpdateComment) {
throw new Error("only_create and only_update cannot be both set to true");
}
if (config_1.hideOldComment && config_1.hideAndRecreate) {
throw new Error("hide and hide_and_recreate cannot be both set to true");
}
const octokit = github.getOctokit(config_1.githubToken);
const previous = yield (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
core.setOutput("previous_comment_id", previous === null || previous === void 0 ? void 0 : previous.id);
if (config_1.deleteOldComment) {
if (previous) {
yield (0, comment_1.deleteComment)(octokit, previous.id);
}
return;
}
if (!previous) {
if (config_1.onlyUpdateComment) {
return;
}
const created = yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, body, config_1.header);
core.setOutput("created_comment_id", created === null || created === void 0 ? void 0 : created.data.id);
return;
}
if (config_1.onlyCreateComment) {
// don't comment anything, user specified only_create and there is an
// existing comment, so this is probably a placeholder / introduction one.
return;
}
if (config_1.hideOldComment) {
yield (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
return;
}
if (config_1.skipUnchanged && (0, comment_1.commentsEqual)(body, previous.body || "", config_1.header)) {
// don't recreate or update if the message is unchanged
return;
}
const previousBody = (0, comment_1.getBodyOf)({ body: previous.body || "" }, config_1.append, config_1.hideDetails);
if (config_1.recreate) {
yield (0, comment_1.deleteComment)(octokit, previous.id);
const created = yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, body, config_1.header, previousBody);
core.setOutput("created_comment_id", created === null || created === void 0 ? void 0 : created.data.id);
return;
}
if (config_1.hideAndRecreate) {
yield (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
const created = yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, body, config_1.header);
core.setOutput("created_comment_id", created === null || created === void 0 ? void 0 : created.data.id);
return;
}
yield (0, comment_1.updateComment)(octokit, previous.id, body, config_1.header, previousBody);
if (!config_1.deleteOldComment && !config_1.hideOldComment && !body) {
throw new Error("Either message or path input is required");
}
catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
}
if (config_1.deleteOldComment && config_1.recreate) {
throw new Error("delete and recreate cannot be both set to true");
}
});
if (config_1.onlyCreateComment && config_1.onlyUpdateComment) {
throw new Error("only_create and only_update cannot be both set to true");
}
if (config_1.hideOldComment && config_1.hideAndRecreate) {
throw new Error("hide and hide_and_recreate cannot be both set to true");
}
const octokit = github.getOctokit(config_1.githubToken);
const previous = await (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
core.setOutput("previous_comment_id", previous?.id);
if (config_1.deleteOldComment) {
if (previous) {
await (0, comment_1.deleteComment)(octokit, previous.id);
}
return;
}
if (!previous) {
if (config_1.onlyUpdateComment) {
return;
}
const created = await (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, body, config_1.header);
core.setOutput("created_comment_id", created?.data.id);
return;
}
if (config_1.onlyCreateComment) {
// don't comment anything, user specified only_create and there is an
// existing comment, so this is probably a placeholder / introduction one.
return;
}
if (config_1.hideOldComment) {
await (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
return;
}
if (config_1.skipUnchanged && (0, comment_1.commentsEqual)(body, previous.body || "", config_1.header)) {
// don't recreate or update if the message is unchanged
return;
}
const previousBody = (0, comment_1.getBodyOf)({ body: previous.body || "" }, config_1.append, config_1.hideDetails);
if (config_1.recreate) {
await (0, comment_1.deleteComment)(octokit, previous.id);
const created = await (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, body, config_1.header, previousBody);
core.setOutput("created_comment_id", created?.data.id);
return;
}
if (config_1.hideAndRecreate) {
await (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
const created = await (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, body, config_1.header);
core.setOutput("created_comment_id", created?.data.id);
return;
}
await (0, comment_1.updateComment)(octokit, previous.id, body, config_1.header, previousBody);
}
catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
}
}
}
run();

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -5,7 +5,7 @@ import type {
ReportedContentClassifiers,
Repository,
User
} from "@octokit/graphql-schema/schema.d"
} from "@octokit/graphql-schema"
type CreateCommentResponse = Awaited<
ReturnType<InstanceType<typeof GitHub>["rest"]["issues"]["createComment"]>

View file

@ -2,7 +2,7 @@ import {readFileSync} from "node:fs"
import * as core from "@actions/core"
import {context} from "@actions/github"
import {create} from "@actions/glob"
import type {ReportedContentClassifiers} from "@octokit/graphql-schema/schema.d"
import type {ReportedContentClassifiers} from "@octokit/graphql-schema"
export const pullRequestNumber =
context?.payload?.pull_request?.number || +core.getInput("number", {required: false})

View file

@ -1,12 +1,25 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"allowSyntheticDefaultImports": true,
"declaration": false,
"declarationMap": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["ES2022"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"newLine": "lf",
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
"pretty": true,
"resolveJsonModule": true,
"strict": true,
"strictNullChecks": true,
"target": "ES2022",
"outDir": "./lib",
"rootDir": "./src"
},
"exclude": ["node_modules", "**/*.test.ts"]
}