diff --git a/docs/configuration.md b/docs/configuration.md index 51a09dd2981062c13b62fe8ccdd98d6869f7bb34..ebf66045ff49b3bf532504a7d98fb3f39b04720d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -64,64 +64,6 @@ module.exports = { ``` $ node renovate --help - - Usage: renovate [options] [repositories...] - - - Options: - - --log-level <string> Logging level - --log-file <string> Log file path - --log-file-level <string> Log file log level - --onboarding [boolean] Require a Configuration PR first - --private-key <string> Server-side private key - --encrypted <json> A configuration object containing configuration encrypted with project key - --timezone <string> [IANA Time Zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) - --update-not-scheduled [boolean] Whether to update (but not create) branches when not scheduled - --onboarding [boolean] Require a Configuration PR first - --platform <string> Platform type of repository - --endpoint <string> Custom endpoint to use - --token <string> Repository Auth Token - --npmrc <string> String copy of npmrc file. Use \n instead of line breaks - --yarnrc <string> String copy of yarnrc file. Use \n instead of line breaks - --ignore-npmrc-file [boolean] Whether to ignore any .npmrc file found in repository - --autodiscover [boolean] Autodiscover all repositories - --autodiscover [boolean] Autodiscover all repositories - --github-app-id <integer> GitHub App ID (enables GitHub App functionality if set) - --github-app-key <string> GitHub App Private Key (.pem file contents) - --package-files <list> Package file paths - --ignore-paths <list> Skip any package.json whose path matches one of these. - --ignore-deps <list> Dependencies to ignore - --pin-digests [boolean] Whether to add digests to Dockerfile source images - --pin-versions [boolean] Convert ranged versions to pinned versions - --separate-major-releases [boolean] If set to false, it will upgrade dependencies to latest release only, and not separate major/minor branches - --separate-patch-releases [boolean] If set to true, it will separate minor and patch updates into separate branches - --ignore-future [boolean] Ignore versions tagged as "future" - --ignore-unstable [boolean] Ignore versions with unstable semver - --respect-latest [boolean] Ignore versions newer than npm "latest" version - --branch-prefix <string> Prefix to use for all branch names - --semantic-commits [boolean] Enable semantic commit prefixes for commits and PR titles - --semantic-prefix <string> Prefix to use if semantic commits are enabled - --recreate-closed [boolean] Recreate PRs even if same ones were closed previously - --rebase-stale-prs [boolean] Rebase stale PRs (GitHub only) - --unpublish-safe [boolean] Set a status check for unpublish-safe upgrades - --pr-creation <string> When to create the PR for a branch. Values: immediate, not-pending, status-success. - --pr-not-pending-hours <integer> Timeout in hours for when prCreation=not-pending - --automerge [boolean] Whether to automerge branches/PRs automatically, without human intervention - --automerge-type <string> How to automerge - "branch-merge-commit", "branch-push" or "pr". Branch support is GitHub-only - --lazy-grouping [boolean] Use group names only when multiple dependencies upgraded - --group-name <string> Human understandable name for the dependency group - --labels <list> Labels to add to Pull Request - --assignees <list> Assignees for Pull Request - --reviewers <list> Requested reviewers for Pull Requests (GitHub only) - --npm <json> Configuration object for npm package.json renovation - --meteor <json> Configuration object for meteor package.js renovation - -h, --help output usage information - Examples: - - $ renovate --token abc123 singapore/lint-condo - $ renovate --labels=renovate,dependency --ignore-unstable=false --log-level verbose singapore/lint-condo - $ renovate singapore/lint-condo singapore/package-test ``` To configure any `<list>` items, separate with commas. E.g. `renovate --labels=renovate,dependency`. @@ -324,22 +266,6 @@ Obviously, you can't set repository or package file location with this method. <td>`RENOVATE_AUTODISCOVER`</td> <td>`--autodiscover`<td> </tr> -<tr> - <td>`githubAppId`</td> - <td>GitHub App ID (enables GitHub App functionality if set)</td> - <td>integer</td> - <td><pre>undefined</pre></td> - <td>`RENOVATE_GITHUB_APP_ID`</td> - <td>`--github-app-id`<td> -</tr> -<tr> - <td>`githubAppKey`</td> - <td>GitHub App Private Key (.pem file contents)</td> - <td>string</td> - <td><pre>null</pre></td> - <td>`RENOVATE_GITHUB_APP_KEY`</td> - <td>`--github-app-key`<td> -</tr> <tr> <td>`repositories`</td> <td>List of Repositories</td> diff --git a/lib/config/cli.js b/lib/config/cli.js index 443c1ed85f1c4062cb3a8d8ab0a43c0b7a15cf09..02ea33c94eb66c54844e66bc7f126e7241102457 100644 --- a/lib/config/cli.js +++ b/lib/config/cli.js @@ -23,7 +23,6 @@ function getConfig(argv) { boolean: val => val === 'true', list: val => val.split(',').map(el => el.trim()), string: val => val, - integer: val => parseInt(val, 10), }; let program = new commander.Command().arguments('[repositories...]'); diff --git a/lib/config/definitions.js b/lib/config/definitions.js index 9424d974b8ccb93b5243e62721f8ed125bfa7ed9..d79efec676d44ec2b71fb02a74b0761b87c42f13 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -167,18 +167,6 @@ const options = [ type: 'boolean', default: false, }, - { - name: 'githubAppId', - description: 'GitHub App ID (enables GitHub App functionality if set)', - stage: 'global', - type: 'integer', - }, - { - name: 'githubAppKey', - description: 'GitHub App Private Key (.pem file contents)', - stage: 'global', - type: 'string', - }, { name: 'repositories', description: 'List of Repositories', diff --git a/lib/config/env.js b/lib/config/env.js index 5d8db9d41c5ab98f0283edbf0e65f2c6cbed21db..86ef166fd9212a376f64f7e3534eb0a3a38a36b9 100644 --- a/lib/config/env.js +++ b/lib/config/env.js @@ -25,7 +25,6 @@ function getConfig(env) { boolean: val => val === 'true', list: val => val.split(',').map(el => el.trim()), string: val => val, - integer: val => parseInt(val, 10), json: val => JSON.parse(val), }; diff --git a/lib/config/github-app.js b/lib/config/github-app.js deleted file mode 100644 index ec69e4e3c4f96ff1463895df6531af437154fe72..0000000000000000000000000000000000000000 --- a/lib/config/github-app.js +++ /dev/null @@ -1,72 +0,0 @@ -const jwt = require('jsonwebtoken'); -const logger = require('../logger'); -const ghApi = require('../platform/github'); - -module.exports = { - generateJwt, - getUserRepositories, - getRepositories, -}; - -function generateJwt(appId, pemFileContent) { - logger.debug(`githubApp.generateJwt(${appId})`); - const payload = { - // GitHub app identifier - iss: appId, - }; - const options = { - // 5 minutes - expiresIn: 300, - // RS256 required by GitHub - algorithm: 'RS256', - }; - return jwt.sign(payload, pemFileContent, options); -} - -async function getUserRepositories(appToken, installationId) { - logger.debug(`githubApp.getUserRepositories(appToken, ${installationId})`); - const userToken = await ghApi.getInstallationToken(appToken, installationId); - logger.debug(`userToken=${userToken}`); - const userRepositories = await ghApi.getInstallationRepositories(userToken); - logger.debug(`Found ${userRepositories.repositories.length} repositories`); - return userRepositories.repositories.map(repository => ({ - repository: repository.full_name, - token: userToken, - })); -} - -async function getRepositories(config) { - logger.debug(`githubApp.getRepositories`); - const configuredRepositories = config.repositories.map( - repository => - typeof repository === 'string' ? repository : repository.repository - ); - let installedRepos = []; - try { - const appToken = module.exports.generateJwt( - config.githubAppId, - config.githubAppKey - ); - const installations = await ghApi.getInstallations(appToken); - logger.info(`Found installations for ${installations.length} users`); - for (const installation of installations) { - logger.debug(`installation=${JSON.stringify(installation)}`); - let installationRepos = await module.exports.getUserRepositories( - appToken, - installation.id - ); - logger.debug(`installationRepos=${JSON.stringify(installationRepos)}`); - if (configuredRepositories.length) { - installationRepos = installationRepos.filter( - repository => - configuredRepositories.indexOf(repository.repository) !== -1 - ); - } - installedRepos = installedRepos.concat(installationRepos); - } - } catch (err) { - logger.error(`githubApp.getRepositories error: ${JSON.stringify(err)}`); - } - logger.debug(`installedRepos=${JSON.stringify(installedRepos)}`); - return installedRepos; -} diff --git a/lib/config/index.js b/lib/config/index.js index e8d6516e330480acc0ee73aff26ec0afe4a0e24d..19d29baca8daf4b40d60bda9434c33e122ee6957 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -9,8 +9,6 @@ const fileParser = require('./file'); const cliParser = require('./cli'); const envParser = require('./env'); -const githubApp = require('./github-app'); - module.exports = { parseConfigs, mergeChildConfig, @@ -71,15 +69,7 @@ async function parseConfigs(env, argv) { throw new Error(`Unsupported platform: ${config.platform}.`); } - if (config.githubAppId) { - logger.info('Initialising GitHub App mode'); - if (!config.githubAppKey) { - throw new Error('A GitHub App Private Key must be provided'); - } - config.repositories = await githubApp.getRepositories(config); - logger.info(`Found ${config.repositories.length} repositories installed`); - logger.debug({ config }, 'GitHub App config'); - } else if (config.autodiscover) { + if (config.autodiscover) { // Autodiscover list of repositories if (config.platform === 'github') { logger.info('Autodiscovering GitHub repositories'); diff --git a/lib/config/validation.js b/lib/config/validation.js index 15874931491aafdda26bed2946b8612ac41c7964..6329be067e40105d49599bd6c1bb9358838ce6f2 100644 --- a/lib/config/validation.js +++ b/lib/config/validation.js @@ -85,13 +85,6 @@ function validateConfig(config) { message: `Configuration option \`${key}\` should be a string`, }); } - } else if (type === 'integer') { - if (val !== parseInt(val, 10)) { - errors.push({ - depName: 'Configuration Error', - message: `Configuration option \`${key}\` should be an integer`, - }); - } } else if (type === 'json') { if (isObject(val)) { const subValidation = module.exports.validateConfig(val); diff --git a/lib/platform/github.js b/lib/platform/github.js index 4ae54f8b77b9458cd9b7423af752201ccc858611..74c38066fcae4fdf492e768422c1e27db51b4087 100644 --- a/lib/platform/github.js +++ b/lib/platform/github.js @@ -4,10 +4,6 @@ const get = require('./gh-got-wrapper'); const config = {}; module.exports = { - // GitHub App - getInstallations, - getInstallationToken, - getInstallationRepositories, // Initialization getRepos, initRepo, @@ -55,68 +51,6 @@ module.exports = { getCommitDetails, }; -// Get all installations for a GitHub app -async function getInstallations(appToken) { - logger.debug('getInstallations(appToken)'); - try { - const url = 'app/installations'; - const options = { - headers: { - accept: 'application/vnd.github.machine-man-preview+json', - authorization: `Bearer ${appToken}`, - }, - }; - const res = await get(url, options); - logger.debug(`Returning ${res.body.length} results`); - return res.body; - } catch (err) { - logger.error({ err }, `GitHub getInstallations error`); - throw err; - } -} - -// Get the user's installation token -async function getInstallationToken(appToken, installationId) { - logger.debug(`getInstallationToken(appToken, ${installationId})`); - try { - const url = `installations/${installationId}/access_tokens`; - const options = { - headers: { - accept: 'application/vnd.github.machine-man-preview+json', - authorization: `Bearer ${appToken}`, - }, - }; - const res = await get.post(url, options); - return res.body.token; - } catch (err) { - logger.error({ err }, `GitHub getInstallationToken error`); - throw err; - } -} - -// Get all repositories for a user's installation -async function getInstallationRepositories(userToken) { - logger.debug('getInstallationRepositories(userToken)'); - try { - const url = 'installation/repositories'; - const options = { - headers: { - accept: 'application/vnd.github.machine-man-preview+json', - authorization: `token ${userToken}`, - }, - }; - const res = await get(url, options); - logger.debug( - `Returning ${res.body.repositories.length} results from a total of ${res - .body.total_count}` - ); - return res.body; - } catch (err) { - logger.error({ err }, `GitHub getInstallationRepositories error`); - throw err; - } -} - // Get all repositories that the user has access to async function getRepos(token, endpoint) { logger.debug('getRepos(token, endpoint)'); diff --git a/test/config/__snapshots__/github-app.spec.js.snap b/test/config/__snapshots__/github-app.spec.js.snap deleted file mode 100644 index 362af4579fc5024ee47ab98f1c7f1c982a53f6bc..0000000000000000000000000000000000000000 --- a/test/config/__snapshots__/github-app.spec.js.snap +++ /dev/null @@ -1,48 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`config/github-app getRepositories returns filtered list of repos 1`] = ` -Array [ - Object { - "repository": "a/b", - "token": "token_a", - }, - Object { - "repository": "d/f", - "token": "token_d", - }, -] -`; - -exports[`config/github-app getRepositories returns list of repos 1`] = ` -Array [ - Object { - "repository": "a/b", - "token": "token_a", - }, - Object { - "repository": "a/c", - "token": "token_a", - }, - Object { - "repository": "d/e", - "token": "token_d", - }, - Object { - "repository": "d/f", - "token": "token_d", - }, -] -`; - -exports[`config/github-app getUserRepositories returns a repository list 1`] = ` -Array [ - Object { - "repository": "a", - "token": "some_token", - }, - Object { - "repository": "b", - "token": "some_token", - }, -] -`; diff --git a/test/config/__snapshots__/validation.spec.js.snap b/test/config/__snapshots__/validation.spec.js.snap index 3633466e5460842e8f9a081cd02e46ea3ad3e9a1..c52425562ef38d1dcdf8b1c807ae72872d80b9e0 100644 --- a/test/config/__snapshots__/validation.spec.js.snap +++ b/test/config/__snapshots__/validation.spec.js.snap @@ -18,10 +18,6 @@ Array [ "depName": "Configuration Error", "message": "Configuration option \`semanticPrefix\` should be a string", }, - Object { - "depName": "Configuration Error", - "message": "Configuration option \`githubAppId\` should be an integer", - }, Object { "depName": "Configuration Error", "message": "Configuration option \`lockFileMaintenance\` should be a json object", diff --git a/test/config/cli.spec.js b/test/config/cli.spec.js index 430d9d0f9cd3d3224613cabcb9ecfa452d1bffef..f9a08e36ae60501f369db2e5843c9afc88c5a2b0 100644 --- a/test/config/cli.spec.js +++ b/test/config/cli.spec.js @@ -60,10 +60,6 @@ describe('config/cli', () => { argv.push('--token=a'); cli.getConfig(argv).should.eql({ token: 'a' }); }); - it('supports integer', () => { - argv.push('--github-app-id=5'); - cli.getConfig(argv).should.eql({ githubAppId: 5 }); - }); it('supports repositories', () => { argv.push('foo'); argv.push('bar'); diff --git a/test/config/env.spec.js b/test/config/env.spec.js index f454a8ad7a6a938bd8be25f1ab1dd5ca8337c9a6..31e04ea905091de6db15070f6efa0f4cbb6df6da 100644 --- a/test/config/env.spec.js +++ b/test/config/env.spec.js @@ -30,10 +30,6 @@ describe('config/env', () => { const envParam = { RENOVATE_TOKEN: 'a' }; env.getConfig(envParam).should.eql({ token: 'a' }); }); - it('supports integer', () => { - const envParam = { RENOVATE_GITHUB_APP_ID: 5 }; - env.getConfig(envParam).should.eql({ githubAppId: 5 }); - }); it('supports json', () => { const envParam = { RENOVATE_LOCK_FILE_MAINTENANCE: '{}' }; expect(env.getConfig(envParam)).toEqual({ lockFileMaintenance: {} }); diff --git a/test/config/github-app.spec.js b/test/config/github-app.spec.js deleted file mode 100644 index 38d5cb8676f113d7c96a81b32dadf2c0cb027ed6..0000000000000000000000000000000000000000 --- a/test/config/github-app.spec.js +++ /dev/null @@ -1,123 +0,0 @@ -const githubApp = require('../../lib/config/github-app'); -const ghApi = require('../../lib/platform/github'); -const fs = require('fs'); -const path = require('path'); - -jest.mock('../../lib/platform/github'); - -const examplePrivateKey = fs.readFileSync( - path.resolve(__dirname, '../_fixtures/jwt/example.pem') -); - -describe('config/github-app', () => { - describe('generateJwt', () => { - it('returns a jwt for valid PEM file', () => { - expect(githubApp.generateJwt(1, examplePrivateKey)).not.toBeNull(); - }); - }); - describe('getUserRepositories', async () => { - beforeEach(() => { - ghApi.getInstallationToken = jest.fn(() => 'some_token'); - }); - it('returns empty list', async () => { - ghApi.getInstallationRepositories = jest.fn(() => ({ repositories: [] })); - expect(await githubApp.getUserRepositories('token', 123)).toHaveLength(0); - }); - it('returns a repository list', async () => { - ghApi.getInstallationRepositories = jest.fn(() => ({ - repositories: [{ full_name: 'a' }, { full_name: 'b' }], - })); - expect( - await githubApp.getUserRepositories('token', 123) - ).toMatchSnapshot(); - }); - }); - describe('getRepositories', async () => { - const config = { - githubAppId: 123, - githubAppKey: 'some_key', - repositories: [], - }; - beforeEach(() => { - githubApp.generateJwt = jest.fn(); - githubApp.generateJwt.mockImplementationOnce(() => 'jwt'); - githubApp.getUserRepositories = jest.fn(); - }); - it('returns empty list if error', async () => { - ghApi.getInstallations.mockImplementationOnce(() => { - throw new Error('error'); - }); - const results = await githubApp.getRepositories(config); - expect(results).toHaveLength(0); - }); - it('returns empty list if no installations', async () => { - ghApi.getInstallations.mockImplementationOnce(() => []); - const results = await githubApp.getRepositories(config); - expect(results).toHaveLength(0); - }); - it('returns empty list if no repos per installation', async () => { - ghApi.getInstallations.mockImplementationOnce(() => [{ id: 567 }]); - githubApp.getUserRepositories.mockImplementationOnce(() => []); - const results = await githubApp.getRepositories(config); - expect(results).toHaveLength(0); - }); - it('returns list of repos', async () => { - ghApi.getInstallations.mockImplementationOnce(() => [ - { id: 567 }, - { id: 568 }, - ]); - githubApp.getUserRepositories.mockImplementationOnce(() => [ - { - repository: 'a/b', - token: 'token_a', - }, - { - repository: 'a/c', - token: 'token_a', - }, - ]); - githubApp.getUserRepositories.mockImplementationOnce(() => [ - { - repository: 'd/e', - token: 'token_d', - }, - { - repository: 'd/f', - token: 'token_d', - }, - ]); - const results = await githubApp.getRepositories(config); - expect(results).toMatchSnapshot(); - }); - it('returns filtered list of repos', async () => { - ghApi.getInstallations.mockImplementationOnce(() => [ - { id: 567 }, - { id: 568 }, - ]); - githubApp.getUserRepositories.mockImplementationOnce(() => [ - { - repository: 'a/b', - token: 'token_a', - }, - { - repository: 'a/c', - token: 'token_a', - }, - ]); - githubApp.getUserRepositories.mockImplementationOnce(() => [ - { - repository: 'd/e', - token: 'token_d', - }, - { - repository: 'd/f', - token: 'token_d', - }, - ]); - config.repositories = ['a/b', 'd/f', 'x/y']; - const results = await githubApp.getRepositories(config); - expect(results.length).toBe(2); - expect(results).toMatchSnapshot(); - }); - }); -}); diff --git a/test/config/index.spec.js b/test/config/index.spec.js index 2a4db9718c5e3fbd2d52ba3b69f09a894deec138..4abc970c28d595d53364dc2bbe26ecf2db4c1007 100644 --- a/test/config/index.spec.js +++ b/test/config/index.spec.js @@ -7,7 +7,6 @@ describe('config/index', () => { let defaultArgv; let ghGot; let get; - let githubApp; beforeEach(() => { jest.resetModules(); configParser = require('../../lib/config/index.js'); @@ -16,9 +15,6 @@ describe('config/index', () => { ghGot = require('gh-got'); jest.mock('gl-got'); get = require('gl-got'); - jest.mock('../../lib/config/github-app'); - githubApp = require('../../lib/config/github-app'); - githubApp.getRepositories = jest.fn(); }); it('throws for invalid platform', async () => { const env = {}; @@ -60,35 +56,6 @@ describe('config/index', () => { const env = {}; await configParser.parseConfigs(env, defaultArgv); }); - it('throws if no GitHub App key defined', async () => { - defaultArgv = defaultArgv.concat(['--github-app-id=5']); - const env = {}; - let err; - try { - await configParser.parseConfigs(env, defaultArgv); - } catch (e) { - err = e; - } - expect(err.message).toBe('A GitHub App Private Key must be provided'); - }); - it('supports github app', async () => { - const env = {}; - defaultArgv = defaultArgv.concat([ - '--github-app-id=5', - '--github-app-key=abc', - ]); - githubApp.getRepositories.mockImplementationOnce(() => { - const result = [ - { - repository: 'a/b', - token: 'token_a', - }, - ]; - return result; - }); - await configParser.parseConfigs(env, defaultArgv); - expect(githubApp.getRepositories.mock.calls.length).toBe(1); - }); it('autodiscovers github platform', async () => { const env = {}; defaultArgv = defaultArgv.concat(['--autodiscover', '--token=abc']); diff --git a/test/config/validation.spec.js b/test/config/validation.spec.js index deef5300b4a1e64f66855c83353b15373f7a391d..080cbddc49df0d2335a1d83b0960c183ac4e16ef 100644 --- a/test/config/validation.spec.js +++ b/test/config/validation.spec.js @@ -23,7 +23,6 @@ describe('config/validation', () => { schedule: ['every 15 mins every weekday'], labels: 5, semanticPrefix: 7, - githubAppId: 'none', lockFileMaintenance: false, packageRules: [ { @@ -36,7 +35,7 @@ describe('config/validation', () => { logger ); expect(warnings).toHaveLength(0); - expect(errors).toHaveLength(7); + expect(errors).toHaveLength(6); expect(errors).toMatchSnapshot(); }); }); diff --git a/test/platform/__snapshots__/github.spec.js.snap b/test/platform/__snapshots__/github.spec.js.snap index f863af2c827b25dc36155c936bbf581391078c9b..253818db750e2ef9445c7853c0a123b21836e467 100644 --- a/test/platform/__snapshots__/github.spec.js.snap +++ b/test/platform/__snapshots__/github.spec.js.snap @@ -690,55 +690,6 @@ Array [ ] `; -exports[`platform/github getInstallationRepositories should return an array of repositories 1`] = ` -Array [ - Array [ - "installation/repositories", - Object { - "headers": Object { - "accept": "application/vnd.github.machine-man-preview+json", - "authorization": "token sometoken", - }, - }, - ], -] -`; - -exports[`platform/github getInstallationRepositories should return an array of repositories 2`] = ` -Object { - "repositories": Array [ - "a", - "b", - ], - "total_count": 2, -} -`; - -exports[`platform/github getInstallationToken should return an installation token 1`] = `Array []`; - -exports[`platform/github getInstallationToken should return an installation token 2`] = `"aUserToken"`; - -exports[`platform/github getInstallations should return an array of installations 1`] = ` -Array [ - Array [ - "app/installations", - Object { - "headers": Object { - "accept": "application/vnd.github.machine-man-preview+json", - "authorization": "Bearer sometoken", - }, - }, - ], -] -`; - -exports[`platform/github getInstallations should return an array of installations 2`] = ` -Array [ - "a", - "b", -] -`; - exports[`platform/github getPr(prNo) should return a PR object - 0 1`] = ` Object { "base": Object { diff --git a/test/platform/github.spec.js b/test/platform/github.spec.js index 74297af5e33bd2c86205b2048ad48a25bcbb4b42..2362b48cb5fd2d89a25d7a9d87af2c81537b1ff4 100644 --- a/test/platform/github.spec.js +++ b/test/platform/github.spec.js @@ -15,87 +15,6 @@ describe('platform/github', () => { github = require('../../lib/platform/github'); }); - describe('getInstallations', () => { - it('should return an array of installations', async () => { - get.mockImplementationOnce(() => ({ - body: ['a', 'b'], - })); - const installations = await github.getInstallations('sometoken'); - expect(get.mock.calls).toMatchSnapshot(); - expect(installations).toMatchSnapshot(); - }); - it('should return a 404', async () => { - get.mockImplementationOnce(() => - Promise.reject({ - statusCode: 404, - }) - ); - let err; - try { - await github.getInstallations('sometoken'); - } catch (e) { - err = e; - } - expect(err.statusCode).toBe(404); - }); - }); - - describe('getInstallationToken', () => { - it('should return an installation token', async () => { - get.post.mockImplementationOnce(() => ({ - body: { - token: 'aUserToken', - }, - })); - const installationToken = await github.getInstallationToken( - 'sometoken', - 123456 - ); - expect(get.mock.calls).toMatchSnapshot(); - expect(installationToken).toMatchSnapshot(); - }); - it('should return an error if given one', async () => { - get.post.mockImplementationOnce(() => { - throw new Error('error'); - }); - let err; - try { - await github.getInstallationToken('sometoken', 123456); - } catch (e) { - err = e; - } - expect(err.message).toBe('error'); - }); - }); - - describe('getInstallationRepositories', () => { - it('should return an array of repositories', async () => { - get.mockImplementationOnce(() => ({ - body: { - total_count: 2, - repositories: ['a', 'b'], - }, - })); - const repositories = await github.getInstallationRepositories( - 'sometoken' - ); - expect(get.mock.calls).toMatchSnapshot(); - expect(repositories).toMatchSnapshot(); - }); - it('should return an error if given one', async () => { - get.mockImplementationOnce(() => { - throw new Error('error'); - }); - let err; - try { - await github.getInstallationRepositories('sometoken'); - } catch (e) { - err = e; - } - expect(err.message).toBe('error'); - }); - }); - async function getRepos(...args) { // repo info get.mockImplementationOnce(() => ({