Skip to content

Commit

Permalink
chore: empty string test
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Oct 8, 2024
1 parent c8eaf08 commit 629f351
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
21 changes: 13 additions & 8 deletions .github/empty-string-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 29 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -5641,7 +5660,7 @@ [email protected]:
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==
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 629f351

Please sign in to comment.