Typed and customizable wrapper for the GitHub REST API. Handles pagination automatically and supports custom mappers to transform responses into the shape your app needs.
npm install @rodbe/github-api
# or
pnpm add @rodbe/github-api- Node.js >= 18.18.2
- A GitHub personal access token 🔑
All functions accept a token parameter (GitHub personal access token) and an optional mapper function to transform each item in the response.
Fetches all organizations for the authenticated user. Handles pagination automatically.
import{getOrgs}from'@rodbe/github-api';const{ organizations, errors }=awaitgetOrgs({token: 'ghp_...'});// With a custom mapperconst{ organizations }=awaitgetOrgs({token: 'ghp_...',mapper: org=>({id: org.id,name: org.login,avatar: org.avatar_url}),});Returns:{ organizations: T[], errors: Error[] }
Fetches all repositories for the authenticated user (owned, member, forked, etc.).
import{getReposByUser}from'@rodbe/github-api';constrepos=awaitgetReposByUser({token: 'ghp_...'});// With a custom mapperconstrepos=awaitgetReposByUser({token: 'ghp_...',mapper: repo=>({name: repo.name,isPrivate: repo.private,stars: repo.stargazers_count}),});Returns:T[]
Fetches all repositories for a specific organization.
import{getReposByOrg}from'@rodbe/github-api';constrepos=awaitgetReposByOrg({token: 'ghp_...',org: 'my-org'});// With a custom mapperconstrepos=awaitgetReposByOrg({token: 'ghp_...',org: 'my-org',mapper: repo=>({name: repo.name,url: repo.html_url}),});Returns:T[]
Fetches repositories for multiple organizations in a single call. Returns a record keyed by org name.
import{getReposByOrgs}from'@rodbe/github-api';constresult=awaitgetReposByOrgs({token: 'ghp_...',orgs: ['org-a','org-b'],});result['org-a'];// OrgRepository[]result['org-b'];// OrgRepository[]// With a custom mapperconstresult=awaitgetReposByOrgs({token: 'ghp_...',orgs: ['org-a','org-b']asconst,mapper: repo=>repo.name,});Returns:Record<Org, T[]>
Fetches all repositories starred by the authenticated user.
import{getStarredRepos}from'@rodbe/github-api';conststarred=awaitgetStarredRepos({token: 'ghp_...'});// With a custom mapperconststarred=awaitgetStarredRepos({token: 'ghp_...',mapper: repo=>({name: repo.name,language: repo.language}),});Returns:T[]
Every function accepts an optional mapper callback that receives the raw GitHub API object and returns a value of any shape. The return type of the function is inferred automatically from the mapper's return type.
// Without mapper → returns UserRepository[]constrepos=awaitgetReposByUser({ token });// With mapper → returns { name: string; stars: number }[]constrepos=awaitgetReposByUser({
token,mapper: repo=>({name: repo.name,stars: repo.stargazers_count}),});The following types are exported and can be used in your own code:
| Type | Description |
|---|---|
Organization | GitHub organization object |
UserRepository | Repository returned by user endpoints |
OrgRepository | Repository returned by org endpoints |
Owner | Repository owner object |
Permissions | Repository permissions object |
License | Repository license object |
MIT