Home / Function/ getGitHubFileContents() — supabase Function Reference

getGitHubFileContents() — supabase Function Reference

Architecture documentation for the getGitHubFileContents() function in octokit.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  fa70cd46_6219_d8e8_0dc2_82ecdff73892["getGitHubFileContents()"]
  ee8de8b7_e8af_56c2_fb6b_f0ff1d2a3bdd["getGitHubFileContentsImmutableOnly()"]
  ee8de8b7_e8af_56c2_fb6b_f0ff1d2a3bdd -->|calls| fa70cd46_6219_d8e8_0dc2_82ecdff73892
  849f251d_84e6_f75c_65e8_837d964c4544["octokit()"]
  fa70cd46_6219_d8e8_0dc2_82ecdff73892 -->|calls| 849f251d_84e6_f75c_65e8_837d964c4544
  style fa70cd46_6219_d8e8_0dc2_82ecdff73892 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/docs/lib/octokit.ts lines 37–86

async function getGitHubFileContents({
  org,
  repo,
  path,
  branch,
  options: { onError, fetch },
}: {
  org: string
  repo: string
  path: string
  branch: string
  options: {
    onError: (err?: unknown) => void
    /**
     *
     * A custom fetch implementation to control Next.js caching.
     * By default, uses a "once-per-day" revalidation strategy.
     * This default may change later as we move to on-demand revalidation.
     */
    fetch?: (info: RequestInfo, init?: RequestInit) => Promise<Response>
  }
}) {
  if (path.startsWith('/')) {
    path = path.slice(1)
  }

  try {
    const response = await octokit().request('GET /repos/{owner}/{repo}/contents/{path}', {
      owner: org,
      repo: repo,
      path: path,
      ref: branch,
      options: {
        fetch: fetch ?? fetchRevalidatePerDay,
      },
    })
    if (response.status !== 200 || !response.data) {
      throw Error(`Could not find contents of ${path} in ${org}/${repo}`)
    }
    if (!('type' in response.data) || response.data.type !== 'file') {
      throw Error(`${path} in ${org}/${repo} is not a file`)
    }
    const content = Buffer.from(response.data.content, 'base64').toString('utf-8')
    return content
  } catch (err) {
    console.error('Error fetching GitHub file: %o', err)
    onError?.(err)
    return ''
  }
}

Subdomains

Calls

Frequently Asked Questions

What does getGitHubFileContents() do?
getGitHubFileContents() is a function in the supabase codebase.
What does getGitHubFileContents() call?
getGitHubFileContents() calls 1 function(s): octokit.
What calls getGitHubFileContents()?
getGitHubFileContents() is called by 1 function(s): getGitHubFileContentsImmutableOnly.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free