Ember Data Github
Ember Data abstraction for the GitHub REST API v3.
Installation
ember install ember-data-github
Usage
You need to choose how you wish to authenticate your GitHub requests using OAuth. ember-data-github
provides a simple
and direct mechanism that is specific to itself. Alternatively, you can use a more general authentication framework like
ember-simple-auth
.
Authenticating Directly
If you already have a token to use the OAuth endpoints, such as a Personal access token, you must set the property
named githubAccessToken
on github-session
service with the currently logged in user's GitHub access token.
ember-simple-auth
Authenticating with If you are using ember-simple-auth (ESA) to authenticate, perhaps with
torii and ESA's torii-provider
, you can authenticate by creating a github
authorizer and extending ember-data-github
's adapter for each model you use. See the respective addon docs and
GitHub's OAuth docs to set it up.
Once you have a token, the authorizer will look like
// app/authorizers/github.js ;;; ;
assuming access_token
is the name of the property containing the token. This automatically injects the Authorization
header into the API requests using ESA mechanisms.
An extended adapter for github-user
would look like
// app/adapters/github-user.js ;; ;
Retrieving GitHub Data
Users
Get the current authenticated user
this;
Get a single user
this; // get a user by user loginthis; // get a user by user id
Repositories
Get
this; // get a repository by repository namethis; // get a repository by repository id
Get By User
this; // get repositories owned by userthis; // get all repositories for userthis; // get repositories owned by user sorted by last updated, ascending
Repository Contents
Get
Note: At this time we only support getting file contents.
this; // get file contents from repo
Branches
List branches
this;
Get
this; // get a branchthis; // get a specific branch
Releases
List releases for a repository
this;
Get a single release
this;
Commits
Compate two commits
this;
Pull Requests
List pull requests
this;
Get a single pull request
this;
GitHub Organizations
Get an organizaton
this;
Get organization members
this
Git Blobs
Get a blob
this;
Git Trees
Get a Tree
this;
Testing with Mirage
This addon uses ember-cli-mirage in its tests. It is often beneficial for consuming apps to be able to re-use the factories and models defined in mirage, so if you would like to use these in your tests you can add the mirage-support
object to your ember-cli-build.js
file:
module.exports = function(defaults) {
let app = new EmberApp(defaults, {
...
'mirage-support': {
includeAll: true
}
...
});
return app.toTree();
};
As long as ember-cli-mirage
is not disabled, the files in this addon's mirage-support
directory will be merged with the consuming app's namespace, and be made available to that mirage context.
The 'mirage-support'
key has 3 options:
Key | Type | Description |
---|---|---|
includeAll |
Boolean |
If true , includes the full mirage-support tree, i.e. no-brainer just use it all. |
exclude |
{Array of GlobStrings,RegExps,Functions } |
This value gets passed directly to broccoli-funnel , only if includeAll is specified. Allows for excluding certain files from import. |
include |
{Array of GlobStrings,RegExps,Functions } |
Passed dirctly to broccoli-funnel . Allows to pick only certain files to be imported into app namespace. |
Contributing
Installation
git clone git@github.com:elwayman02/ember-data-github.git
cd ember-data-github
yarn
Running
ember serve
- Visit your app at http://localhost:4200.
Running Tests
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"ember try:each
– Runs the test suite against multiple Ember versions
Building
ember build
For more information on using ember-cli, visit https://ember-cli.com/.