Migrate to biome

This commit is contained in:
marocchino 2025-04-09 21:20:28 +09:00
parent e24be28b0d
commit cce8920b20
No known key found for this signature in database
GPG key ID: F54107506CCF18D0
15 changed files with 433 additions and 2243 deletions

View file

@ -1,4 +0,0 @@
dist/
lib/
node_modules/
jest.config.js

View file

@ -1,59 +0,0 @@
{
"root": true,
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"i18n-text/no-en": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{"accessibility": "no-public"}
],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-function-return-type": [
"error",
{"allowExpressions": true}
],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}

View file

@ -43,3 +43,7 @@ jobs:
hide_details: true
message: |
The build is over.
- name: Lint
run: npm run lint
- name: Format Check
run: npm run format-check

View file

@ -1,3 +0,0 @@
dist/
lib/
node_modules/

View file

@ -1,9 +0,0 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"
}

View file

@ -90,12 +90,8 @@ it("findPreviousComment", async () => {
} as any)
expect(await findPreviousComment(octokit, repo, 123, "")).toBe(comment)
expect(await findPreviousComment(octokit, repo, 123, "TypeA")).toBe(
commentWithCustomHeader
)
expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(
headerFirstComment
)
expect(await findPreviousComment(octokit, repo, 123, "TypeA")).toBe(commentWithCustomHeader)
expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(headerFirstComment)
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
after: null,
number: 123,
@ -112,18 +108,14 @@ describe("updateComment", () => {
})
it("with comment body", async () => {
expect(
await updateComment(octokit, "456", "hello there", "")
).toBeUndefined()
expect(await updateComment(octokit, "456", "hello there", "")).toBeUndefined()
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
input: {
id: "456",
body: "hello there\n<!-- Sticky Pull Request Comment -->"
}
})
expect(
await updateComment(octokit, "456", "hello there", "TypeA")
).toBeUndefined()
expect(await updateComment(octokit, "456", "hello there", "TypeA")).toBeUndefined()
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
input: {
id: "456",
@ -164,18 +156,16 @@ describe("createComment", () => {
})
it("with comment body or previousBody", async () => {
expect(await createComment(octokit, repo, 456, "hello there", "")).toEqual(
"<return value>"
)
expect(await createComment(octokit, repo, 456, "hello there", "")).toEqual("<return value>")
expect(octokit.rest.issues.createComment).toBeCalledWith({
issue_number: 456,
owner: "marocchino",
repo: "sticky-pull-request-comment",
body: "hello there\n<!-- Sticky Pull Request Comment -->"
})
expect(
await createComment(octokit, repo, 456, "hello there", "TypeA")
).toEqual("<return value>")
expect(await createComment(octokit, repo, 456, "hello there", "TypeA")).toEqual(
"<return value>"
)
expect(octokit.rest.issues.createComment).toBeCalledWith({
issue_number: 456,
owner: "marocchino",

View file

@ -250,9 +250,7 @@ describe("path", () => {
ignoreEmpty: false,
skipUnchanged: false
})
expect(await require("../src/config").getBody()).toEqual(
"hi there\n\nhey there\n"
)
expect(await require("../src/config").getBody()).toEqual("hi there\n\nhey there\n")
})
test("when not exists return null string", async () => {

105
biome.json Normal file
View file

@ -0,0 +1,105 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"files": {
"include": ["src/**/*.ts"],
"ignore": ["node_modules", "dist", "lib", "**/__tests__/**"]
},
"formatter": {
"enabled": true,
"useEditorconfig": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 100,
"attributePosition": "auto",
"bracketSpacing": true,
"ignore": ["**/dist/", "**/lib/", "**/node_modules/"]
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"noExtraBooleanCast": "error",
"noMultipleSpacesInRegularExpressionLiterals": "error",
"noStaticOnlyClass": "error",
"noUselessConstructor": "error",
"noUselessStringConcat": "error"
},
"correctness": {
"noConstAssign": "error",
"noConstantCondition": "error",
"noEmptyCharacterClassInRegex": "error",
"noEmptyPattern": "error",
"noGlobalObjectCalls": "error",
"noInnerDeclarations": "error",
"noInvalidConstructorSuper": "error",
"noNewSymbol": "error",
"noSelfAssign": "error",
"noSwitchDeclarations": "error",
"noUndeclaredVariables": "error",
"noUnreachable": "error",
"noUnreachableSuper": "error",
"noUnsafeFinally": "error",
"noUnusedLabels": "error",
"noUnusedVariables": "error",
"useIsNan": "error",
"useYield": "error"
},
"style": {
"noArguments": "error",
"noCommaOperator": "error",
"noInferrableTypes": "error",
"noNamespace": "error",
"noNonNullAssertion": "warn",
"noVar": "error",
"useConsistentArrayType": "error",
"useConst": "error",
"useForOf": "warn",
"useShorthandFunctionType": "warn",
"useSingleVarDeclarator": "error",
"useTemplate": "error"
},
"suspicious": {
"noCatchAssign": "error",
"noClassAssign": "error",
"noCompareNegZero": "error",
"noConsole": "error",
"noControlCharactersInRegex": "error",
"noDebugger": "error",
"noDoubleEquals": "error",
"noDuplicateCase": "error",
"noDuplicateClassMembers": "error",
"noDuplicateObjectKeys": "error",
"noDuplicateParameters": "error",
"noEmptyBlockStatements": "error",
"noExplicitAny": "warn",
"noFallthroughSwitchClause": "error",
"noFunctionAssign": "error",
"noGlobalAssign": "error",
"noMisleadingInstantiator": "error",
"noRedeclare": "error",
"noSparseArray": "error",
"noUnsafeNegation": "error",
"useValidTypeof": "error"
}
},
"ignore": ["**/dist/", "**/lib/", "**/node_modules/", "**/jest.config.js"]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "none",
"semicolons": "asNeeded",
"arrowParentheses": "asNeeded",
"bracketSameLine": false,
"quoteStyle": "double",
"attributePosition": "auto",
"bracketSpacing": false
},
"globals": ["jest"]
}
}

450
dist/index.js generated vendored
View file

@ -110,8 +110,7 @@ function findPreviousComment(octokit, repo, number, header) {
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;
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;
}
return undefined;
});
@ -120,9 +119,7 @@ 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)
: "";
const rawPreviousBody = previousBody ? bodyWithoutHeader(previousBody, header) : "";
yield octokit.graphql(`
mutation($input: UpdateIssueCommentInput!) {
updateIssueComment(input: $input) {
@ -148,9 +145,7 @@ function createComment(octokit, repo, issue_number, body, header, previousBody)
core.warning("Comment body cannot be blank");
return;
}
return yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: previousBody
? `${previousBody}\n${body}`
: 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) {
@ -243,12 +238,11 @@ 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;
const node_fs_1 = __nccwpck_require__(3024);
const core = __importStar(__nccwpck_require__(7484));
const github_1 = __nccwpck_require__(3228);
const fs_1 = __nccwpck_require__(9896);
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 = ((_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.repo = buildRepo();
exports.header = core.getInput("header", { required: false });
exports.append = core.getBooleanInput("append", { required: true });
@ -295,9 +289,7 @@ function getBody() {
followSymbolicLinks,
matchDirectories: false
});
return (yield globber.glob())
.map(path => (0, fs_1.readFileSync)(path, "utf-8"))
.join("\n");
return (yield globber.glob()).map((path) => (0, node_fs_1.readFileSync)(path, "utf-8")).join("\n");
}
catch (error) {
if (error instanceof Error) {
@ -365,11 +357,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(7484));
const github = __importStar(__nccwpck_require__(3228));
const config_1 = __nccwpck_require__(6472);
const comment_1 = __nccwpck_require__(9661);
const config_1 = __nccwpck_require__(6472);
function run() {
return __awaiter(this, void 0, void 0, function* () {
if (isNaN(config_1.pullRequestNumber) || config_1.pullRequestNumber < 1) {
if (Number.isNaN(config_1.pullRequestNumber) || config_1.pullRequestNumber < 1) {
core.info("no pull request numbers given: skip step");
return;
}
@ -10381,6 +10373,214 @@ function removeHook(state, name, method) {
}
/***/ }),
/***/ 4691:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
var concatMap = __nccwpck_require__(7087);
var balanced = __nccwpck_require__(9380);
module.exports = expandTop;
var escSlash = '\0SLASH'+Math.random()+'\0';
var escOpen = '\0OPEN'+Math.random()+'\0';
var escClose = '\0CLOSE'+Math.random()+'\0';
var escComma = '\0COMMA'+Math.random()+'\0';
var escPeriod = '\0PERIOD'+Math.random()+'\0';
function numeric(str) {
return parseInt(str, 10) == str
? parseInt(str, 10)
: str.charCodeAt(0);
}
function escapeBraces(str) {
return str.split('\\\\').join(escSlash)
.split('\\{').join(escOpen)
.split('\\}').join(escClose)
.split('\\,').join(escComma)
.split('\\.').join(escPeriod);
}
function unescapeBraces(str) {
return str.split(escSlash).join('\\')
.split(escOpen).join('{')
.split(escClose).join('}')
.split(escComma).join(',')
.split(escPeriod).join('.');
}
// Basically just str.split(","), but handling cases
// where we have nested braced sections, which should be
// treated as individual members, like {a,{b,c},d}
function parseCommaParts(str) {
if (!str)
return [''];
var parts = [];
var m = balanced('{', '}', str);
if (!m)
return str.split(',');
var pre = m.pre;
var body = m.body;
var post = m.post;
var p = pre.split(',');
p[p.length-1] += '{' + body + '}';
var postParts = parseCommaParts(post);
if (post.length) {
p[p.length-1] += postParts.shift();
p.push.apply(p, postParts);
}
parts.push.apply(parts, p);
return parts;
}
function expandTop(str) {
if (!str)
return [];
// I don't know why Bash 4.3 does this, but it does.
// Anything starting with {} will have the first two bytes preserved
// but *only* at the top level, so {},a}b will not expand to anything,
// but a{},b}c will be expanded to [a}c,abc].
// One could argue that this is a bug in Bash, but since the goal of
// this module is to match Bash's rules, we escape a leading {}
if (str.substr(0, 2) === '{}') {
str = '\\{\\}' + str.substr(2);
}
return expand(escapeBraces(str), true).map(unescapeBraces);
}
function identity(e) {
return e;
}
function embrace(str) {
return '{' + str + '}';
}
function isPadded(el) {
return /^-?0\d/.test(el);
}
function lte(i, y) {
return i <= y;
}
function gte(i, y) {
return i >= y;
}
function expand(str, isTop) {
var expansions = [];
var m = balanced('{', '}', str);
if (!m || /\$$/.test(m.pre)) return [str];
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
var isSequence = isNumericSequence || isAlphaSequence;
var isOptions = m.body.indexOf(',') >= 0;
if (!isSequence && !isOptions) {
// {a},b}
if (m.post.match(/,.*\}/)) {
str = m.pre + '{' + m.body + escClose + m.post;
return expand(str);
}
return [str];
}
var n;
if (isSequence) {
n = m.body.split(/\.\./);
} else {
n = parseCommaParts(m.body);
if (n.length === 1) {
// x{{a,b}}y ==> x{a}y x{b}y
n = expand(n[0], false).map(embrace);
if (n.length === 1) {
var post = m.post.length
? expand(m.post, false)
: [''];
return post.map(function(p) {
return m.pre + n[0] + p;
});
}
}
}
// at this point, n is the parts, and we know it's not a comma set
// with a single entry.
// no need to expand pre, since it is guaranteed to be free of brace-sets
var pre = m.pre;
var post = m.post.length
? expand(m.post, false)
: [''];
var N;
if (isSequence) {
var x = numeric(n[0]);
var y = numeric(n[1]);
var width = Math.max(n[0].length, n[1].length)
var incr = n.length == 3
? Math.abs(numeric(n[2]))
: 1;
var test = lte;
var reverse = y < x;
if (reverse) {
incr *= -1;
test = gte;
}
var pad = n.some(isPadded);
N = [];
for (var i = x; test(i, y); i += incr) {
var c;
if (isAlphaSequence) {
c = String.fromCharCode(i);
if (c === '\\')
c = '';
} else {
c = String(i);
if (pad) {
var need = width - c.length;
if (need > 0) {
var z = new Array(need + 1).join('0');
if (i < 0)
c = '-' + z + c.slice(1);
else
c = z + c;
}
}
}
N.push(c);
}
} else {
N = concatMap(n, function(el) { return expand(el, false) });
}
for (var j = 0; j < N.length; j++) {
for (var k = 0; k < post.length; k++) {
var expansion = pre + N[j] + post[k];
if (!isTop || isSequence || expansion)
expansions.push(expansion);
}
}
return expansions;
}
/***/ }),
/***/ 7087:
@ -10489,7 +10689,7 @@ var path = (function () { try { return __nccwpck_require__(6928) } catch (e) {}}
minimatch.sep = path.sep
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
var expand = __nccwpck_require__(3783)
var expand = __nccwpck_require__(4691)
var plTypes = {
'!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
@ -11429,214 +11629,6 @@ function regExpEscape (s) {
}
/***/ }),
/***/ 3783:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
var concatMap = __nccwpck_require__(7087);
var balanced = __nccwpck_require__(9380);
module.exports = expandTop;
var escSlash = '\0SLASH'+Math.random()+'\0';
var escOpen = '\0OPEN'+Math.random()+'\0';
var escClose = '\0CLOSE'+Math.random()+'\0';
var escComma = '\0COMMA'+Math.random()+'\0';
var escPeriod = '\0PERIOD'+Math.random()+'\0';
function numeric(str) {
return parseInt(str, 10) == str
? parseInt(str, 10)
: str.charCodeAt(0);
}
function escapeBraces(str) {
return str.split('\\\\').join(escSlash)
.split('\\{').join(escOpen)
.split('\\}').join(escClose)
.split('\\,').join(escComma)
.split('\\.').join(escPeriod);
}
function unescapeBraces(str) {
return str.split(escSlash).join('\\')
.split(escOpen).join('{')
.split(escClose).join('}')
.split(escComma).join(',')
.split(escPeriod).join('.');
}
// Basically just str.split(","), but handling cases
// where we have nested braced sections, which should be
// treated as individual members, like {a,{b,c},d}
function parseCommaParts(str) {
if (!str)
return [''];
var parts = [];
var m = balanced('{', '}', str);
if (!m)
return str.split(',');
var pre = m.pre;
var body = m.body;
var post = m.post;
var p = pre.split(',');
p[p.length-1] += '{' + body + '}';
var postParts = parseCommaParts(post);
if (post.length) {
p[p.length-1] += postParts.shift();
p.push.apply(p, postParts);
}
parts.push.apply(parts, p);
return parts;
}
function expandTop(str) {
if (!str)
return [];
// I don't know why Bash 4.3 does this, but it does.
// Anything starting with {} will have the first two bytes preserved
// but *only* at the top level, so {},a}b will not expand to anything,
// but a{},b}c will be expanded to [a}c,abc].
// One could argue that this is a bug in Bash, but since the goal of
// this module is to match Bash's rules, we escape a leading {}
if (str.substr(0, 2) === '{}') {
str = '\\{\\}' + str.substr(2);
}
return expand(escapeBraces(str), true).map(unescapeBraces);
}
function identity(e) {
return e;
}
function embrace(str) {
return '{' + str + '}';
}
function isPadded(el) {
return /^-?0\d/.test(el);
}
function lte(i, y) {
return i <= y;
}
function gte(i, y) {
return i >= y;
}
function expand(str, isTop) {
var expansions = [];
var m = balanced('{', '}', str);
if (!m || /\$$/.test(m.pre)) return [str];
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
var isSequence = isNumericSequence || isAlphaSequence;
var isOptions = m.body.indexOf(',') >= 0;
if (!isSequence && !isOptions) {
// {a},b}
if (m.post.match(/,.*\}/)) {
str = m.pre + '{' + m.body + escClose + m.post;
return expand(str);
}
return [str];
}
var n;
if (isSequence) {
n = m.body.split(/\.\./);
} else {
n = parseCommaParts(m.body);
if (n.length === 1) {
// x{{a,b}}y ==> x{a}y x{b}y
n = expand(n[0], false).map(embrace);
if (n.length === 1) {
var post = m.post.length
? expand(m.post, false)
: [''];
return post.map(function(p) {
return m.pre + n[0] + p;
});
}
}
}
// at this point, n is the parts, and we know it's not a comma set
// with a single entry.
// no need to expand pre, since it is guaranteed to be free of brace-sets
var pre = m.pre;
var post = m.post.length
? expand(m.post, false)
: [''];
var N;
if (isSequence) {
var x = numeric(n[0]);
var y = numeric(n[1]);
var width = Math.max(n[0].length, n[1].length)
var incr = n.length == 3
? Math.abs(numeric(n[2]))
: 1;
var test = lte;
var reverse = y < x;
if (reverse) {
incr *= -1;
test = gte;
}
var pad = n.some(isPadded);
N = [];
for (var i = x; test(i, y); i += incr) {
var c;
if (isAlphaSequence) {
c = String.fromCharCode(i);
if (c === '\\')
c = '';
} else {
c = String(i);
if (pad) {
var need = width - c.length;
if (need > 0) {
var z = new Array(need + 1).join('0');
if (i < 0)
c = '-' + z + c.slice(1);
else
c = z + c;
}
}
}
N.push(c);
}
} else {
N = concatMap(n, function(el) { return expand(el, false) });
}
for (var j = 0; j < N.length; j++) {
for (var k = 0; k < post.length; k++) {
var expansion = pre + N[j] + post[k];
if (!isTop || isSequence || expansion)
expansions.push(expansion);
}
}
return expansions;
}
/***/ }),
/***/ 5560:
@ -34306,6 +34298,14 @@ module.exports = require("node:events");
/***/ }),
/***/ 3024:
/***/ ((module) => {
"use strict";
module.exports = require("node:fs");
/***/ }),
/***/ 7075:
/***/ ((module) => {

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -6,9 +6,10 @@
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"format": "biome format --write .",
"format-check": "biome format --write .",
"lint": "biome check .",
"lint:fix": "biome check --apply .",
"package": "ncc build --source-map --license licenses.txt",
"test": "jest",
"build_test": "tsc && jest",
@ -32,18 +33,13 @@
"@octokit/graphql-schema": "^15.26.0"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.7",
"@typescript-eslint/parser": "^8.20.0",
"@vercel/ncc": "^0.38.3",
"eslint": "^8.56.0",
"eslint-plugin-github": "^5.1.5",
"eslint-plugin-jest": "^28.11.0",
"eslint-plugin-prettier": "^5.2.2",
"jest": "^29.7.0",
"jest-circus": "^29.7.0",
"js-yaml": "^4.1.0",
"prettier": "3.4.2",
"ts-jest": "^29.2.5",
"typescript": "^5.7.3"
}

View file

@ -1,17 +1,17 @@
import * as core from "@actions/core"
import {
import type {GitHub} from "@actions/github/lib/utils"
import type {
IssueComment,
ReportedContentClassifiers,
Repository,
User
} from "@octokit/graphql-schema/schema.d"
import {GitHub} from "@actions/github/lib/utils"
type CreateCommentResponse = Awaited<
ReturnType<InstanceType<typeof GitHub>["rest"]["issues"]["createComment"]>
>
function headerComment(header: String): string {
function headerComment(header: string): string {
return `<!-- Sticky Pull Request Comment${header} -->`
}
@ -76,8 +76,7 @@ export async function findPreviousComment(
return target
}
after = repository.pullRequest?.comments?.pageInfo?.endCursor
hasNextPage =
repository.pullRequest?.comments?.pageInfo?.hasNextPage ?? false
hasNextPage = repository.pullRequest?.comments?.pageInfo?.hasNextPage ?? false
}
return undefined
}
@ -89,12 +88,9 @@ export async function updateComment(
header: string,
previousBody?: string
): Promise<void> {
if (!body && !previousBody)
return core.warning("Comment body cannot be blank")
if (!body && !previousBody) return core.warning("Comment body cannot be blank")
const rawPreviousBody: String = previousBody
? bodyWithoutHeader(previousBody, header)
: ""
const rawPreviousBody: string = previousBody ? bodyWithoutHeader(previousBody, header) : ""
await octokit.graphql(
`
@ -136,9 +132,7 @@ export async function createComment(
return await octokit.rest.issues.createComment({
...repo,
issue_number,
body: previousBody
? `${previousBody}\n${body}`
: bodyWithHeader(body, header)
body: previousBody ? `${previousBody}\n${body}` : bodyWithHeader(body, header)
})
}
export async function deleteComment(
@ -189,11 +183,7 @@ export function getBodyOf(
return previous.body.replace(/(<details.*?)\s*\bopen\b(.*>)/g, "$1$2")
}
export function commentsEqual(
body: string,
previous: string | undefined,
header: string
): boolean {
export function commentsEqual(body: string, previous: string | undefined, header: string): boolean {
const newBody = bodyWithHeader(body, header)
return newBody === previous
}

View file

@ -1,12 +1,11 @@
import {readFileSync} from "node:fs"
import * as core from "@actions/core"
import {ReportedContentClassifiers} from "@octokit/graphql-schema/schema.d"
import {context} from "@actions/github"
import {readFileSync} from "fs"
import {create} from "@actions/glob"
import type {ReportedContentClassifiers} from "@octokit/graphql-schema/schema.d"
export const pullRequestNumber =
context?.payload?.pull_request?.number ||
+core.getInput("number", {required: false})
context?.payload?.pull_request?.number || +core.getInput("number", {required: false})
export const repo = buildRepo()
export const header = core.getInput("header", {required: false})
@ -55,9 +54,7 @@ export async function getBody(): Promise<string> {
followSymbolicLinks,
matchDirectories: false
})
return (await globber.glob())
.map(path => readFileSync(path, "utf-8"))
.join("\n")
return (await globber.glob()).map(path => readFileSync(path, "utf-8")).join("\n")
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message)

View file

@ -1,35 +1,35 @@
import * as core from "@actions/core"
import * as github from "@actions/github"
import {
commentsEqual,
createComment,
deleteComment,
findPreviousComment,
getBodyOf,
minimizeComment,
updateComment
} from "./comment"
import {
append,
getBody,
deleteOldComment,
getBody,
githubToken,
header,
hideAndRecreate,
hideClassify,
hideDetails,
hideOldComment,
ignoreEmpty,
onlyCreateComment,
onlyUpdateComment,
pullRequestNumber,
recreate,
repo,
ignoreEmpty,
skipUnchanged,
onlyCreateComment,
onlyUpdateComment
skipUnchanged
} from "./config"
import {
createComment,
deleteComment,
findPreviousComment,
getBodyOf,
minimizeComment,
updateComment,
commentsEqual
} from "./comment"
async function run(): Promise<undefined> {
if (isNaN(pullRequestNumber) || pullRequestNumber < 1) {
if (Number.isNaN(pullRequestNumber) || pullRequestNumber < 1) {
core.info("no pull request numbers given: skip step")
return
}
@ -59,12 +59,7 @@ async function run(): Promise<undefined> {
}
const octokit = github.getOctokit(githubToken)
const previous = await findPreviousComment(
octokit,
repo,
pullRequestNumber,
header
)
const previous = await findPreviousComment(octokit, repo, pullRequestNumber, header)
core.setOutput("previous_comment_id", previous?.id)
@ -79,13 +74,7 @@ async function run(): Promise<undefined> {
if (onlyUpdateComment) {
return
}
const created = await createComment(
octokit,
repo,
pullRequestNumber,
body,
header
)
const created = await createComment(octokit, repo, pullRequestNumber, body, header)
core.setOutput("created_comment_id", created?.data.id)
return
}
@ -106,11 +95,7 @@ async function run(): Promise<undefined> {
return
}
const previousBody = getBodyOf(
{body: previous.body || ""},
append,
hideDetails
)
const previousBody = getBodyOf({body: previous.body || ""}, append, hideDetails)
if (recreate) {
await deleteComment(octokit, previous.id)
const created = await createComment(
@ -127,13 +112,7 @@ async function run(): Promise<undefined> {
if (hideAndRecreate) {
await minimizeComment(octokit, previous.id, hideClassify)
const created = await createComment(
octokit,
repo,
pullRequestNumber,
body,
header
)
const created = await createComment(octokit, repo, pullRequestNumber, body, header)
core.setOutput("created_comment_id", created?.data.id)
return
}

1900
yarn.lock

File diff suppressed because it is too large Load diff