Fix validation of git repository identifier in updateProjectGitRepository (#137)

Validation logic of the git repository field in the project's settings expected an URL instead of the `owner/name` format
This commit is contained in:
Kamil Kisiela 2022-06-13 06:50:58 -07:00 committed by GitHub
parent 068d018c54
commit 29552a575f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,10 @@ import { z } from 'zod';
const ProjectNameModel = z.string().min(2).max(40);
const URLModel = z.string().url().max(200);
const RepoOwnerWithNameModel = z
.string()
.regex(/^[^/]+\/[^/]+$/, 'Expected owner/name format')
.max(200);
const MaybeModel = <T extends z.ZodType>(value: T) => z.union([z.null(), z.undefined(), value]);
export const resolvers: ProjectModule.Resolvers & { ProjectType: any } = {
@ -137,7 +141,7 @@ export const resolvers: ProjectModule.Resolvers & { ProjectType: any } = {
},
async updateProjectGitRepository(_, { input }, { injector }) {
const UpdateProjectGitRepositoryModel = z.object({
gitRepository: MaybeModel(URLModel),
gitRepository: MaybeModel(RepoOwnerWithNameModel),
});
const result = UpdateProjectGitRepositoryModel.safeParse(input);