diff --git a/src/pages/RepoPage/CoverageOnboarding/GitHubActions/GitHubActions.test.tsx b/src/pages/RepoPage/CoverageOnboarding/GitHubActions/GitHubActions.test.tsx index 5d4718fdd8..985dc1b8f3 100644 --- a/src/pages/RepoPage/CoverageOnboarding/GitHubActions/GitHubActions.test.tsx +++ b/src/pages/RepoPage/CoverageOnboarding/GitHubActions/GitHubActions.test.tsx @@ -57,7 +57,7 @@ const mockGetUploadTokenRequired = { const mockDetailOwner = { owner: { - ownerid: '1234', + ownerid: 1234, username: 'codecov', avatarUrl: 'https://avatars.githubusercontent.com/u/1234?v=4', isCurrentUserPartOfOrg: true, diff --git a/src/services/user/useOwner.ts b/src/services/user/useOwner.ts index 5b7357cc93..73f636fc04 100644 --- a/src/services/user/useOwner.ts +++ b/src/services/user/useOwner.ts @@ -1,7 +1,23 @@ import { useQuery } from '@tanstack/react-query' import { useParams } from 'react-router-dom' +import { z } from 'zod' import Api from 'shared/api' +import { rejectNetworkError } from 'shared/api/helpers' + +const OwnerSchema = z.object({ + ownerid: z.number().nullish(), + username: z.string().nullish(), + avatarUrl: z.string().nullish(), + isCurrentUserPartOfOrg: z.boolean().nullish(), + isAdmin: z.boolean().nullish(), +}) + +export type Owner = z.infer<typeof OwnerSchema> + +const RequestSchema = z.object({ + owner: OwnerSchema.nullish(), +}) interface URLParams { provider: string @@ -40,6 +56,17 @@ export function useOwner({ queryKey: ['owner', variables, provider, query], queryFn: ({ signal }) => Api.graphql({ provider, query, variables, signal }).then((res) => { + const parsedRes = RequestSchema.safeParse(res?.data) + + if (!parsedRes.success) { + return rejectNetworkError({ + status: 404, + data: {}, + dev: 'useOwner - 404 Failed to parse data', + error: parsedRes.error, + }) + } + return res?.data?.owner }), ...opts,