Fetch a GitHub user's profile: bio, company, followers and their top repositories.
{"username":"string (the GitHub login, e.g. 'torvalds')"}{"login":"string","name":"string|null","bio":"string|null","company":"string|null","location":"string|null","blog":"string|null","followers":"int","following":"int","publicRepos":"int","url":"url","topRepos":"array of { full_name, stars, language, url }"}Fetch a GitHub user's profile via the public REST API (api.github.com), plus their most-starred public repositories. Param: username (the GitHub login, e.g. 'torvalds'). Returns {login, name, bio, company, location, blog, followers, following, publicRepos, url, topRepos:[{full_name, stars, language, url}]}. Read-only, no auth needed.
params. It does the in-page work and returns the JSON in returns.( async (root, params) => { const u = String((params && params.username) || '').trim().replace(/^@/, '').replace(/^https?://github.com//, '').split('/')[0]; if (!u) throw new Error('missing username'); const H = { 'accept': 'application/vnd.github+json', 'x-github-api-version': '2022-11-28' }; const r = await fetch('https://api.github.com/users/' + encodeURIComponent(u), { headers: H }); if (r.status === 404) return { error: 'user not found: ' + u }; if (r.status === 403) return { error: 'rate limited. Try again in a minute.' }; const d = await r.json(); let topRepos = []; try { const rr = await fetch('https://api.github.com/users/' + encodeURIComponent(u) + '/repos?sort=updated&per_page=100', { headers: H }); const list = await rr.json(); if (Array.isArray(list)) topRepos = list.filter(x => !x.fork).sort((a, b) => b.stargazers_count - a.stargazers_count).slice(0, 5).map(x => ({ full_name: x.full_name, stars: x.stargazers_count, language: x.language || null, url: x.html_url })); } catch (e) {} return { login: d.login, name: d.name || null, bio: d.bio || null, company: d.company || null, location: d.location || null, blog: d.blog || null, followers: d.followers, following: d.following, publicRepos: d.public_repos, url: d.html_url, topRepos }; } )
{
"expr": "typeof result === 'object' && (result.login || result.error)",
"type": "value"
}