mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-08-07 04:24:16 +00:00
Merge branch 'main' into main
This commit is contained in:
+15
-23
@@ -2,17 +2,11 @@ const t = require("ava");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const domainsPath = path.resolve("domains");
|
||||
const files = fs.readdirSync(domainsPath).filter((file) => file.endsWith(".json"));
|
||||
|
||||
const changedFiles = JSON.parse(process.env.CHANGED_FILES);
|
||||
const prAuthor = process.env.PR_AUTHOR.toLowerCase();
|
||||
const prLabels = JSON.parse(process.env.PR_LABELS);
|
||||
const trustedUsers = require("../util/trusted.json").map((u) => u.toLowerCase());
|
||||
|
||||
function getDomainData(subdomain) {
|
||||
try {
|
||||
const data = fs.readJsonSync(path.join(domainsPath, `${subdomain}.json`));
|
||||
const data = fs.readJsonSync(path.join(path.resolve("domains"), `${subdomain}.json`));
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to read JSON for ${subdomain}: ${error.message}`);
|
||||
@@ -21,26 +15,24 @@ function getDomainData(subdomain) {
|
||||
|
||||
t("Users can only update their own subdomains", (t) => {
|
||||
if (process.env.PR_AUTHOR && process.env.CHANGED_FILES) {
|
||||
const changedFiles = JSON.parse(process.env.CHANGED_FILES);
|
||||
const prAuthor = process.env.PR_AUTHOR.toLowerCase();
|
||||
const changedJSONFiles = changedFiles
|
||||
.filter((file) => file.startsWith("domains/"))
|
||||
.map((file) => path.basename(file))
|
||||
.forEach((file) => file.replace(/\.json$/, ""));
|
||||
.map((file) => path.basename(file));
|
||||
|
||||
if (trustedUsers.includes(prAuthor) || prLabels.includes("bypass-owner-check")) {
|
||||
t.pass();
|
||||
} else {
|
||||
files
|
||||
.filter((file) => changedJSONFiles.includes(file))
|
||||
.forEach((file) => {
|
||||
const subdomain = file.replace(/\.json$/, "");
|
||||
const data = getDomainData(subdomain);
|
||||
if (!changedJSONFiles || trustedUsers.includes(prAuthor)) return t.pass();
|
||||
if (process.env.PR_LABELS && process.env.PR_LABELS.includes("bypass-owner-check")) return t.pass();
|
||||
|
||||
t.true(
|
||||
data.owner.username.toLowerCase() === prAuthor,
|
||||
`${subdomain}: ${prAuthor} does not own ${subdomain}.is-a.dev`
|
||||
);
|
||||
});
|
||||
}
|
||||
changedJSONFiles.forEach((file) => {
|
||||
const subdomain = file.replace(/\.json$/, "");
|
||||
const data = getDomainData(subdomain);
|
||||
|
||||
t.true(
|
||||
data.owner.username.toLowerCase() === prAuthor,
|
||||
`${subdomain}: ${prAuthor} does not own ${subdomain}.is-a.dev`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
t.pass();
|
||||
|
||||
Reference in New Issue
Block a user