Skip to content

Commit

Permalink
feat: add baseUrl App option
Browse files Browse the repository at this point in the history
The option can be used to override hardcoded defaults from @octokit/endpoint.

So that we can now use it to work on GitHub Enterprise installations:

```js
const app = new App({
  id: APP_ID,
  privateKey: PRIVATE_KEY,
  baseUrl: 'https://github-enterprise.com/api/v3'
})
```
  • Loading branch information
anton-rudeshko authored and gr2m committed Dec 16, 2018
1 parent 155c17f commit 8c2a991
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ const app = new App({
})
```

## Using with GitHub Enterprise

The `baseUrl` option can be used to override default GitHub's `https://api.github.com`:

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

## License

[MIT](LICENSE)
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ 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, baseUrl, cache }) {
const state = {
id,
privateKey,
request,
request: baseUrl ? request.defaults({ baseUrl }) : request,
cache: cache || getCache()
}
const api = {
Expand Down
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,24 @@ describe('app.js', () => {
expect(options.cache.set.callCount).to.equal(1)
})
})

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

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

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

0 comments on commit 8c2a991

Please sign in to comment.