Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 0 additions & 17 deletions eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ export default [
'src/article-api/scripts/generate-api-docs.ts',
'src/article-api/transformers/audit-logs-transformer.ts',
'src/article-api/transformers/rest-transformer.ts',
'src/automated-pipelines/tests/rendering.ts',
'src/codeql-cli/scripts/convert-markdown-for-docs.ts',
'src/content-linter/lib/helpers/get-lintable-yml.ts',
'src/content-linter/lib/helpers/print-annotations.ts',
Expand Down Expand Up @@ -229,16 +228,11 @@ export default [
'src/content-render/unified/index.ts',
'src/content-render/unified/module-types.d.ts',
'src/content-render/unified/rewrite-local-links.ts',
'src/data-directory/lib/data-directory.ts',
'src/data-directory/lib/data-schemas/learning-tracks.ts',
'src/data-directory/lib/get-data.ts',
'src/data-directory/scripts/find-orphaned-features/find.ts',
'src/early-access/scripts/migrate-early-access-product.ts',
'src/early-access/scripts/what-docs-early-access-branch.ts',
'src/fixtures/tests/categories-and-subcategory.ts',
'src/fixtures/tests/guides.ts',
'src/fixtures/tests/liquid.ts',
'src/fixtures/tests/markdown.ts',
'src/fixtures/tests/translations.ts',
'src/frame/components/context/ArticleContext.tsx',
'src/frame/components/context/CategoryLandingContext.tsx',
Expand All @@ -258,13 +252,10 @@ export default [
'src/github-apps/lib/index.ts',
'src/graphql/lib/index.ts',
'src/graphql/pages/reference.tsx',
'src/graphql/scripts/build-changelog.ts',
'src/graphql/scripts/utils/process-previews.ts',
'src/graphql/scripts/utils/process-schemas.ts',
'src/graphql/scripts/utils/schema-helpers.ts',
'src/graphql/tests/validate-schema.ts',
'src/journeys/lib/journey-path-resolver.ts',
'src/journeys/middleware/journey-track.ts',
'src/landings/components/CookBookFilter.tsx',
'src/landings/components/ProductGuidesContext.tsx',
'src/landings/components/ProductLandingContext.tsx',
Expand All @@ -274,13 +265,10 @@ export default [
'src/languages/lib/correct-translation-content.ts',
'src/languages/lib/render-with-fallback.ts',
'src/languages/lib/translation-utils.ts',
'src/learning-track/lib/process-learning-tracks.ts',
'src/links/lib/update-internal-links.ts',
'src/links/scripts/check-github-github-links.ts',
'src/links/scripts/update-internal-links.ts',
'src/links/tests/extract-links.ts',
'src/pages/_error.tsx',
'src/products/tests/get-product-groups.ts',
'src/redirects/middleware/handle-redirects.ts',
'src/rest/components/get-rest-code-samples.ts',
'src/rest/lib/index.ts',
Expand Down Expand Up @@ -319,13 +307,8 @@ export default [
'src/types/markdownlint-rule-helpers.d.ts',
'src/types/markdownlint-rule-search-replace.d.ts',
'src/types/primer__octicons.d.ts',
'src/versions/scripts/update-versioning-in-files.ts',
'src/versions/scripts/use-short-versions.ts',
'src/webhooks/lib/index.ts',
'src/webhooks/scripts/webhook.ts',
'src/workflows/content-changes-table-comment.ts',
'src/workflows/fr-add-docs-reviewers-requests.ts',
'src/workflows/git-utils.ts',
'src/workflows/projects.ts',
'src/workflows/tests/actions-workflows.ts',
],
Expand Down
4 changes: 2 additions & 2 deletions src/automated-pipelines/tests/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type Page = {
fullPath: string
permalinks: Array<{ href: string }>
versions: {
feature?: any
[key: string]: any
feature?: string | string[]
[key: string]: string | string[] | undefined
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/data-directory/lib/data-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface DataDirectoryOptions {
}

interface DataDirectoryResult {
[key: string]: any
[key: string]: unknown
}

export default function dataDirectory(
Expand Down
2 changes: 1 addition & 1 deletion src/data-directory/lib/data-schemas/learning-tracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { schema } from '@/frame/lib/frontmatter'

// Some learning tracks have `versions` blocks that match `versions` frontmatter,
// so we can import that part of the FM schema.
const versionsProps = Object.assign({}, (schema.properties as any).versions)
const versionsProps = Object.assign({}, schema.properties.versions)

// `versions` are not required in learning tracks the way they are in FM.
delete versionsProps.required
Expand Down
2 changes: 1 addition & 1 deletion src/data-directory/scripts/find-orphaned-features/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function escapeRegex(string: string) {
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')
}

function isFloat(x: any) {
function isFloat(x: string | number) {
return !!(Number(x) + 1)
}
strictEqual(isFloat('1.2'), true)
Expand Down
2 changes: 1 addition & 1 deletion src/data-directory/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('data-directory', () => {
return content.replace('markdown', 'MARKDOWN')
}
const data = dataDirectory(fixturesDir, { preprocess })
expect(data.nested.baz).toBe('I am MARKDOWN!')
expect((data.nested as Record<string, unknown>).baz).toBe('I am MARKDOWN!')
})

test('option: extensions array', async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/fixtures/tests/liquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ describe('rowheaders', () => {
// `scope` attribute.
// See "Scope attribute should be used correctly on tables"
// https://dequeuniversity.com/rules/axe/4.1/scope-attr-valid?application=RuleDescription
$('thead th', firstTable).each((i: number, element: any) => {
$('thead th', firstTable).each((i, element) => {
expect($(element).attr('scope')).toBe('col')
})
$('tbody th', firstTable).each((i: number, element: any) => {
$('tbody th', firstTable).each((i, element) => {
expect($(element).attr('scope')).toBe('row')
})
// The 5 here is the other `expect(...)` that happens before these
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('misc Liquid', () => {
const links = $(`#article-contents a[href="${url}"]`)
expect(links.length).toBe(2)
const texts = links
.map((i: number, element: any) => {
.map((i, element) => {
return $(element).text()
})
.get()
Expand Down Expand Up @@ -293,7 +293,7 @@ describe('data tag', () => {
// But because `{% data reusables.injectables.paragraphs %}` is
// inserted with some indentation, that's replicated on every line.
const li = $('#article-contents li')
.filter((_: number, element: any) => {
.filter((_, element) => {
return $(element).text().trim().startsWith('Point 1')
})
.eq(0)
Expand Down
4 changes: 2 additions & 2 deletions src/fixtures/tests/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe('alerts', () => {
const svgs = $('svg', alerts)
expect(svgs.length).toBe(5)
const titles = $('.ghd-alert-title', alerts)
.map((_: number, el: any) => $(el).text())
.map((_, el) => $(el).text())
.get()
expect(titles).toEqual(['Tip', 'Note', 'Important', 'Warning', 'Caution'])
const bodies = $('p:nth-child(2)', alerts)
.map((_: number, el: any) => $(el).text())
.map((_, el) => $(el).text())
.get()
.map((s: string) => s.trim())
expect(bodies).toEqual([
Expand Down
11 changes: 6 additions & 5 deletions src/graphql/scripts/build-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ interface IgnoredChangesSummary {
types: IgnoredChangeType[]
}

let lastIgnoredChanges: Change[] = []

/**
* Tag `changelogEntry` with `date: YYYY-mm-dd`, then prepend it to the JSON
* structure written to `targetPath`. (`changelogEntry` and that file are modified in place.)
Expand Down Expand Up @@ -89,9 +91,8 @@ export async function createChangelogEntry(
newUpcomingChanges: UpcomingChange[],
): Promise<ChangelogEntry | null> {
// Create schema objects out of the strings
// Using 'as any' because loadSchema accepts string schema directly without requiring loaders
const oldSchema = await loadSchema(oldSchemaString, {} as any)
const newSchema = await loadSchema(newSchemaString, {} as any)
const oldSchema = await loadSchema(oldSchemaString, { loaders: [] })
const newSchema = await loadSchema(newSchemaString, { loaders: [] })

// Generate changes between the two schemas
const changes = await diff(oldSchema, newSchema)
Expand Down Expand Up @@ -122,7 +123,7 @@ export async function createChangelogEntry(
}

// Store ignored changes for potential workflow outputs
;(createChangelogEntry as any).lastIgnoredChanges = ignoredChanges
lastIgnoredChanges = ignoredChanges

const { schemaChangesToReport, previewChangesToReport } = segmentPreviewChanges(
changesToReport,
Expand Down Expand Up @@ -333,7 +334,7 @@ const CHANGES_TO_REPORT = [
* Get the ignored change types from the last changelog entry creation
*/
export function getLastIgnoredChanges(): Change[] {
return (createChangelogEntry as any).lastIgnoredChanges || []
return lastIgnoredChanges
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/scripts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ interface IgnoredChange {

interface RawPreview {
title: string
description?: string
toggled_on: string[]
toggled_by: string
announcement?: unknown
updates?: unknown
owning_teams?: string[]
}

interface UpcomingChangeEntry {
Expand Down
37 changes: 21 additions & 16 deletions src/graphql/scripts/utils/process-previews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import GithubSlugger from 'github-slugger'

interface RawPreview {
title: string
description?: string
toggled_on: string[]
toggled_by: string
announcement?: unknown
updates?: unknown
owning_teams?: string[]
}

interface ProcessedPreview extends Omit<RawPreview, 'announcement' | 'updates'> {
Expand All @@ -18,35 +20,38 @@ const slugger = new GithubSlugger()
const inputOrPayload = /(Input|Payload)$/m

export default function processPreviews(previews: RawPreview[]): ProcessedPreview[] {
// clean up raw yml data
// Using any type because we're mutating the preview object to add new properties
// that don't exist in the RawPreview interface (accept_header, href)
for (const preview of previews as any[]) {
preview.title = sentenceCase(preview.title)
return previews.map((raw) => {
let title = sentenceCase(raw.title)
.replace(/ -.+/, '') // remove any extra info that follows a hyphen
.replace('it hub', 'itHub') // fix overcorrected `git hub` from sentenceCasing
.replace(' s ', "'s ") // sentenceCase replaces apostrophes with spaces

// Add `preview` to the end of titles if needed
preview.title = preview.title.endsWith('preview') ? preview.title : `${preview.title} preview`
title = title.endsWith('preview') ? title : `${title} preview`

// filter out schema members that end in `Input` or `Payload`
preview.toggled_on = preview.toggled_on.filter(
const toggled_on = raw.toggled_on.filter(
(schemaMember: string) => !inputOrPayload.test(schemaMember),
)

// remove unnecessary leading colon
preview.toggled_by = preview.toggled_by.replace(':', '')
const toggled_by = raw.toggled_by.replace(':', '')

// add convenience properties
preview.accept_header = `application/vnd.github.${preview.toggled_by}+json`

delete preview.announcement
delete preview.updates
const accept_header = `application/vnd.github.${toggled_by}+json`

slugger.reset()
preview.href = `/graphql/overview/schema-previews#${slugger.slug(preview.title)}`
}

return previews as ProcessedPreview[]
const href = `/graphql/overview/schema-previews#${slugger.slug(title)}`

// Preserve all original properties except announcement/updates
return {
title,
description: raw.description,
toggled_on,
toggled_by,
owning_teams: raw.owning_teams,
accept_header,
href,
}
})
}
34 changes: 26 additions & 8 deletions src/journeys/middleware/journey-track.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import type { Response, NextFunction } from 'express'
import type { ExtendedRequest, Context } from '@/types'
import type { ExtendedRequest, Context, Page } from '@/types'

import {
resolveJourneyTracks,
resolveJourneyContext,
JourneyTrack,
} from '../lib/journey-path-resolver'

type JourneyTrackData = {
id: string
title: string
description?: string
guides: Array<{
href: string
alternativeNextStep?: string
}>
}

import { resolveJourneyTracks, resolveJourneyContext } from '../lib/journey-path-resolver'
type PageWithJourneys = Page & {
journeyTracks?: JourneyTrackData[]
resolvedJourneyTracks?: JourneyTrack[]
}

export default async function journeyTrack(
req: ExtendedRequest & { context: Context },
Expand All @@ -14,15 +33,14 @@ export default async function journeyTrack(
if (!req.context.page) return next()

try {
const page = req.context.page as PageWithJourneys

// If this page has journey tracks defined, resolve them for the landing page
if ((req.context.page as any).journeyTracks) {
const resolvedTracks = await resolveJourneyTracks(
(req.context.page as any).journeyTracks,
req.context,
)
if (page.journeyTracks) {
const resolvedTracks = await resolveJourneyTracks(page.journeyTracks, req.context)

// Store resolved tracks on the page context for later use in getServerSideProps
;(req.context.page as any).resolvedJourneyTracks = resolvedTracks
page.resolvedJourneyTracks = resolvedTracks
}

// Always try to resolve journey context (for navigation on guide articles)
Expand Down
Loading