octocat.js
Javascript library to access the GitHub API.
- ✨ Promise based
- ✨ Support GitHub Enterprise
- ✨ Easy handling of paginated results
Installation
$ npm install octocat --save
Usage
Create an API client
const GitHub = ; // Using an access tokenconst client = token: 'my-access-token'; // Using an username/passwordconst client = username: 'SamyPesse' password: 'my-password'; // Connecting to an enterprise versionconst client = endpoint: 'https:///github.mycompany.com';
HTTP API access
All of these methods return promises.
client clientclientclientclientclient
These methods return a response
object that looks like:
// HTTP Status code statusCode: 200 // Type of status: 2XX, 3XX, 4xx statusType: '2XX' // Headers returned by the server headers: ... // Body of the request body: ...
In case of error, the response can also be accessible using as a response
property.
Pagination
Some methods of Octonode return paginated results. Check on GitHub which API methods are paginated.
These methods return a Page
object:
page.list
contains the list of results in the current pagepage.next()
update with the results of the next page (Promised)page.prev()
update with the results of the previous page (Promised)page.hasNext()
andpage.hasPrev()
page.all()
return all the results by recursively calling the API
Users
// Get a single userconst user = client;user; // Get the authenticated userconst user = client; // Edit the authenticated useruser
Repositories
// Create a new repositoryclient; // Get public repositories (paginated)client; // List user repositoriesuser; // Get a single repositoryconst repo = client;repo; // Compare two commitsrepo; // Perform a mergerepo; // Delete the repositoryrepo
Issues
// List issues for a repositoryrepo; // Create an issue in a repositoryrepo; // Get a single issue in a repositoryconst issue = repo;issue; // Edit an issueissue
Organization
// List organizations of an useruser; // Check an user's membership to an organizationuser; // List an user's memberships to all of his organizationsuser; // Get a single organizationconst org = client;org; // Edit the organizationorg // List members of the organizationorg; // Create a new repositoryorg;
Commits
// List commits for a repositoryrepo; // Get a single commitconst commit = repo;commit;
Statuses
// Create a Statusrepo; // List Statuses for a specific Refcommit;
Branches
// List branches for a repositoryrepo; // Get a single branchconst branch = repo;branch;
Tags
// List tags for a repositoryrepotags;
Webhooks
// List hooks for a repositoryrepo; // Get a single hookconst hook = repo;hook; // Edit a hookhook // Delete the hookhook
Releases
// List releases of a repositoryrepo; // Get details about the releaseconst release = repo;release; // Edit a releaserelease // Delete the releaserelease
Uploading assets
// Upload a new asset as file/streamrelease;release;
release.upload
will also notify with progress:
release;
Releases Assets
// List assets of a releaserelease; // Get details about the releaseconst asset = release;asset; // Download the asset to a fileasset; // Download the asset to a streamasset; // Delete the assetasset
Emails
// List email addressesclient; // Add email address(es)client; // Delete email address(es)client;
Authorization for a specific app
const app = client;const token = app; // Check an authorizationtoken; // Reset an authorizationtoken; // Delete an authorizationtoken;
Git Data
Reference
const ref = repo; // Get a referenceref; // Edit / Deleteref;ref;
Commit
const commit = repo; // Get a commitcommit;
Rate Limiting
You can also check your rate limit status by calling the following.
client