From c23fdf32c5d61d5e792592b693284deaff02ef4e Mon Sep 17 00:00:00 2001 From: Stefano Del Prete Date: Thu, 2 Jan 2025 14:52:37 +0100 Subject: [PATCH 1/9] Update pr.test.js --- tests/pr.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pr.test.js b/tests/pr.test.js index 7bb79061b..ae4d0a13d 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -2,7 +2,7 @@ const t = require("ava"); const fs = require("fs-extra"); const path = require("path"); -const PR_AUTHOR = process.env.PR_AUTHOR; +const PR_AUTHOR = process.env.PR_AUTHOR.toLowerCase(); const MODIFIED_FILES = (process.env.MODIFIED_FILES || "").split(" ").map((file) => file.replace(/^domains\//, "")); const EVENT = process.env.EVENT; const RUN_ID = process.env.RUN_ID; From 297e8ae19063bad22d36939268ac24c443f58ec6 Mon Sep 17 00:00:00 2001 From: Stefano Del Prete Date: Thu, 2 Jan 2025 14:59:15 +0100 Subject: [PATCH 2/9] Update pr.test.js --- tests/pr.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/pr.test.js b/tests/pr.test.js index ae4d0a13d..edf83560d 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -37,8 +37,8 @@ t("Modified JSON files must be owned by the PR author", async (t) => { } t.true( - domainToCheck.owner.username === PR_AUTHOR || admins.includes(PR_AUTHOR), - `${file}: Domain owner is ${domainToCheck.owner.username} but ${PR_AUTHOR} is the PR author` + domainToCheck.owner.username.toLowerCase() === PR_AUTHOR || admins.includes(PR_AUTHOR), + `${file}: Domain owner is ${domainToCheck.owner.username.toLowerCase()} but ${PR_AUTHOR} is the PR author` ); }); @@ -59,8 +59,8 @@ t("New JSON files must be owned by the PR author", async (t) => { if (!domain) return t.fail(`${file}: Unable to read domain data`); t.true( - domain.owner.username === PR_AUTHOR || admins.includes(PR_AUTHOR), - `${file}: Domain owner is ${domain.owner.username} but ${PR_AUTHOR} is the PR author` + domain.owner.username.toLowerCase() === PR_AUTHOR || admins.includes(PR_AUTHOR), + `${file}: Domain owner is ${domain.owner.username.toLowerCase()} but ${PR_AUTHOR} is the PR author` ); }); From a0c757d0d2de19011c047ce4bf276f6c112345a0 Mon Sep 17 00:00:00 2001 From: Stefano Del Prete Date: Thu, 2 Jan 2025 15:05:03 +0100 Subject: [PATCH 3/9] Update pr.test.js --- tests/pr.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pr.test.js b/tests/pr.test.js index edf83560d..118b1a658 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -10,7 +10,7 @@ const RUN_ID = process.env.RUN_ID; const domainsPath = path.resolve("domains"); const headDomainsPath = path.resolve(`register-${RUN_ID}/domains`); -const admins = require("../util/administrators.json"); +const admins = require("../util/administrators.json").map(admin => admin.toLowerCase()); async function getJSONContent(basePath, fileName) { try { From 245662dca2eb2ad90ec4a079a6f1a8ed1f3b6c91 Mon Sep 17 00:00:00 2001 From: Stefano Del Prete Date: Thu, 2 Jan 2025 15:14:10 +0100 Subject: [PATCH 4/9] Update pr.test.js --- tests/pr.test.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/pr.test.js b/tests/pr.test.js index 118b1a658..bfad9aafe 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -13,10 +13,16 @@ const headDomainsPath = path.resolve(`register-${RUN_ID}/domains`); const admins = require("../util/administrators.json").map(admin => admin.toLowerCase()); async function getJSONContent(basePath, fileName) { + const jsonPath = path.join(basePath, fileName) + + if (!fs.existsSync(jsonPath)) { + return 1; + } + try { return await fs.readJson(path.join(basePath, fileName)); } catch { - return null; + return 2; } } @@ -31,7 +37,7 @@ t("Modified JSON files must be owned by the PR author", async (t) => { const domainToCheck = currentDomain || modifiedDomain; - if (!modifiedDomain || !domainToCheck) { + if (modifiedDomain === 2 || domainToCheck === 2) { t.fail(`${file}: Unable to read domain data`); return; } @@ -56,7 +62,7 @@ t("New JSON files must be owned by the PR author", async (t) => { const checks = newDomainFiles.map(async (file) => { const domain = await getJSONContent(domainsPath, file); - if (!domain) return t.fail(`${file}: Unable to read domain data`); + if (!domain === 2) return t.fail(`${file}: Unable to read domain data`); t.true( domain.owner.username.toLowerCase() === PR_AUTHOR || admins.includes(PR_AUTHOR), From 732930e07af894566da8b04c59630181903511b4 Mon Sep 17 00:00:00 2001 From: Stefano Del Prete Date: Thu, 2 Jan 2025 15:20:29 +0100 Subject: [PATCH 5/9] test logging --- tests/pr.test.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/pr.test.js b/tests/pr.test.js index bfad9aafe..d1cc1a93b 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -7,22 +7,18 @@ const MODIFIED_FILES = (process.env.MODIFIED_FILES || "").split(" ").map((file) const EVENT = process.env.EVENT; const RUN_ID = process.env.RUN_ID; +console.log(MODIFIED_FILES) + const domainsPath = path.resolve("domains"); const headDomainsPath = path.resolve(`register-${RUN_ID}/domains`); const admins = require("../util/administrators.json").map(admin => admin.toLowerCase()); async function getJSONContent(basePath, fileName) { - const jsonPath = path.join(basePath, fileName) - - if (!fs.existsSync(jsonPath)) { - return 1; - } - try { return await fs.readJson(path.join(basePath, fileName)); } catch { - return 2; + return null; } } @@ -37,7 +33,7 @@ t("Modified JSON files must be owned by the PR author", async (t) => { const domainToCheck = currentDomain || modifiedDomain; - if (modifiedDomain === 2 || domainToCheck === 2) { + if (!modifiedDomain || !domainToCheck) { t.fail(`${file}: Unable to read domain data`); return; } @@ -62,7 +58,7 @@ t("New JSON files must be owned by the PR author", async (t) => { const checks = newDomainFiles.map(async (file) => { const domain = await getJSONContent(domainsPath, file); - if (!domain === 2) return t.fail(`${file}: Unable to read domain data`); + if (!domain) return t.fail(`${file}: Unable to read domain data`); t.true( domain.owner.username.toLowerCase() === PR_AUTHOR || admins.includes(PR_AUTHOR), From 581a3078be3c2fcb9d93c7521181725099d0c263 Mon Sep 17 00:00:00 2001 From: Stefano Del Prete Date: Thu, 2 Jan 2025 15:22:01 +0100 Subject: [PATCH 6/9] test logging --- tests/pr.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pr.test.js b/tests/pr.test.js index d1cc1a93b..951a53c9c 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -7,7 +7,7 @@ const MODIFIED_FILES = (process.env.MODIFIED_FILES || "").split(" ").map((file) const EVENT = process.env.EVENT; const RUN_ID = process.env.RUN_ID; -console.log(MODIFIED_FILES) +console.log(process.env.MODIFIED_FILES, MODIFIED_FILES) const domainsPath = path.resolve("domains"); const headDomainsPath = path.resolve(`register-${RUN_ID}/domains`); From fdd50605feede3aa5d665585c13d164410a6bc6b Mon Sep 17 00:00:00 2001 From: Stefano Del Prete Date: Thu, 2 Jan 2025 15:24:05 +0100 Subject: [PATCH 7/9] test logging --- tests/pr.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pr.test.js b/tests/pr.test.js index 951a53c9c..b1bde01aa 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -7,7 +7,7 @@ const MODIFIED_FILES = (process.env.MODIFIED_FILES || "").split(" ").map((file) const EVENT = process.env.EVENT; const RUN_ID = process.env.RUN_ID; -console.log(process.env.MODIFIED_FILES, MODIFIED_FILES) +console.log(process.env.MODIFIED_FILES, MODIFIED_FILES || "") const domainsPath = path.resolve("domains"); const headDomainsPath = path.resolve(`register-${RUN_ID}/domains`); From d966e9cbfaa956cd7f24f9b2a83974c7ebe94e23 Mon Sep 17 00:00:00 2001 From: Stefano Del Prete Date: Thu, 2 Jan 2025 15:27:48 +0100 Subject: [PATCH 8/9] Update pr.test.js --- tests/pr.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/pr.test.js b/tests/pr.test.js index b1bde01aa..4cd2b3a69 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -3,11 +3,11 @@ const fs = require("fs-extra"); const path = require("path"); const PR_AUTHOR = process.env.PR_AUTHOR.toLowerCase(); -const MODIFIED_FILES = (process.env.MODIFIED_FILES || "").split(" ").map((file) => file.replace(/^domains\//, "")); +const MODIFIED_DOMAIN_FILES = (process.env.MODIFIED_FILES || "").split(" ").map((file) => file.replace(/^domains\//, "")); const EVENT = process.env.EVENT; const RUN_ID = process.env.RUN_ID; -console.log(process.env.MODIFIED_FILES, MODIFIED_FILES || "") +console.log(process.env.MODIFIED_FILES.length) const domainsPath = path.resolve("domains"); const headDomainsPath = path.resolve(`register-${RUN_ID}/domains`); @@ -25,7 +25,7 @@ async function getJSONContent(basePath, fileName) { t("Modified JSON files must be owned by the PR author", async (t) => { if (EVENT !== "pull_request") return t.pass(); - const checks = MODIFIED_FILES.map(async (file) => { + const checks = MODIFIED_DOMAIN_FILES.map(async (file) => { const [modifiedDomain, currentDomain] = await Promise.all([ getJSONContent(domainsPath, file), getJSONContent(headDomainsPath, file) From ce30624074b2790a0bdb76ef7ea506f09389b544 Mon Sep 17 00:00:00 2001 From: Stefano Del Prete Date: Thu, 2 Jan 2025 15:30:17 +0100 Subject: [PATCH 9/9] Update pr.test.js --- tests/pr.test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/pr.test.js b/tests/pr.test.js index 4cd2b3a69..4a9822684 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -3,12 +3,12 @@ const fs = require("fs-extra"); const path = require("path"); const PR_AUTHOR = process.env.PR_AUTHOR.toLowerCase(); -const MODIFIED_DOMAIN_FILES = (process.env.MODIFIED_FILES || "").split(" ").map((file) => file.replace(/^domains\//, "")); +const MODIFIED_DOMAIN_FILES = (process.env.MODIFIED_FILES || "").length > 0 + ? (process.env.MODIFIED_FILES || "").split(" ").map((file) => file.replace(/^domains\//, "")) + : null; const EVENT = process.env.EVENT; const RUN_ID = process.env.RUN_ID; -console.log(process.env.MODIFIED_FILES.length) - const domainsPath = path.resolve("domains"); const headDomainsPath = path.resolve(`register-${RUN_ID}/domains`); @@ -24,6 +24,7 @@ async function getJSONContent(basePath, fileName) { t("Modified JSON files must be owned by the PR author", async (t) => { if (EVENT !== "pull_request") return t.pass(); + if (!MODIFIED_DOMAIN_FILES) return t.pass(); const checks = MODIFIED_DOMAIN_FILES.map(async (file) => { const [modifiedDomain, currentDomain] = await Promise.all([ @@ -50,6 +51,7 @@ t("Modified JSON files must be owned by the PR author", async (t) => { t("New JSON files must be owned by the PR author", async (t) => { if (EVENT !== "pull_request") return t.pass(); + if (!MODIFIED_DOMAIN_FILES) return t.pass(); const [newFiles, currentFiles] = await Promise.all([fs.readdir(domainsPath), fs.readdir(headDomainsPath)]);