octonode
octonode is a library for nodejs to access the github v3 api
Installation
npm install octonode
Usage
var github = ; // Then we instanciate a client with or without a token (as show in a later section) var ghme = client;var ghuser = client;var ghrepo = client;var ghorg = client;var ghgist = client;var ghteam = client; var ghsearch = client;
Build a client which accesses any public information
var client = github; client;
Build a client from an access token
var client = github; client;
Build a client from credentials
var client = github; client;
Build a client from client keys
var client = github; client;
Many of the below use cases use parts of the above code
Authentication
Authenticate to github in cli mode (desktop application)
githubauth;
Revoke authentication to github in cli mode (desktop application)
githubauth;
Authenticate to github in web mode (web application)
// Web application which authenticates to githubvar http = url = qs = github = ; // Build the authorization config and urlvar auth_url = githubauth; // Store info to verify against CSRFvar state = auth_url; // Web serverhttp; console;
Rate Limiting
You can also check your rate limit status by calling the following.
client;
API Callback Structure
All the callbacks for the following will take first an error argument, then a data argument, like this:
ghme;
Github authenticated user api
Token/Credentials required for the following:
Get information about the user (GET /user)
ghme; //json
Update user profile (PATCH /user)
ghme;
Get emails of the user (GET /user/emails)
ghme; //array of emails
Set emails of the user (POST /user/emails)
ghme; //array of emailsghme; //array of emails
Delete emails of the user (DELETE /user/emails)
ghme;ghme;
Get the followers of the user (GET /user/followers)
ghme; //array of github users
Get users whom the user is following (GET /user/following)
ghme; //array of github users
Check if the user is following a user (GET /user/following/marak)
ghme; //boolean
Follow a user (PUT /user/following/marak)
ghme;
Unfollow a user (DELETE /user/following/marak)
ghme;
Get public keys of a user (GET /user/keys)
ghme; //array of keys
Get a single public key (GET /user/keys/1)
ghme; //key
Create a public key (POST /user/keys)
ghme; //key
Update a public key (PATCH /user/keys/1)
ghme; //key
Delete a public key (DELETE /user/keys/1)
ghme;
List your public and private organizations (GET /user/orgs)
ghme; // array of orgs
List your repositories (GET /user/repos)
ghme; //array of repos
Create a repository (POST /user/repos)
ghme; //repo
Fork a repository (POST /repos/pksunkara/hub/forks)
ghme; //forked repo
Github users api
No token required for the following
Get information about a user (GET /users/pksunkara)
ghuser; //json
Get user followers (GET /users/pksunkara/followers)
ghuser; //array of github users
Get user followings (GET /users/pksunkara/following)
ghuser; //array of github users
Get user organizations (GET /users/pksunkara/orgs)
ghuser; //array of organizations
Github repositories api
Get information about a repository (GET /repos/pksunkara/hub)
ghrepo; //json
Get the collaborators for a repository (GET /repos/pksunkara/hub/collaborators)
ghrepo; //array of github users
Check if a user is collaborator for a repository (GET /repos/pksunkara/hub/collaborators/marak)
ghrepo; //boolean
Get the commits for a repository (GET /repos/pksunkara/hub/commits)
ghrepo; //array of commits
Get the tags for a repository (GET /repos/pksunkara/hub/tags)
ghrepotagscallback; //array of tags
Get the languages for a repository (GET /repos/pksunkara/hub/languages)
ghrepo; //array of languages
Get the contributors for a repository (GET /repos/pksunkara/hub/contributors)
ghrepo; //array of github users
Get the branches for a repository (GET /repos/pksunkara/hub/branches)
ghrepo; //array of branches
Get the issues for a repository (GET /repos/pksunkara/hub/issues)
Issues are arranged in pages. The page argument is optional and is used to specify which page of issues to retrieve. The perPage argument is also optional and is used to specify how many issues per page. Alternatively, you can pass in parameters as an object.
ghrepo; //array of issuesghrepo; //array of first 100 issuesghrepo; //array of 30 issues from page 10ghrepo; //array of first 30 issuesghrepo; //array of issues from page 2 of all closed issues
Get the README for a repository (GET /repos/pksunkara/hub/readme)
ghrepo; //fileghrepo; //file
Get the contents of a path in repository
ghrepo; //pathghrepo; //path
Get archive link for a repository
ghrepoarchive'tarball' callback; //link to archiveghrepoarchive'zipball' 'v0.1.0' callback; //link to archive
Get the blob for a repository (GET /repos/pksunkara/hub/git/blobs/SHA)
ghrepo; //blob
Get users who starred a repository (GET /repos/pksunkara/hub/stargazers)
ghrepo; //array of usersghrepo; //array of usersghrepo; //array of users
Get the teams for a repository (GET /repos/pksunkara/hub/teams)
ghrepo; //array of teams
Get a git tree (GET /repos/pksunkara/hub/git/trees/18293abcd72)
ghrepo; //treeghrepo; //recursive tree
Delete the repository (DELETE /repos/pksunkara/hub)
ghrepo;
List statuses for a specific ref (GET /repos/pksunkara/hub/statuses/master)
ghrepo; // array of statuses
Create status (POST /repos/pksunkara/hub/statuses/SHA)
ghrepostatus'18e129c213848c7f239b93fe5c67971a64f183ff' "state": "success" "target_url": "http://ci.mycompany.com/job/hub/3" "description": "Build success." callback; // created status
Github organizations api
Get information about an organization (GET /orgs/flatiron)
ghorg; //json
Update an organization (POST /orgs/flatiron)
ghorg; // org
List organization repositories (GET /orgs/flatiron/repos)
ghorg; //array of repos
Create an organization repository (POST /orgs/flatiron/repos)
ghorg; //repo
Get an organization's teams (GET /orgs/flatiron/teams)
ghorg; //array of teams
Get an organization's members (GET /orgs/flatiron/members)
ghorg; //array of github users
Check an organization member (GET /orgs/flatiron/members/pksunkara)
ghorg; //boolean
Github gists api
List authenticated user's gists (GET /gists)
ghgist; //array of gists
List authenticated user's public gists (GET /gists/public)
ghgist; //array of gists
List authenticated user's starred gists (GET /gists/starred)
ghgist; //array of gists
List a user's public gists (GET /users/pksunkara/gists)
ghgist; //array of gists
Get a single gist (GET /gists/37)
ghgist; //gist
Create a gist (POST /gists)
ghgist callback); //gist
Edit a gist (PATCH /gists/37)
ghgist; //gist
Delete a gist (DELETE /gists/37)
ghgist;
Fork a gist (POST /gists/37/forks)
ghgist; //gist
Star a gist (PUT /gists/37/star)
ghgist;
Unstar a gist (DELETE /gists/37/unstar)
ghgist;
Check if a gist is starred (GET /gists/37/star)
ghgist; //boolean
List comments on a gist (GET /gists/37/comments)
ghgist; //array of comments
Create a comment (POST /gists/37/comments)
ghgist; //comment
Get a single comment (GET /gists/comments/1)
ghgist; //comment
Edit a comment (POST /gists/comments/1)
ghgist; //comment
Delete a comment (DELETE /gists/comments/1)
ghgist;
Github teams api
Get a team (GET /team/37)
ghteam; //json
Get the team members (GET /team/37/members)
ghteam; //array of github users
Check if a user is part of the team (GET /team/37/members/pksunkara)
ghteam; //boolean
Github search api
Search issues
ghsearch; //array of issues
Search repositories
ghsearch; //array of repositories
Search users
ghsearch; //array of users
Search emails
ghsearch; //user
Testing
npm test
If you like this project, please watch this and follow me.
Contributors
Here is a list of Contributors
TODO
The following method names use underscore as an example. The library contains camel cased method names.
// public repos for unauthenticated, private and public for authenticatedme;me;me;me;me; // organization datavar org = octonode; org;org;org;org;org;org;org; org;org;org;org;org;org;org;org;org;org;org;org;org; var repo = octonode; repo; // collaborator informationrepo;repo; // commit datarepo;repo;repo;repo;repo;repo;repo; // downloadsrepo;repo;repo;repo; // keysrepo;repo;repo;repo;repo; // watcher datarepo; // pull requestsrepo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo;repo; // raw git accessrepo;repo;repo;repo;repo;repo;repo;
I accept pull requests and guarantee a reply back within a day
License
MIT/X11
Bug Reports
Report here. Guaranteed reply within a day.
Contact
Pavan Kumar Sunkara (pavan.sss1991@gmail.com)