ci(lint): validate name metadata (#402)
Co-authored-by: winston <[email protected]>
This commit is contained in:
1 parent
8da437f9f2
commit
5bb6f6db1e
14 files changed
+96
-67
No files matched your search
@@ -1,5 +1,10 @@
|
||||
import Ajv, { Schema } from "ajv";
|
||||
import { parse } from "std/yaml/parse.ts";
|
||||
import { join } from "std/path/join.ts";
|
||||
import { SetRequired } from "type-fest/source/set-required.d.ts";
|
||||
|
||||
import { REPO_ROOT, userStylesSchema } from "@/deps.ts";
|
||||
import { UserstylesSchema } from "@/types/userstyles.d.ts";
|
||||
|
||||
/**
|
||||
* @param content A string of YAML content
|
||||
@@ -20,3 +25,23 @@ export const validateYaml = <T>(
|
||||
return resolve(data);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility function that calls {@link validateYaml} on the userstyles.yml file.
|
||||
* Fails when data.userstyles is undefined.
|
||||
*/
|
||||
export const getUserstylesData = (): Promise<Userstyles> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
validateYaml<UserstylesSchema>(
|
||||
Deno.readTextFileSync(join(REPO_ROOT, "scripts/userstyles.yml")),
|
||||
userStylesSchema,
|
||||
).then((data) => {
|
||||
if (data.userstyles === undefined || data.collaborators === undefined) {
|
||||
return reject("userstyles.yml is missing required fields");
|
||||
}
|
||||
return resolve(data as Userstyles);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
type Userstyles = SetRequired<UserstylesSchema, "userstyles" | "collaborators">;
|
||||
Reference in new issue
Block a user