Skip to content

Commit

Permalink
Merge 555b2ca into 3e7e2de
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-rudeshko committed Dec 13, 2018
2 parents 3e7e2de + 555b2ca commit 865f27f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ const app = new App({
})
```

## Using with GitHub Enterprise

The `endpointDefaults` option allows to override defaults from [octokit/endpoint](https://github.com/octokit/endpoint):

```js
const app = new App({
id: APP_ID,
privateKey: PRIVATE_KEY,
endpointDefaults: {
baseUrl: 'https://api.github-enterprise.com'
}
})
```

## License

[MIT](LICENSE)
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module.exports = App

const request = require('@octokit/request')

const getCache = require('./lib/get-cache')
const getInstallationAccessToken = require('./lib/get-installation-access-token')
const getSignedJsonWebToken = require('./lib/get-signed-json-web-token')

function App ({ id, privateKey, cache }) {
function App ({ id, privateKey, endpointDefaults, cache }) {
const state = {
id,
privateKey,
request: endpointDefaults ? request.defaults(endpointDefaults) : request,
cache: cache || getCache()
}
const api = {
Expand Down
4 changes: 1 addition & 3 deletions lib/get-installation-access-token.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module.exports = getInstallationAccessToken

const request = require('@octokit/request')

const getSignedJsonWebToken = require('./get-signed-json-web-token')

// https://developer.github.com/v3/apps/#create-a-new-installation-token
Expand All @@ -11,7 +9,7 @@ function getInstallationAccessToken (state, { installationId }) {
return Promise.resolve(token)
}

return request({
return state.request({
method: 'POST',
url: '/app/installations/:installation_id/access_tokens',
installation_id: installationId,
Expand Down
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,26 @@ describe('app.js', () => {
expect(options.cache.set.callCount).to.equal(1)
})
})

it('supports custom endpoint defaults', () => {
nock('https://api.github-enterprise.com')
.post('/app/installations/123/access_tokens')
.reply(201, {
token: 'foo'
})

const options = {
id: APP_ID,
privateKey: PRIVATE_KEY,
endpointDefaults: {
baseUrl: 'https://api.github-enterprise.com'
}
}
const appWithCustomEndpointDefaults = new App(options)

return appWithCustomEndpointDefaults.getInstallationAccessToken({ installationId: 123 })
.then(token => {
expect(token).to.equal('foo')
})
})
})

0 comments on commit 865f27f

Please sign in to comment.