Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata line length check ignores API docs #930

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions scripts/commands/checkMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ const readMetadata = async (filePath: string): Promise<Record<string, any>> => {
}
};

const isValidMetadata = (metadata: Record<string, any>): boolean =>
const isValidMetadata = (
metadata: Record<string, any>,
filePath: string,
): boolean =>
metadata.title &&
metadata.description &&
metadata.title != metadata.description &&
metadata.description.length <= 160 &&
metadata.description.length >= 50;
(isApi(filePath) ||
(metadata.title != metadata.description &&
metadata.description.length <= 160 &&
metadata.description.length >= 50));

const main = async (): Promise<void> => {
const args = readArgs();
Expand All @@ -67,15 +71,15 @@ const main = async (): Promise<void> => {
const mdErrors = [];
for (const file of mdFiles) {
const metadata = await readMetadata(file);
if (!isValidMetadata(metadata)) {
if (!isValidMetadata(metadata, file)) {
mdErrors.push(file);
}
}

const notebookErrors = [];
for (const file of notebookFiles) {
const metadata = await readMetadata(file);
if (!isValidMetadata(metadata)) {
if (!isValidMetadata(metadata, file)) {
notebookErrors.push(file);
}
}
Expand All @@ -99,6 +103,14 @@ async function determineFiles(args: Arguments): Promise<[string[], string[]]> {
return [await globby(mdGlobs), await globby(notebookGlobs)];
}

function isApi(filePath: string): boolean {
return (
filePath.includes("/api/qiskit/") ||
filePath.includes("/api/qiskit-ibm-runtime/") ||
filePath.includes("/api/qiskit-ibm-provider/")
);
}

function handleErrors(mdErrors: string[], notebookErrors: string[]): void {
if (mdErrors.length > 0) {
console.error(`
Expand Down
Loading