diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..5a4a2d5 --- /dev/null +++ b/biome.json @@ -0,0 +1,58 @@ +{ + "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", + "vcs": { + "enabled": false, + "clientKind": "git", + "useIgnoreFile": false + }, + "files": { + "ignoreUnknown": false, + "includes": [ + "**", + "!node_modules", + "!vendor", + "!composer.json", + "!composer.lock", + "!package.json", + "!package-lock.json", + "!analytics.*", + "!metrics.*", + "!coverage", + "!dist" + ] + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 4 + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "javascript": { + "formatter": { + "quoteStyle": "double" + } + }, + "json": { + "formatter": { + "enabled": true, + "bracketSpacing": true, + "expand": "always" + }, + "parser": { + "allowComments": true + } + }, + "assist": { + "enabled": true, + "actions": { + "source": { + "organizeImports": "on" + } + } + } +} diff --git a/dist/index.js b/dist/index.js index b9c3b9f..8047e36 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34392,7 +34392,6 @@ const previewUpdater = async () => { repository: { owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, - octokit: (0, github_1.getOctokit)(token), }, }, configPath); // Read names @@ -34404,7 +34403,7 @@ const previewUpdater = async () => { // Show working directory (0, core_1.info)(`Working directory: ${config.directory}`); // Authenticate - const repo = new repository_1.Repository(config); + const repo = new repository_1.Repository(config, (0, github_1.getOctokit)(token)); await repo.authenticate(); // Read file const content = (0, filesystem_1.readFile)(config, config.path.readme); @@ -34463,8 +34462,8 @@ exports.defaultConfig = { fontSize: "100px", icon: "code", packageManager: "auto", - packageName: undefined, packageGlobal: false, + packageName: undefined, title: undefined, description: undefined, }, @@ -34754,7 +34753,8 @@ const setPreview = (content, config) => { content = `# ${title}\n\n${content}`; } const images = (0, image_1.getImages)(config); - return cleanUp(content).replace(/^(#\s+.+[\n\s]+)/, "$1" + images + "\n\n"); + const replace = "$1"; + return cleanUp(content).replace(/^(#\s+.+[\n\s]+)/, `${replace}${images}\n\n`); }; exports.setPreview = setPreview; @@ -34791,10 +34791,11 @@ exports.Repository = void 0; const filesystem_1 = __nccwpck_require__(9742); const randomizer_1 = __nccwpck_require__(3678); class Repository { - constructor(config) { - this._currentBranch = ''; + constructor(config, octokit) { + this._currentBranch = ""; this._newBranch = false; this._config = config; + this._octokit = octokit; } async authenticate() { try { @@ -34829,17 +34830,17 @@ class Repository { async checkoutBranch(isNew) { try { this._newBranch = isNew; - await (0, filesystem_1.exec)(`git switch ${isNew ? '-c' : ''} "${this.branchName()}"`); + await (0, filesystem_1.exec)(`git switch ${isNew ? "-c" : ""} "${this.branchName()}"`); } catch (error) { // @ts-expect-error - error.message = `Error checking out ${isNew ? 'new' : 'existing'} branch "${this.branchName()}": ${error.message}`; + error.message = `Error checking out ${isNew ? "new" : "existing"} branch "${this.branchName()}": ${error.message}`; throw error; } } async stage() { try { - await (0, filesystem_1.exec)('git add ' + this._config.path.readme); + await (0, filesystem_1.exec)(`git add ${this._config.path.readme}`); } catch (error) { // @ts-expect-error @@ -34850,7 +34851,7 @@ class Repository { async commit() { try { const message = this._config.repository.commit.title + - '\n' + + "\n" + this._config.repository.commit.body; await (0, filesystem_1.exec)(`git commit -m "${message}"`); } @@ -34862,7 +34863,7 @@ class Repository { } async push() { try { - let cmd = 'git push'; + let cmd = "git push"; if (this._newBranch) { cmd += ` --set-upstream origin ${this.branchName()}`; } @@ -34877,13 +34878,13 @@ class Repository { async createPullRequest() { try { const defaultBranch = await (0, filesystem_1.exec)(`git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5`); - return this._config.repository.octokit.rest.pulls.create({ + return this._octokit.rest.pulls.create({ owner: this._config.repository.owner, repo: this._config.repository.repo, title: this._config.repository.pullRequest.title, body: this._config.repository.pullRequest.body, head: this.branchName(), - base: defaultBranch + base: defaultBranch, }); } catch (error) { @@ -34894,11 +34895,11 @@ class Repository { } async assignee(issueNumber, assignees) { try { - return this._config.repository.octokit.rest.issues.addAssignees({ + return this._octokit.rest.issues.addAssignees({ owner: this._config.repository.owner, repo: this._config.repository.repo, issue_number: issueNumber, - assignees: assignees + assignees: assignees, }); } catch (error) { @@ -34909,11 +34910,11 @@ class Repository { } async addLabels(issueNumber, labels) { try { - return this._config.repository.octokit.rest.issues.addLabels({ + return this._octokit.rest.issues.addLabels({ owner: this._config.repository.owner, repo: this._config.repository.repo, issue_number: issueNumber, - labels + labels, }); } catch (error) { @@ -34923,8 +34924,8 @@ class Repository { } } branchName() { - if (this._currentBranch === '') { - this._currentBranch = this._config.repository.commit.branch.replace('{random}', (0, randomizer_1.randomizer)()); + if (this._currentBranch === "") { + this._currentBranch = this._config.repository.commit.branch.replace("{random}", (0, randomizer_1.randomizer)()); } return this._currentBranch; } diff --git a/package.json b/package.json index 254361b..cacff3a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,10 @@ "dev": "npm run build && node dist/index.js", "coverage": "jest --coverage", "test": "jest", - "type-check": "tsc --noEmit" + "type-check": "tsc --noEmit", + "lint": "npx @biomejs/biome lint --write", + "format": "npx @biomejs/biome format --write", + "style": "npm run lint && npm run format" }, "keywords": [ "preview", diff --git a/src/main.ts b/src/main.ts index cff1e2c..774787c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,6 @@ const previewUpdater = async () => { repository: { owner: context.repo.owner, repo: context.repo.repo, - octokit: getOctokit(token), }, }, configPath, @@ -39,7 +38,7 @@ const previewUpdater = async () => { info(`Working directory: ${config.directory}`); // Authenticate - const repo = new Repository(config); + const repo = new Repository(config, getOctokit(token)); await repo.authenticate(); // Read file diff --git a/src/types/config.ts b/src/types/config.ts index 739d688..371cc22 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -39,7 +39,6 @@ export interface PullRequest { export interface Repository { owner?: string; repo?: string; - octokit?: any; commit: Commit; pullRequest: PullRequest; diff --git a/src/utils/preview.ts b/src/utils/preview.ts index dbda915..1824438 100644 --- a/src/utils/preview.ts +++ b/src/utils/preview.ts @@ -19,5 +19,10 @@ export const setPreview = (content: string, config: Config) => { const images: string = getImages(config); - return cleanUp(content).replace(/^(#\s+.+[\n\s]+)/, "$1" + images + "\n\n"); + const replace = "$1"; + + return cleanUp(content).replace( + /^(#\s+.+[\n\s]+)/, + `${replace}${images}\n\n`, + ); }; diff --git a/src/utils/repository.ts b/src/utils/repository.ts index 18d3dec..142c1ef 100644 --- a/src/utils/repository.ts +++ b/src/utils/repository.ts @@ -1,14 +1,18 @@ import type { Config } from "../types/config"; import { exec } from "./filesystem"; import { randomizer } from "./randomizer"; +import type { GitHub } from "@actions/github/lib/utils"; +import type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types"; export class Repository { private _config: Config; private _currentBranch: string = ""; private _newBranch: boolean = false; + private _octokit: InstanceType; - constructor(config: Config) { + constructor(config: Config, octokit: InstanceType) { this._config = config; + this._octokit = octokit; } async authenticate() { @@ -69,7 +73,7 @@ export class Repository { async stage() { try { - await exec("git add " + this._config.path.readme); + await exec(`git add ${this._config.path.readme}`); } catch (error) { // @ts-expect-error error.message = `Error staging file "${this._config.path.readme}": ${error.message}`; @@ -117,7 +121,9 @@ export class Repository { `git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5`, ); - return this._config.repository.octokit.rest.pulls.create({ + return this._octokit.rest.pulls.create(< + RestEndpointMethodTypes["pulls"]["create"]["parameters"] + >{ owner: this._config.repository.owner, repo: this._config.repository.repo, title: this._config.repository.pullRequest.title, @@ -135,7 +141,9 @@ export class Repository { async assignee(issueNumber: number, assignees: string[]) { try { - return this._config.repository.octokit.rest.issues.addAssignees({ + return this._octokit.rest.issues.addAssignees(< + RestEndpointMethodTypes["issues"]["addAssignees"]["parameters"] + >{ owner: this._config.repository.owner, repo: this._config.repository.repo, issue_number: issueNumber, @@ -151,7 +159,9 @@ export class Repository { async addLabels(issueNumber: number, labels: string[]) { try { - return this._config.repository.octokit.rest.issues.addLabels({ + return this._octokit.rest.issues.addLabels(< + RestEndpointMethodTypes["issues"]["addLabels"]["parameters"] + >{ owner: this._config.repository.owner, repo: this._config.repository.repo, issue_number: issueNumber, diff --git a/tests/helpers/filesystem.ts b/tests/helpers/filesystem.ts index 82562d9..bbee0af 100644 --- a/tests/helpers/filesystem.ts +++ b/tests/helpers/filesystem.ts @@ -3,7 +3,7 @@ import { setPreview } from "../../src/utils/preview"; import { testConfig } from "./config"; export const getReadme = (filename: string): string => { - const content = readFile(testConfig, "tests/fixtures/readme/" + filename); + const content = readFile(testConfig, `tests/fixtures/readme/${filename}`); return setPreview(content, testConfig); };