Skip to main content

Get Repository Files

Retrieves all files from a GitHub repository.
GET /api/repo-files

Query Parameters

owner
string
required
The repository owner (user or organization)
repo
string
required
The repository name

Response

files
string[]
Array of file paths in the repository
defaultBranch
string
The default branch name (e.g., “main” or “master”)

Example Request

curl "https://yourdomain.com/api/repo-files?owner=octocat&repo=Hello-World"

Example Response

{
  "files": [
    "README.md",
    "src/index.ts",
    "src/utils/helper.ts",
    "package.json"
  ],
  "defaultBranch": "main"
}

Error Responses


Get Organization Repositories

Retrieves repositories belonging to a GitHub organization.
GET /api/org-repos

Query Parameters

org
string
required
The organization name

Response

repos
object[]
Array of repository objects

Example Request

curl "https://yourdomain.com/api/org-repos?org=github"

Example Response

{
  "repos": [
    {
      "name": "docs",
      "full_name": "github/docs",
      "description": "The open-source repo for docs.github.com",
      "stargazers_count": 15234,
      "private": false
    },
    {
      "name": "gitignore",
      "full_name": "github/gitignore",
      "description": "A collection of useful .gitignore templates",
      "stargazers_count": 156789,
      "private": false
    }
  ]
}

Error Responses


Get User Repositories

Retrieves repositories for the authenticated user.
GET /api/user-repos

Query Parameters

No query parameters required. This endpoint uses the authenticated user’s session.

Response

repos
object[]
Array of repository objects

Example Request

curl "https://yourdomain.com/api/user-repos" \
  -H "Cookie: your-session-cookie"

Example Response

{
  "repos": [
    {
      "id": 123456789,
      "full_name": "octocat/Hello-World",
      "description": "My first repository on GitHub!",
      "language": "JavaScript",
      "stargazers_count": 42,
      "owner": {
        "login": "octocat",
        "avatar_url": "https://github.com/images/error/octocat_happy.gif"
      }
    }
  ]
}

Get File Content

Retrieves the content of a specific file from a GitHub repository with optional syntax highlighting.
GET /api/file-content

Query Parameters

owner
string
required
The repository owner (user or organization)
repo
string
required
The repository name
path
string
required
The file path within the repository
ref
string
The branch, tag, or commit SHA to read from. Defaults to the repository’s default branch.
highlight
boolean
Whether to include syntax highlighting tokens. Set to true to enable.

Response

content
string
The raw file content
sha
string
The Git SHA of the file
tokens
array
Syntax highlighting tokens (only included if highlight=true). Array of token objects for rendering highlighted code.

Example Request

curl "https://yourdomain.com/api/file-content?owner=octocat&repo=Hello-World&path=README.md"

Example Response

{
  "content": "# Hello World\n\nThis is a sample repository.",
  "sha": "a1b2c3d4e5f6",
  "tokens": [
    {
      "content": "#",
      "style": { "color": "#6A9955" }
    },
    {
      "content": " Hello World",
      "style": { "color": "#6A9955" }
    }
  ]
}

Error Responses

Notes

  • All repository endpoints leverage the GitHub API integration defined in /lib/github.ts
  • File content is decoded from base64 when retrieved from GitHub
  • Syntax highlighting uses Shiki with support for 100+ languages
  • The path parameter is automatically URL-decoded to handle special characters
  • Repositories are sorted by most recently pushed (for org repos) or most recently updated (for user repos)
  • The /api/org-repos endpoint fetches up to 100 repositories per request
  • The /api/user-repos endpoint fetches up to 100 repositories sorted by update time
  • Authentication is handled via session cookies for user-specific endpoints