mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
fix(Docs): Migrate the rest of the raw.githubcontent calls to new util (#44274)
This commit is contained in:
1 parent
2fd49395b8
commit
5e6e2ec0c1
4 files changed
+29
-38
No files matched your search
@@ -16,14 +16,13 @@ import {
|
||||
removeRedundantH1,
|
||||
} from '~/features/docs/GuidesMdx.utils'
|
||||
import { newEditLink } from '~/features/helpers.edit-link'
|
||||
import { REVALIDATION_TAGS } from '~/features/helpers.fetch'
|
||||
import { Guide, GuideArticle, GuideFooter, GuideHeader, GuideMdxContent } from '~/features/ui/guide'
|
||||
import { GUIDES_DIRECTORY, isValidGuideFrontmatter } from '~/lib/docs'
|
||||
import { linkTransform, type UrlTransformFunction } from '~/lib/mdx/plugins/rehypeLinkTransform'
|
||||
import remarkMkDocsAdmonition from '~/lib/mdx/plugins/remarkAdmonition'
|
||||
import { removeTitle } from '~/lib/mdx/plugins/remarkRemoveTitle'
|
||||
import remarkPyMdownTabs from '~/lib/mdx/plugins/remarkTabs'
|
||||
import { octokit } from '~/lib/octokit'
|
||||
import { getGitHubFileContents, octokit } from '~/lib/octokit'
|
||||
import type { SerializeOptions } from '~/types/next-mdx-remote-serialize'
|
||||
|
||||
// We fetch these docs at build time from an external repo
|
||||
@@ -85,13 +84,6 @@ async function getLatestRelease(after: string | null = null) {
|
||||
owner: org,
|
||||
name: repo,
|
||||
after,
|
||||
request: {
|
||||
fetch: (url: RequestInfo | URL, options?: RequestInit) =>
|
||||
fetch(url, {
|
||||
...options,
|
||||
next: { tags: [REVALIDATION_TAGS.WRAPPERS] },
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
@@ -357,26 +349,14 @@ const getContent = async (params: Params) => {
|
||||
throw new Error('No latest release found for federated wrappers pages')
|
||||
}
|
||||
|
||||
const repoPath = `${org}/${repo}/${tag}/${docsDir}/${remoteFile}`
|
||||
editLink = `${org}/${repo}/blob/${tag}/${docsDir}/${remoteFile}`
|
||||
|
||||
let response: Response
|
||||
try {
|
||||
response = await fetch(`https://raw.githubusercontent.com/${repoPath}`, {
|
||||
cache: 'force-cache',
|
||||
next: { tags: [REVALIDATION_TAGS.WRAPPERS] },
|
||||
})
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to fetch wrappers docs from GitHub (network error): ${err}`)
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch wrappers docs from GitHub: ${response.status} ${response.statusText}`
|
||||
)
|
||||
}
|
||||
|
||||
const rawContent = await response.text()
|
||||
let rawContent = await getGitHubFileContents({
|
||||
org,
|
||||
repo,
|
||||
path: `${docsDir}/${remoteFile}`,
|
||||
branch: tag,
|
||||
})
|
||||
|
||||
assetsBaseUrl = `https://raw.githubusercontent.com/${org}/${repo}/${tag}/docs/assets/`
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export const OCTOKIT_RETRY_OPTIONS = {
|
||||
retries: 5,
|
||||
retryAfter: 1,
|
||||
} as const
|
||||
@@ -6,14 +6,12 @@ import { retry } from '@octokit/plugin-retry'
|
||||
import crypto from 'node:crypto'
|
||||
|
||||
import { fetchRevalidatePerDay } from '~/features/helpers.fetch'
|
||||
import { OCTOKIT_RETRY_OPTIONS } from './octokit.constants'
|
||||
|
||||
export { OCTOKIT_RETRY_OPTIONS }
|
||||
|
||||
const RetryOctokit = Octokit.plugin(retry)
|
||||
|
||||
export const OCTOKIT_RETRY_OPTIONS = {
|
||||
retries: 5,
|
||||
retryAfter: 1,
|
||||
} as const
|
||||
|
||||
let octokitInstance: InstanceType<typeof RetryOctokit>
|
||||
|
||||
export function octokit() {
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { createAppAuth } from '@octokit/auth-app'
|
||||
import { Octokit } from '@octokit/core'
|
||||
import { retry } from '@octokit/plugin-retry'
|
||||
import crypto, { createHash } from 'node:crypto'
|
||||
import { OCTOKIT_RETRY_OPTIONS } from '../../../lib/octokit.constants.js'
|
||||
import { BaseLoader, BaseSource } from './base.js'
|
||||
|
||||
const RetryOctokit = Octokit.plugin(retry)
|
||||
|
||||
const appId = process.env.DOCS_GITHUB_APP_ID
|
||||
const installationId = process.env.DOCS_GITHUB_APP_INSTALLATION_ID
|
||||
const privateKey = process.env.DOCS_GITHUB_APP_PRIVATE_KEY
|
||||
@@ -28,7 +32,7 @@ export class LintWarningsGuideLoader extends BaseLoader {
|
||||
throw new Error('Missing DOCS_GITHUB_APP_* environment variables')
|
||||
}
|
||||
|
||||
const octokit = new Octokit({
|
||||
const octokit = new RetryOctokit({
|
||||
authStrategy: createAppAuth,
|
||||
auth: {
|
||||
appId,
|
||||
@@ -42,6 +46,7 @@ export class LintWarningsGuideLoader extends BaseLoader {
|
||||
repo: this.repo,
|
||||
path: this.docsDir,
|
||||
ref: this.branch,
|
||||
request: OCTOKIT_RETRY_OPTIONS,
|
||||
headers: {
|
||||
'X-GitHub-Api-Version': '2022-11-28',
|
||||
},
|
||||
@@ -62,15 +67,19 @@ export class LintWarningsGuideLoader extends BaseLoader {
|
||||
// Fetch all lint files and combine them into a single guide
|
||||
const lints = await Promise.all(
|
||||
lintsList.map(async ({ path }) => {
|
||||
const fileResponse = await fetch(
|
||||
`https://raw.githubusercontent.com/${this.org}/${this.repo}/${this.branch}/${path}`
|
||||
)
|
||||
const fileResponse = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
|
||||
owner: this.org,
|
||||
repo: this.repo,
|
||||
path,
|
||||
ref: this.branch,
|
||||
request: OCTOKIT_RETRY_OPTIONS,
|
||||
})
|
||||
|
||||
if (fileResponse.status >= 400) {
|
||||
if (!('content' in fileResponse.data) || fileResponse.data.type !== 'file') {
|
||||
throw Error(`Could not get contents of file ${this.org}/${this.repo}/${path}`)
|
||||
}
|
||||
|
||||
const content = await fileResponse.text()
|
||||
const content = Buffer.from(fileResponse.data.content, 'base64').toString('utf-8')
|
||||
const basename = getBasename(path)
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user