Skip to content

Repository files navigation

🐙 @rodbe/github-api

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.

📦 Installation

npm install @rodbe/github-api
# or
pnpm add @rodbe/github-api

✅ Requirements

📖 API

All functions accept a token parameter (GitHub personal access token) and an optional mapper function to transform each item in the response.

getOrgs({ token, mapper? }) 🏢

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[] }


getReposByUser({ token, mapper? }) 👤

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[]


getReposByOrg({ token, org, mapper? }) 🏗️

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[]


getReposByOrgs({ token, orgs, mapper? }) 🏗️🏗️

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[]>


getStarredRepos({ token, mapper? })

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[]


🔄 Custom mappers

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}),});

🧩 Types

The following types are exported and can be used in your own code:

TypeDescription
OrganizationGitHub organization object
UserRepositoryRepository returned by user endpoints
OrgRepositoryRepository returned by org endpoints
OwnerRepository owner object
PermissionsRepository permissions object
LicenseRepository license object

📄 License

MIT

About

Typed and customizable wrapper 💫 for the GitHub API 🐙

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages