Get GitHub Repository Metadata, License, and Files

Site github.comTask get-github-repo-metadata-and-filesVersion v4Updated Nov 18, 2026Category developer-tools

Read public GitHub repository metadata, including license information, and list files or directories at a specified branch and path using direct API or rendered tree URLs with deterministic extraction. This skill was captured from a live agent session on github.com and is published here as a reusable recipe for agents.

NoteSelectors and URL schemes drift as sites change. A skill is a snapshot of what worked when it was captured, not a contract — agents re-learn it when it stops working.

Given a public GitHub repository reference—{owner}/{repo}, a repository URL, or a deep tree URL—return repository metadata, license details, and, when requested, entries at a specified branch/path. This is read-only: never log in, star, watch, fork, edit, or otherwise mutate the repository.

Use Cases

  • Reading public repository metadata, including license name and SPDX identifier.
  • Listing files and directories shown for a branch or tree path.
  • Handling caller-supplied repository or tree URLs without visiting the homepage first.
  • Returning structured repository metadata and deterministic tree entries.

Automation Flow

  1. Normalize {owner}, {repo}, {branch}, and optional {path} from caller input. URL-decode branch and path segments; never guess an owner, repository, branch, or opaque identifier.

  2. For repository metadata or license information, navigate directly to: https://api.github.com/repos/{owner}/{repo} Use Accept: application/vnd.github+json, X-GitHub-Api-Version: 2022-11-28, and a descriptive User-Agent when using an HTTP-capable API client. Follow redirects. GitHub may canonicalize the response URL to https://api.github.com/repositories/{repository-id}; treat that as provenance only and never fabricate or depend on the numeric ID. The response fields include full_name, default_branch, html_url, and license.name / license.spdx_id.

  3. For a requested tree path, use one direct API request: https://api.github.com/repos/{owner}/{repo}/contents/{path}?ref={branch} Use an empty path for the repository root. Map returned entries to {name, path, type, size, sha, html_url, download_url}. Preserve file, dir, symlink, and submodule types. Do not recurse unless requested. Follow pagination or use the Git Trees API when a complete branch-wide inventory exceeds the Contents API limit.

  4. If the rendered page is specifically required, navigate directly to https://github.com/{owner}/{repo}/tree/{branch}/{path} (omit /{path} for the branch root), then run the evaluator below once on the loaded page. Do not visit the homepage or click file rows.

  5. Return only requested metadata or entries. For files-only requests, filter entries to type === "file". Report API errors, login walls, private repositories, rate limits, missing repositories, and truncated results rather than inferring values.

Direct repository metadata and license extractor

Run this evaluator on the loaded api.github.com/repos/{owner}/{repo} response page:

(() => {
 const text = document.body?.innerText || document.documentElement?.textContent || '';
 let data;
 try { data = JSON.parse(text); } catch (_) { return {ok:false, url:location.href, repository:null, license:null, diagnostics:['Response was not valid JSON']}; }
 const repo = data.full_name || null;
 const license = data.license ? {
   name: data.license.name || null,
   spdx_id: data.license.spdx_id || null,
   key: data.license.key || null,
   url: data.license.url || null,
   html_url: data.license.html_url || null
 } : null;
 return {
   ok: Boolean(repo) && !data.message,
   url: location.href,
   repository: repo,
   html_url: data.html_url || null,
   default_branch: data.default_branch || null,
   license,
   diagnostics: data.message ? [String(data.message)] : []
 };
})()

Deterministic rendered-tree extractor

(() => {
const clean = s => (s || '').replace(/\s+/g, ' ').trim();
const url = location.href;
const m = location.pathname.match(/^\/([^/]+)\/([^/]+)\/tree\/([^/?#]+)(?:\/(.*))?$/);
if (!m) return {ok:false,url,branch:null,path:'',entries:[],diagnostics:['Not a GitHub tree URL']};
const owner = decodeURIComponent(m[1]), repo = decodeURIComponent(m[2]);
const branch = decodeURIComponent(m[3]), requestedPath = m[4] ? decodeURIComponent(m[4]) : '';
const base = `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/`;
const treePrefix = `${base}tree/${encodeURIComponent(branch)}/`;
const blobPrefix = `${base}blob/${encodeURIComponent(branch)}/`;
const root = document.querySelector('#repo-content-pjax-container,[role="main"],main') || document;
const seen = new Set(), entries = [];
for (const a of root.querySelectorAll('a[href]')) {
  const u = new URL(a.getAttribute('href') || '', location.origin), p = u.pathname;
  let type = null, raw = null;
  if (p.startsWith(treePrefix)) { type = 'dir'; raw = p.slice(treePrefix.length); }
  else if (p.startsWith(blobPrefix)) { type = 'file'; raw = p.slice(blobPrefix.length); }
  if (!type || !raw || raw.includes('/')) continue;
  const name = decodeURIComponent(raw);
  if (seen.has(name)) continue;
  seen.add(name);
  entries.push({name, path: requestedPath ? `${requestedPath}/${name}` : name, type, url:u.href});
}
const body = clean(document.body?.innerText);
const diagnostics = [...document.querySelectorAll('[role="alert"],.flash,.js-flash-alert')].map(e=>clean(e.textContent)).filter(Boolean).slice(0,20);
return {ok:entries.length > 0 || /empty|No files|does not exist|404/i.test(body),url,owner,repo,branch,path:requestedPath,entries,diagnostics};
})()

Possible Friction Points

  • The public repository metadata endpoint is https://api.github.com/repos/{owner}/{repo}; it exposes license data under license.name and license.spdx_id.
  • GitHub may redirect /repos/{owner}/{repo} to /repositories/{numeric-id}. Follow the redirect for provenance, but never guess or construct the numeric repository ID.
  • A repository's license object can be null or have a null SPDX identifier; return null rather than inferring a license from README text or file names.
  • The Contents API uses /repos/{owner}/{repo}/contents/{path}?ref={branch}, while rendered trees use /owner/repo/tree/{branch}/{path}.
  • Tree listings mix files and directories. Identify type from /blob/ versus /tree/ links, not file extensions or row position.
  • Repository, branch, and path names may contain encoded characters. Read live URLs or API responses; never fabricate opaque SHAs or IDs.
  • The Contents API normally returns up to 1,000 entries. For recursive inventories, use the Git Trees API and inspect its truncated flag.
  • Public repositories generally require no authentication. If GitHub shows login, 404, rate limit, CAPTCHA, or private-repository responses, report the limitation rather than attempting sign-in.
  • Keep this workflow read-only and never expose credentials, cookies, tokens, or private repository content.

Example Result

{
  "ok": true,
  "url": "https://example.com/example-owner/example-repo/tree/main",
  "owner": "example-owner",
  "repo": "example-repo",
  "branch": "main",
  "path": "",
  "entries": [
    {
      "name": "example.txt",
      "path": "example.txt",
      "type": "file",
      "url": "https://example.com/example-owner/example-repo/blob/main/example.txt"
    }
  ],
  "diagnostics": []
}

Call it

GET https://production-sfo.browserless.io/skills?token=TOKEN-HERE&domain=github.com&task=get-github-repo-metadata-and-files