Skip to content

Commit a38f520

Browse files
committed
chore(models): require slug for organization and project, better descriptions
1 parent 105b1b8 commit a38f520

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

packages/models/src/lib/audit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const pluginAuditsSchema = z
3333
// helper for validator: audit slugs are unique
3434
function duplicateSlugsInAuditsErrorMsg(audits: Audit[]) {
3535
const duplicateRefs = getDuplicateSlugsInAudits(audits);
36-
return `In plugin audits the slugs are not unique: ${errorItems(
36+
return `In plugin audits the following slugs are not unique: ${errorItems(
3737
duplicateRefs,
3838
)}`;
3939
}

packages/models/src/lib/group.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ function getDuplicateRefsInGroups(groups: WeightedRef[]) {
6363
// helper for validator: group refs are unique
6464
function duplicateSlugsInGroupsErrorMsg(groups: Group[] | undefined) {
6565
const duplicateRefs = getDuplicateSlugsInGroups(groups);
66-
return `In groups the slugs are not unique: ${errorItems(duplicateRefs)}`;
66+
return `In groups the following slugs are not unique: ${errorItems(
67+
duplicateRefs,
68+
)}`;
6769
}
6870

6971
function getDuplicateSlugsInGroups(groups: Group[] | undefined) {

packages/models/src/lib/plugin-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const pluginMetaSchema = packageVersionSchema()
2121
)
2222
.merge(
2323
z.object({
24-
slug: slugSchema('References plugin. ID (unique within core config)'),
24+
slug: slugSchema('Unique plugin slug within core config'),
2525
icon: materialIconSchema,
2626
}),
2727
);
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import { z } from 'zod';
2-
import { urlSchema } from './implementation/schemas';
2+
import { slugSchema, urlSchema } from './implementation/schemas';
33

44
export const uploadConfigSchema = z.object({
55
server: urlSchema('URL of deployed portal API'),
66
apiKey: z.string({
77
description:
88
'API key with write access to portal (use `process.env` for security)',
99
}),
10-
organization: z.string({
11-
description: 'Organization in code versioning system',
12-
}),
13-
project: z.string({
14-
description: 'Project in code versioning system',
15-
}),
10+
organization: slugSchema('Organization slug from Code PushUp portal'),
11+
project: slugSchema('Project slug from Code PushUp portal'),
1612
});
1713

1814
export type UploadConfig = z.infer<typeof uploadConfigSchema>;

packages/models/src/lib/upload-config.unit.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,26 @@ describe('uploadConfigSchema', () => {
2323
} satisfies UploadConfig),
2424
).toThrow('Invalid url');
2525
});
26+
27+
it('should throw for a PascalCase organization name', () => {
28+
expect(() =>
29+
uploadConfigSchema.parse({
30+
apiKey: 'API-K3Y',
31+
organization: 'CodePushUp',
32+
project: 'cli',
33+
server: '-invalid-/url',
34+
} satisfies UploadConfig),
35+
).toThrow('slug has to follow the pattern');
36+
});
37+
38+
it('should throw for a project with uppercase letters', () => {
39+
expect(() =>
40+
uploadConfigSchema.parse({
41+
apiKey: 'API-K3Y',
42+
organization: 'code-pushup',
43+
project: 'Code-PushUp-CLI',
44+
server: '-invalid-/url',
45+
} satisfies UploadConfig),
46+
).toThrow('slug has to follow the pattern');
47+
});
2648
});

0 commit comments

Comments
 (0)