Skip to content

Commit

Permalink
move fragment schema next to gql fragment string
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov committed May 10, 2024
1 parent 7fd328c commit 5b09479
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 54 deletions.
55 changes: 55 additions & 0 deletions src/services/pull/fragments.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { z } from 'zod'

export const HeaderOnPullFragment = `
fragment HeaderOnPullFragment on Pull {
pullId
Expand Down Expand Up @@ -253,6 +255,59 @@ fragment FileComparisonWithBase on Pull {
}
}`

const CoverageLineSchema = z.enum(['H', 'M', 'P'])

export const ComparisonSchema = z.object({
__typename: z.literal('Comparison'),
impactedFile: z
.object({
headName: z.string().nullable(),
hashedPath: z.string(),
isNewFile: z.boolean(),
isRenamedFile: z.boolean(),
isDeletedFile: z.boolean(),
isCriticalFile: z.boolean(),
changeCoverage: z.number().nullable(),
baseCoverage: z
.object({
percentCovered: z.number().nullable(),
})
.nullable(),
headCoverage: z
.object({
percentCovered: z.number().nullable(),
})
.nullable(),
patchCoverage: z
.object({
percentCovered: z.number().nullable(),
})
.nullable(),
segments: z.object({
results: z.array(
z.object({
header: z.string(),
hasUnintendedChanges: z.boolean(),
lines: z.array(
z.object({
baseNumber: z.string().nullable(),
headNumber: z.string().nullable(),
baseCoverage: CoverageLineSchema.nullable(),
headCoverage: CoverageLineSchema.nullable(),
content: z.string().nullable(),
coverageInfo: z.object({
hitCount: z.number().nullable(),
hitUploadIds: z.array(z.number()).nullable(),
}),
})
),
})
),
}),
})
.nullable(),
})

export const PullCompareWithBaseFragment = `
fragment PullCompareWithBaseFragment on Pull {
compareWithBase {
Expand Down
55 changes: 1 addition & 54 deletions src/services/pull/usePrefetchSingleFileComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,9 @@ import Api from 'shared/api'
import { NetworkErrorObject } from 'shared/api/helpers'
import A from 'ui/A'

import { FileComparisonWithBase } from './fragments'
import { ComparisonSchema, FileComparisonWithBase } from './fragments'
import { transformImpactedFileData } from './utils'

const CoverageLineSchema = z.enum(['H', 'M', 'P'])

const ComparisonSchema = z.object({
__typename: z.literal('Comparison'),
impactedFile: z
.object({
headName: z.string().nullable(),
hashedPath: z.string(),
isNewFile: z.boolean(),
isRenamedFile: z.boolean(),
isDeletedFile: z.boolean(),
isCriticalFile: z.boolean(),
changeCoverage: z.number().nullable(),
baseCoverage: z
.object({
percentCovered: z.number().nullable(),
})
.nullable(),
headCoverage: z
.object({
percentCovered: z.number().nullable(),
})
.nullable(),
patchCoverage: z
.object({
percentCovered: z.number().nullable(),
})
.nullable(),
segments: z.object({
results: z.array(
z.object({
header: z.string(),
hasUnintendedChanges: z.boolean(),
lines: z.array(
z.object({
baseNumber: z.string().nullable(),
headNumber: z.string().nullable(),
baseCoverage: CoverageLineSchema.nullable(),
headCoverage: CoverageLineSchema.nullable(),
content: z.string().nullable(),
coverageInfo: z.object({
hitCount: z.number().nullable(),
hitUploadIds: z.array(z.number()).nullable(),
}),
})
),
})
),
}),
})
.nullable(),
})

const FileComparisonWithBaseSchema = z.object({
compareWithBase: z
.discriminatedUnion('__typename', [
Expand Down

0 comments on commit 5b09479

Please sign in to comment.