Octop
Octop provides a minimal higher-level wrapper around git's plumbing commands, exposing an API for manipulating GitHub repositories on the file level. It is being developed in the context of Prose, a content editor for GitHub.
This repo is now officially maintained by WeFlex.
Note: this is a fork from michael/github, thanks to DevelopmentSeed.
Installation
Either grab octop
from this repo or install via NPM:
npm install octop --save
Usage
Create a Github instance.
var github = username: "YOU_USER" password: "YOUR_PASSWORD" auth: "basic";
Or if you prefer OAuth, it looks like this:
var github = token: "OAUTH_TOKEN" auth: "oauth";
You can use either:
- Authorised App Tokens (via client/secret pairs), used for bigger applications, created in web-flows/on the fly
- Personal Access Tokens (simpler to set up), used on command lines, scripts etc, created in GitHub web UI
See these pages for more info:
Enterprise Github instances may be specified using the apiUrl
option:
var github = apiUrl: "https://serverName/api/v3" ...;
Repository API
var repo = github;
Show repository information
repo;
Delete a repository
repo;
Get contents at a particular path in a particular branch.
repo;
Fork repository. This operation runs asynchronously. You may want to poll for repo.contents
until the forked repo is ready.
repo;
Create new branch for repo. You can omit oldBranchName to default to "master".
repo;
List Pull Requests.
var state = 'open'; //or 'closed', or 'all'repo;
Get details of a Pull Request.
var pullRequestID = 123;repo;
Create Pull Request.
var pull = title: message body: "This pull request has been automatically generated by Prose.io." base: "gh-pages" head: "michael" + ":" + "prose-patch";repo;
Retrieve all available branches (aka heads) of a repository.
repo;
Store contents at a certain path, where files that don't yet exist are created on the fly.
repo;
Not only can you can write files, you can of course read them.
repo;
Move a file from A to B.
repo;
Remove a file.
repo;
Get information about a particular commit.
repo;
Exploring files of a repository is easy too by accessing the top level tree object.
repo;
If you want to access all blobs and trees recursively, you can specify 2nd argument
repo;
Given a filepath, retrieve the reference blob or tree sha.
repo;
For a given reference, get the corresponding commit sha.
repo;
Create a new reference.
var refSpec = "ref": "refs/heads/my-new-branch-name" "sha": "827efc6d56897b048c772eb4087f854f46256132";repo;
Delete a reference.
repo;
Get contributors list with additions, deletions, and commit counts.
repo;
User API
var user = github;
List all repositories of the authenticated user, including private repositories and repositories in which the user is a collaborator and not an owner.
user;
List organizations the autenticated user belongs to.
user;
List authenticated user's gists.
user;
List private & public events for the authenticated user.
user;
List unread notifications for the authenticated user.
user;
Show user information for a particular username. Also works for organizations.
user;
List public repositories for a particular user.
user;
Create a new repo for the authenticated user
user;
Repo description, homepage, private/public can also be set. For a full list of options see the docs here
List repositories for a particular organization. Includes private repositories if you are authorized.
user;
List all gists of a particular user. If username is ommitted gists of the current authenticated user are returned.
user;
Gist API
var gist = github;
Read the contents of a Gist.
gist;
Updating the contents of a Gist. Please consult the documentation on GitHub.
var delta = "description": "the description for this gist" "files": "file1.txt": "content": "updated file contents" "old_name.txt": "filename": "new_name.txt" "content": "modified contents" "new_file.txt": "content": "a new file" "delete_this_file.txt": null ; gist;
Issues API
var issues = github;
To read all the issues of a given repository
issues;
Setup
Github.js has the following dependency:
- btoa (included in modern browsers, an npm module is included in package.json for node)