From 629f351f6ad26f5d4d7fad6c58f05c05b8be05c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 9 Oct 2024 07:08:06 +0900 Subject: [PATCH] chore: empty string test --- .github/empty-string-checker.ts | 21 +++++++++++++-------- package.json | 1 + yarn.lock | 30 +++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/.github/empty-string-checker.ts b/.github/empty-string-checker.ts index 406cce7..61c4d26 100644 --- a/.github/empty-string-checker.ts +++ b/.github/empty-string-checker.ts @@ -14,7 +14,7 @@ if (!token || !owner || !repo || pullNumber === "0" || !baseRef) { const octokit = new Octokit({ auth: token }); const git = simpleGit(); -async function run() { +async function main() { try { // Get the base and head SHAs for the pull request const { data: pullRequest } = await octokit.pulls.get({ @@ -32,17 +32,22 @@ async function run() { // Get the diff of the pull request using the SHAs const diff = await git.diff([`${baseSha}...${headSha}`]); - const violations = parseDiffForEmptyStrings(diff); + console.log("Checking for empty strings..."); + const emptyStrings = parseDiffForEmptyStrings(diff); - if (violations.length > 0) { - await createReview(violations); - process.exit(1); // Exit with error to indicate failure + if (emptyStrings.length > 0) { + console.error("Empty strings found:"); + emptyStrings.forEach(({ file, line }) => { + console.error(`${file}:${line}`); + }); + await createReview(emptyStrings); + process.exit(1); // This line is causing the non-zero exit code } else { console.log("No empty strings found."); } } catch (error) { - console.error("Error running empty string check:", error); - process.exit(1); + console.error("An error occurred:", error); + process.exit(1); // This could also be causing the non-zero exit code } } @@ -91,7 +96,7 @@ async function createReview(violations: Array<{ file: string; line: number; cont }); } -run().catch((error) => { +main().catch((error) => { console.error("Error running empty string check:", error); process.exit(1); }); diff --git a/package.json b/package.json index 87b1014..6665034 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "lint-staged": "^15.2.2", "npm-run-all": "^4.1.5", "prettier": "^3.2.5", + "simple-git": "^3.27.0", "ts-jest": "29.1.2", "tsx": "^4.7.1", "typescript": "^5.3.3" diff --git a/yarn.lock b/yarn.lock index 61a0a00..b445824 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1451,6 +1451,18 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" +"@kwsites/file-exists@^1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@kwsites/file-exists/-/file-exists-1.1.1.tgz#ad1efcac13e1987d8dbaf235ef3be5b0d96faa99" + integrity sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw== + dependencies: + debug "^4.1.1" + +"@kwsites/promise-deferred@^1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz#8ace5259254426ccef57f3175bc64ed7095ed919" + integrity sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw== + "@mswjs/cookies@^1.1.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@mswjs/cookies/-/cookies-1.1.0.tgz#1528eb43630caf83a1d75d5332b30e75e9bb1b5b" @@ -3142,6 +3154,13 @@ debug@^3.1.0: dependencies: ms "^2.1.1" +debug@^4.3.5: + version "4.3.7" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52" + integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ== + dependencies: + ms "^2.1.3" + decamelize-keys@^1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/decamelize-keys/-/decamelize-keys-1.1.1.tgz#04a2d523b2f18d80d0158a43b895d56dff8d19d8" @@ -5641,7 +5660,7 @@ ms@2.1.2: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== -ms@^2.1.1: +ms@^2.1.1, ms@^2.1.3: version "2.1.3" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== @@ -6600,6 +6619,15 @@ simple-get@^4.0.1: once "^1.3.1" simple-concat "^1.0.0" +simple-git@^3.27.0: + version "3.27.0" + resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-3.27.0.tgz#f4b09e807bda56a4a3968f635c0e4888d3decbd5" + integrity sha512-ivHoFS9Yi9GY49ogc6/YAi3Fl9ROnF4VyubNylgCkA+RVqLaKWnDSzXOVzya8csELIaWaYNutsEuAhZrtOjozA== + dependencies: + "@kwsites/file-exists" "^1.1.1" + "@kwsites/promise-deferred" "^1.1.1" + debug "^4.3.5" + sisteransi@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"