forked from github-tools/github
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP Redesign to align with GitHub's conventions #41
Open
philschatz
wants to merge
53
commits into
master
Choose a base branch
from
redesign
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
so browser sepia.js can use the same fixtures
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This code change leverages the URL patterns GitHub provides and converts the returned JSON into objects which allows nifty daisy-chaining.
Overview
This library closely mirrors the https://developer.github.com/v3 documentation.
For example,
GET /repos/:owner/:repo
becomesocto.repos(owner, repo).fetch()
andPOST /repos/:owner/:repo/issues/:number/comments
becomesocto.repos(owner, repo).issues(number).comments.create(params)
.Promises and Callbacks
This library supports NodeJS-style callbacks as well as Promises.
To use a callback, just specify it as the last argument to a method.
To use a Promise, do not specify a callback and the return value will be a Promise.
Example (get information on a repo):
Chaining
You construct the URL by chaining properties and methods together and an async call is made once a verb method is called (see below).
Example:
Or, update a specific comment:
The basic structure of these methods is:
.foos.fetch({optionalStuff:...})
yields a list of items (possibly paginated).foos(id).fetch(...)
yields a single item (issue, repo, user).foos.contains(id)
tests membership in a list (yields true/false).foos.create(...)
creates a newfoo
.foos(id).add()
adds an existing User/Repo to the list.foos(id).remove()
removes a member from a list or deletes the object and yields a boolean indicating successJSON with methods (Hypermedia)
GitHub provides URL patterns in its JSON responses. These are automatically converted into methods.
For example:
Paged Results
If a
.fetch()
returns paged results thennextPage()
,previousPage()
,firstPage()
andlastPage()
are added to the returned JSON. For example:Development
The unit tests are named to illustrate examples of using the API. See travis tests or run
npm test
to see them.linkedin/sepia is used to generate recorded results from GitHub and philschatz/sepia.js uses them in the browser. If you are adding tests be sure to include the updated fixtures in the Pull Request.
Overview of Features
Implemented GitHub APIs:
Examples
Here are some examples of code you can write with this library
Global
octo.zen.fetch()
octo.users.fetch({since})
octo.gists.fetch({since})
octo.events.fetch({since})
octo.notifications.fetch({...})
Search
octo.search.repos.fetch({q,sort,order})
octo.search.code.fetch({q,sort,order})
octo.search.issues.fetch({q,sort,order})
octo.search.users.fetch({q,sort,order})
User
octo.users(name).fetch()
octo.users(name).repos({type,sort,direction})
octo.users(name).orgs.fetch()
octo.users(name).gists.fetch()
octo.users(name).followers.fetch()
octo.users(name).following.fetch()
octo.users(name).following.contains(name)
octo.users(name).keys.fetch()
octo.users(name).receivedEvents.fetch({onlyPublic})
octo.users(name).events.fetch({onlyPublic})
Me
octo.me.fetch()
octo.me.update({...})
octo.me.repos.fetch({type,sort,direction})
octo.me.orgs.fetch()
octo.me.followers.fetch()
octo.me.following.fetch()
octo.me.following.contains(name)
octo.me.following(name).add()
octo.me.following(name).remove()
octo.me.emails.fetch()
octo.me.emails.add(emails)
octo.me.emails.remove(emails)
octo.me.keys.fetch()
octo.me.keys.add()
octo.me.keys(id).remove()
octo.me.key(id).fetch()
Org
octo.orgs(name).fetch()
octo.orgs(name).update({...})
octo.orgs(name).teams.fetch()
octo.orgs(name).teams.create({name,repoNames,permission})
octo.orgs(name).members.fetch()
octo.orgs(name).members.contains(name)
octo.orgs(name).members(name).remove()
octo.orgs(name).repos.fetch()
octo.orgs(name).repos.create(name, {...})
Team
octo.teams(id).fetch()
octo.teams(id).update({...})
octo.teams(id).remove()
octo.teams(id).members.fetch()
octo.teams(id).members.contains(name)
octo.teams(id).members(name).add()
octo.teams(id).members(name).remove()
octo.teams(id).repos.fetch()
octo.teams(id).repos(owner, name).add()
octo.teams(id).repos(owner, name).remove()
Repo
octo.repos(owner, name).fetch()
octo.repos(owner, name).remove()
octo.repos(owner, name).update({...})
octo.repos(owner, name).readme.fetch()
octo.repos(owner, name).forks.create({organization})
octo.repos(owner, name).pullRequests.create({...})
octo.repos(owner, name).events.fetch()
octo.repos(owner, name).issues.events.fetch()
octo.repos(owner, name).notifications.fetch({since,...})
octo.repos(owner, name).collaborators.fetch()
octo.repos(owner, name).collaborators.contains(name)
octo.repos(owner, name).collaborators(name).add()
octo.repos(owner, name).collaborators(name).remove()
octo.repos(owner, name).hooks.fetch()
octo.repos(owner, name).hooks.create({name,config,events,active})
octo.repos(owner, name).hooks.remove(id)
octo.repos(owner, name).hooks(id).fetch()
octo.repos(owner, name).hooks(id).update({...}) # un-camelize
octo.repos(owner, name).hooks(id).tests.create()
octo.repos(owner, name).languages.fetch()
octo.repos(owner, name).releases.fetch()
octo.repos(owner, name).contents(path, sha?).fetch()
octo.repos(owner, name).contents(path, sha).remove(message, branch)
octo.networks(owner, name).events.fetch()
Git
octo.repos(owner, name).git.refs.create({...})
octo.repos(owner, name).git.refs(ref).remove()
octo.repos(owner, name).git.refs(ref).fetch()
octo.repos(owner, name).git.refs.heads.create()
octo.repos(owner, name).git.refs.heads.fetch()
octo.repos(owner, name).git.refs.heads(name).update({sha,force})
octo.repos(owner, name).git.refs.heads(name).remove()
octo.repos(owner, name).git.blobs.create({...})
octo.repos(owner, name).git.blobs(sha).fetch()
octo.repos(owner, name).git.trees.create({...})
octo.repos(owner, name).git.trees(id).fetch({...})
octo.repos(owner, name).git.trees(id).update(newTrees)
octo.repos(owner, name).git.commits.fetch({...})
octo.repos(owner, name).git.commits.create({parents,tree,message})
octo.repos(owner, name).git.commit(sha).fetch()
Gists
octo.gists.fetch()
octo.gists.create({...})
octo.gists(id).fetch()
octo.gists(id).update({...})
octo.gists(id).remove()
octo.gists(id).forks.create()
octo.gists(id).star.contains(USERNAME)
octo.gists(id).star.add()
octo.gists(id).star.remove()