From 01fedc7e0c4f2b3a00cfcedb2d243c076ef6e039 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@keylocation.sg> Date: Tue, 24 Oct 2017 10:27:17 +0200 Subject: [PATCH] refactor: move github and gitlab api to platform (#1037) --- lib/config/github-app.js | 2 +- lib/config/index.js | 4 +- lib/{api => platform}/gh-got-wrapper.js | 0 lib/{api => platform}/github.js | 0 lib/{api => platform}/gitlab.js | 0 lib/{api => platform}/gl-got-wrapper.js | 0 lib/workers/repository/apis.js | 12 +- test/config/github-app.spec.js | 4 +- .../__snapshots__/github.spec.js.snap | 190 +++++++++--------- .../__snapshots__/gitlab.spec.js.snap | 82 ++++---- test/{api => platform}/gh-got-wrapper.spec.js | 4 +- test/{api => platform}/github.spec.js | 8 +- test/{api => platform}/gitlab.spec.js | 8 +- test/{api => platform}/gl-got-wrapper.spec.js | 4 +- test/workers/repository/apis.spec.js | 8 +- 15 files changed, 163 insertions(+), 163 deletions(-) rename lib/{api => platform}/gh-got-wrapper.js (100%) rename lib/{api => platform}/github.js (100%) rename lib/{api => platform}/gitlab.js (100%) rename lib/{api => platform}/gl-got-wrapper.js (100%) rename test/{api => platform}/__snapshots__/github.spec.js.snap (67%) rename test/{api => platform}/__snapshots__/gitlab.spec.js.snap (55%) rename test/{api => platform}/gh-got-wrapper.spec.js (97%) rename test/{api => platform}/github.spec.js (99%) rename test/{api => platform}/gitlab.spec.js (99%) rename test/{api => platform}/gl-got-wrapper.spec.js (94%) diff --git a/lib/config/github-app.js b/lib/config/github-app.js index 343046f3fb..ec69e4e3c4 100644 --- a/lib/config/github-app.js +++ b/lib/config/github-app.js @@ -1,6 +1,6 @@ const jwt = require('jsonwebtoken'); const logger = require('../logger'); -const ghApi = require('../api/github'); +const ghApi = require('../platform/github'); module.exports = { generateJwt, diff --git a/lib/config/index.js b/lib/config/index.js index 37b94c60a2..e8d6516e33 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -1,6 +1,6 @@ const logger = require('../logger'); -const githubApi = require('../api/github'); -const gitlabApi = require('../api/gitlab'); +const githubApi = require('../platform/github'); +const gitlabApi = require('../platform/gitlab'); const definitions = require('./definitions'); diff --git a/lib/api/gh-got-wrapper.js b/lib/platform/gh-got-wrapper.js similarity index 100% rename from lib/api/gh-got-wrapper.js rename to lib/platform/gh-got-wrapper.js diff --git a/lib/api/github.js b/lib/platform/github.js similarity index 100% rename from lib/api/github.js rename to lib/platform/github.js diff --git a/lib/api/gitlab.js b/lib/platform/gitlab.js similarity index 100% rename from lib/api/gitlab.js rename to lib/platform/gitlab.js diff --git a/lib/api/gl-got-wrapper.js b/lib/platform/gl-got-wrapper.js similarity index 100% rename from lib/api/gl-got-wrapper.js rename to lib/platform/gl-got-wrapper.js diff --git a/lib/workers/repository/apis.js b/lib/workers/repository/apis.js index 5df7dc2154..1ebabfccb8 100644 --- a/lib/workers/repository/apis.js +++ b/lib/workers/repository/apis.js @@ -8,8 +8,8 @@ const configMassage = require('../../config/massage'); const configValidation = require('../../config/validation'); const presets = require('../../config/presets'); // API -const githubApi = require('../../api/github'); -const gitlabApi = require('../../api/gitlab'); +const githubPlatform = require('../../platform/github'); +const gitlabPlatform = require('../../platform/gitlab'); module.exports = { detectSemanticCommits, @@ -110,17 +110,17 @@ async function getNpmrc(config) { } async function initApis(inputConfig, token) { - function getPlatformApi(platform) { + function getApi(platform) { if (platform === 'github') { - return githubApi; + return githubPlatform; } else if (platform === 'gitlab') { - return gitlabApi; + return gitlabPlatform; } throw new Error(`Unknown platform: ${platform}`); } const config = { ...inputConfig }; - config.api = getPlatformApi(config.platform); + config.api = getApi(config.platform); const platformConfig = await config.api.initRepo( config.repository, token, diff --git a/test/config/github-app.spec.js b/test/config/github-app.spec.js index 53ffae776b..38d5cb8676 100644 --- a/test/config/github-app.spec.js +++ b/test/config/github-app.spec.js @@ -1,9 +1,9 @@ const githubApp = require('../../lib/config/github-app'); -const ghApi = require('../../lib/api/github'); +const ghApi = require('../../lib/platform/github'); const fs = require('fs'); const path = require('path'); -jest.mock('../../lib/api/github'); +jest.mock('../../lib/platform/github'); const examplePrivateKey = fs.readFileSync( path.resolve(__dirname, '../_fixtures/jwt/example.pem') diff --git a/test/api/__snapshots__/github.spec.js.snap b/test/platform/__snapshots__/github.spec.js.snap similarity index 67% rename from test/api/__snapshots__/github.spec.js.snap rename to test/platform/__snapshots__/github.spec.js.snap index 5ac959db9b..dc6cd2505b 100644 --- a/test/api/__snapshots__/github.spec.js.snap +++ b/test/platform/__snapshots__/github.spec.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`api/github addAssignees(issueNo, assignees) should add the given assignees to the issue 1`] = ` +exports[`platform/github addAssignees(issueNo, assignees) should add the given assignees to the issue 1`] = ` Array [ Array [ "repos/some/repo/issues/42/assignees", @@ -16,7 +16,7 @@ Array [ ] `; -exports[`api/github addLabels(issueNo, labels) should add the given labels to the issue 1`] = ` +exports[`platform/github addLabels(issueNo, labels) should add the given labels to the issue 1`] = ` Array [ Array [ "repos/some/repo/issues/42/labels", @@ -30,7 +30,7 @@ Array [ ] `; -exports[`api/github addReviewers(issueNo, reviewers) should add the given reviewers to the PR 1`] = ` +exports[`platform/github addReviewers(issueNo, reviewers) should add the given reviewers to the PR 1`] = ` Array [ Array [ "repos/some/repo/pulls/42/requested_reviewers", @@ -50,7 +50,7 @@ Array [ ] `; -exports[`api/github branchExists(branchName) should propagate unknown errors 1`] = ` +exports[`platform/github branchExists(branchName) should propagate unknown errors 1`] = ` Array [ Array [ "repos/some/repo", @@ -77,7 +77,7 @@ Array [ ] `; -exports[`api/github branchExists(branchName) should return false if a 404 is returned 1`] = ` +exports[`platform/github branchExists(branchName) should return false if a 404 is returned 1`] = ` Array [ Array [ "repos/some/repo", @@ -104,7 +104,7 @@ Array [ ] `; -exports[`api/github branchExists(branchName) should return false if the branch does not exist (multiple results) 1`] = ` +exports[`platform/github branchExists(branchName) should return false if the branch does not exist (multiple results) 1`] = ` Array [ Array [ "repos/some/repo", @@ -131,7 +131,7 @@ Array [ ] `; -exports[`api/github branchExists(branchName) should return false if the branch does not exist (one result) 1`] = ` +exports[`platform/github branchExists(branchName) should return false if the branch does not exist (one result) 1`] = ` Array [ Array [ "repos/some/repo", @@ -158,7 +158,7 @@ Array [ ] `; -exports[`api/github branchExists(branchName) should return true if the branch exists (multiple results) 1`] = ` +exports[`platform/github branchExists(branchName) should return true if the branch exists (multiple results) 1`] = ` Array [ Array [ "repos/some/repo", @@ -185,7 +185,7 @@ Array [ ] `; -exports[`api/github branchExists(branchName) should return true if the branch exists (one result) 1`] = ` +exports[`platform/github branchExists(branchName) should return true if the branch exists (one result) 1`] = ` Array [ Array [ "repos/some/repo", @@ -212,7 +212,7 @@ Array [ ] `; -exports[`api/github commitFilesToBranch(branchName, files, message, parentBranch) should add a commit to a new branch if the branch does not already exist 1`] = ` +exports[`platform/github commitFilesToBranch(branchName, files, message, parentBranch) should add a commit to a new branch if the branch does not already exist 1`] = ` Array [ Array [ "repos/some/repo", @@ -245,7 +245,7 @@ Array [ ] `; -exports[`api/github commitFilesToBranch(branchName, files, message, parentBranch) should add a commit to a new branch if the branch does not already exist 2`] = ` +exports[`platform/github commitFilesToBranch(branchName, files, message, parentBranch) should add a commit to a new branch if the branch does not already exist 2`] = ` Array [ Array [ "repos/some/repo/git/blobs", @@ -296,9 +296,9 @@ Array [ ] `; -exports[`api/github commitFilesToBranch(branchName, files, message, parentBranch) should add a commit to a new branch if the branch does not already exist 3`] = `Array []`; +exports[`platform/github commitFilesToBranch(branchName, files, message, parentBranch) should add a commit to a new branch if the branch does not already exist 3`] = `Array []`; -exports[`api/github commitFilesToBranch(branchName, files, message, parentBranch) should add a new commit to the branch 1`] = ` +exports[`platform/github commitFilesToBranch(branchName, files, message, parentBranch) should add a new commit to the branch 1`] = ` Array [ Array [ "repos/some/repo", @@ -331,7 +331,7 @@ Array [ ] `; -exports[`api/github commitFilesToBranch(branchName, files, message, parentBranch) should add a new commit to the branch 2`] = ` +exports[`platform/github commitFilesToBranch(branchName, files, message, parentBranch) should add a new commit to the branch 2`] = ` Array [ Array [ "repos/some/repo/git/blobs", @@ -373,7 +373,7 @@ Array [ ] `; -exports[`api/github commitFilesToBranch(branchName, files, message, parentBranch) should add a new commit to the branch 3`] = ` +exports[`platform/github commitFilesToBranch(branchName, files, message, parentBranch) should add a new commit to the branch 3`] = ` Array [ Array [ "repos/some/repo/git/refs/heads/package.json", @@ -387,14 +387,14 @@ Array [ ] `; -exports[`api/github createPr(branchName, title, body) should create and return a PR object 1`] = ` +exports[`platform/github createPr(branchName, title, body) should create and return a PR object 1`] = ` Object { "displayNumber": "Pull Request #123", "number": 123, } `; -exports[`api/github createPr(branchName, title, body) should create and return a PR object 2`] = ` +exports[`platform/github createPr(branchName, title, body) should create and return a PR object 2`] = ` Array [ Array [ "repos/some/repo/pulls", @@ -410,14 +410,14 @@ Array [ ] `; -exports[`api/github createPr(branchName, title, body) should use defaultBranch 1`] = ` +exports[`platform/github createPr(branchName, title, body) should use defaultBranch 1`] = ` Object { "displayNumber": "Pull Request #123", "number": 123, } `; -exports[`api/github createPr(branchName, title, body) should use defaultBranch 2`] = ` +exports[`platform/github createPr(branchName, title, body) should use defaultBranch 2`] = ` Array [ Array [ "repos/some/repo/pulls", @@ -433,7 +433,7 @@ Array [ ] `; -exports[`api/github ensureComment add comment if not found 1`] = ` +exports[`platform/github ensureComment add comment if not found 1`] = ` Array [ Array [ "repos/some/repo/issues/42/comments", @@ -449,7 +449,7 @@ content", ] `; -exports[`api/github ensureComment add updates comment if necessary 1`] = ` +exports[`platform/github ensureComment add updates comment if necessary 1`] = ` Array [ Array [ "repos/some/repo/issues/comments/1234", @@ -465,7 +465,7 @@ content", ] `; -exports[`api/github findFilePaths(fileName) should return the files matching the fileName 1`] = ` +exports[`platform/github findFilePaths(fileName) should return the files matching the fileName 1`] = ` Array [ "package.json", "src/app/package.json", @@ -473,16 +473,16 @@ Array [ ] `; -exports[`api/github getAllRenovateBranches() should return all renovate branches 1`] = ` +exports[`platform/github getAllRenovateBranches() should return all renovate branches 1`] = ` Array [ "renovate/a", "renovate/b", ] `; -exports[`api/github getBranchLastCommitTime should return a Date 1`] = `2011-04-14T16:00:49.000Z`; +exports[`platform/github getBranchLastCommitTime should return a Date 1`] = `2011-04-14T16:00:49.000Z`; -exports[`api/github getBranchPr(branchName) should return the PR object 1`] = ` +exports[`platform/github getBranchPr(branchName) should return the PR object 1`] = ` Array [ Array [ "repos/some/repo", @@ -512,16 +512,16 @@ Array [ ] `; -exports[`api/github getBranchPr(branchName) should return the PR object 2`] = `null`; +exports[`platform/github getBranchPr(branchName) should return the PR object 2`] = `null`; -exports[`api/github getCommitMessages() returns commits messages 1`] = ` +exports[`platform/github getCommitMessages() returns commits messages 1`] = ` Array [ "foo", "bar", ] `; -exports[`api/github getFile(filePatch, branchName) should return the encoded file content 1`] = ` +exports[`platform/github getFile(filePatch, branchName) should return the encoded file content 1`] = ` Array [ Array [ "repos/some/repo", @@ -548,7 +548,7 @@ Array [ ] `; -exports[`api/github getFileContent(filePatch, branchName) should return null if GitHub returns a 404 1`] = ` +exports[`platform/github getFileContent(filePatch, branchName) should return null if GitHub returns a 404 1`] = ` Array [ Array [ "repos/some/repo", @@ -575,7 +575,7 @@ Array [ ] `; -exports[`api/github getFileContent(filePatch, branchName) should return null if getFile returns nothing 1`] = ` +exports[`platform/github getFileContent(filePatch, branchName) should return null if getFile returns nothing 1`] = ` Array [ Array [ "repos/some/repo", @@ -602,7 +602,7 @@ Array [ ] `; -exports[`api/github getFileContent(filePatch, branchName) should return the encoded file content 1`] = ` +exports[`platform/github getFileContent(filePatch, branchName) should return the encoded file content 1`] = ` Array [ Array [ "repos/some/repo", @@ -629,7 +629,7 @@ Array [ ] `; -exports[`api/github getFileJson(filePatch, branchName) should return null if invalid JSON 1`] = ` +exports[`platform/github getFileJson(filePatch, branchName) should return null if invalid JSON 1`] = ` Array [ Array [ "repos/some/repo", @@ -656,7 +656,7 @@ Array [ ] `; -exports[`api/github getFileJson(filePatch, branchName) should return the file contents parsed as JSON 1`] = ` +exports[`platform/github getFileJson(filePatch, branchName) should return the file contents parsed as JSON 1`] = ` Array [ Array [ "repos/some/repo", @@ -683,13 +683,13 @@ Array [ ] `; -exports[`api/github getFileJson(filePatch, branchName) should return the file contents parsed as JSON 2`] = ` +exports[`platform/github getFileJson(filePatch, branchName) should return the file contents parsed as JSON 2`] = ` Object { "hello": "world", } `; -exports[`api/github getInstallationRepositories should return an array of repositories 1`] = ` +exports[`platform/github getInstallationRepositories should return an array of repositories 1`] = ` Array [ Array [ "installation/repositories", @@ -703,7 +703,7 @@ Array [ ] `; -exports[`api/github getInstallationRepositories should return an array of repositories 2`] = ` +exports[`platform/github getInstallationRepositories should return an array of repositories 2`] = ` Object { "repositories": Array [ "a", @@ -713,11 +713,11 @@ Object { } `; -exports[`api/github getInstallationToken should return an installation token 1`] = `Array []`; +exports[`platform/github getInstallationToken should return an installation token 1`] = `Array []`; -exports[`api/github getInstallationToken should return an installation token 2`] = `"aUserToken"`; +exports[`platform/github getInstallationToken should return an installation token 2`] = `"aUserToken"`; -exports[`api/github getInstallations should return an array of installations 1`] = ` +exports[`platform/github getInstallations should return an array of installations 1`] = ` Array [ Array [ "app/installations", @@ -731,14 +731,14 @@ Array [ ] `; -exports[`api/github getInstallations should return an array of installations 2`] = ` +exports[`platform/github getInstallations should return an array of installations 2`] = ` Array [ "a", "b", ] `; -exports[`api/github getPr(prNo) should return a PR object - 0 1`] = ` +exports[`platform/github getPr(prNo) should return a PR object - 0 1`] = ` Object { "base": Object { "sha": "1234", @@ -750,7 +750,7 @@ Object { } `; -exports[`api/github getPr(prNo) should return a PR object - 1 1`] = ` +exports[`platform/github getPr(prNo) should return a PR object - 1 1`] = ` Object { "base": Object { "sha": "1234", @@ -765,7 +765,7 @@ Object { } `; -exports[`api/github getPr(prNo) should return a PR object - 2 1`] = ` +exports[`platform/github getPr(prNo) should return a PR object - 2 1`] = ` Object { "base": Object { "sha": "5678", @@ -779,7 +779,7 @@ Object { } `; -exports[`api/github getPr(prNo) should return a rebaseable PR despite multiple commits 1`] = ` +exports[`platform/github getPr(prNo) should return a rebaseable PR despite multiple commits 1`] = ` Object { "base": Object { "sha": "1234", @@ -794,7 +794,7 @@ Object { } `; -exports[`api/github getPr(prNo) should return a rebaseable PR if web-flow is second author 1`] = ` +exports[`platform/github getPr(prNo) should return a rebaseable PR if web-flow is second author 1`] = ` Object { "base": Object { "sha": "1234", @@ -809,7 +809,7 @@ Object { } `; -exports[`api/github getPr(prNo) should return an unrebaseable PR if multiple authors 1`] = ` +exports[`platform/github getPr(prNo) should return an unrebaseable PR if multiple authors 1`] = ` Object { "base": Object { "sha": "1234", @@ -823,7 +823,7 @@ Object { } `; -exports[`api/github getRepos should return an array of repos 1`] = ` +exports[`platform/github getRepos should return an array of repos 1`] = ` Array [ Array [ "user/repos", @@ -831,14 +831,14 @@ Array [ ] `; -exports[`api/github getRepos should return an array of repos 2`] = ` +exports[`platform/github getRepos should return an array of repos 2`] = ` Array [ "a/b", "c/d", ] `; -exports[`api/github getRepos should support a custom endpoint 1`] = ` +exports[`platform/github getRepos should support a custom endpoint 1`] = ` Array [ Array [ "user/repos", @@ -846,14 +846,14 @@ Array [ ] `; -exports[`api/github getRepos should support a custom endpoint 2`] = ` +exports[`platform/github getRepos should support a custom endpoint 2`] = ` Array [ "a/b", "c/d", ] `; -exports[`api/github getSubDirectories(path) should return subdirectories 1`] = ` +exports[`platform/github getSubDirectories(path) should return subdirectories 1`] = ` Array [ Array [ "repos/some/repo", @@ -880,13 +880,13 @@ Array [ ] `; -exports[`api/github getSubDirectories(path) should return subdirectories 2`] = ` +exports[`platform/github getSubDirectories(path) should return subdirectories 2`] = ` Array [ "a", ] `; -exports[`api/github initRepo should detect repoForceRebase 1`] = ` +exports[`platform/github initRepo should detect repoForceRebase 1`] = ` Object { "isFork": false, "privateRepo": false, @@ -894,7 +894,7 @@ Object { } `; -exports[`api/github initRepo should ignore repoForceRebase 403 1`] = ` +exports[`platform/github initRepo should ignore repoForceRebase 403 1`] = ` Object { "isFork": false, "privateRepo": false, @@ -902,7 +902,7 @@ Object { } `; -exports[`api/github initRepo should ignore repoForceRebase 404 1`] = ` +exports[`platform/github initRepo should ignore repoForceRebase 404 1`] = ` Object { "isFork": false, "privateRepo": false, @@ -910,7 +910,7 @@ Object { } `; -exports[`api/github initRepo should initialise the config for the repo - 0 1`] = ` +exports[`platform/github initRepo should initialise the config for the repo - 0 1`] = ` Array [ Array [ "repos/some/repo", @@ -934,7 +934,7 @@ Array [ ] `; -exports[`api/github initRepo should initialise the config for the repo - 0 2`] = ` +exports[`platform/github initRepo should initialise the config for the repo - 0 2`] = ` Object { "isFork": false, "privateRepo": false, @@ -942,7 +942,7 @@ Object { } `; -exports[`api/github initRepo should initialise the config for the repo - 1 1`] = ` +exports[`platform/github initRepo should initialise the config for the repo - 1 1`] = ` Array [ Array [ "repos/some/repo", @@ -966,7 +966,7 @@ Array [ ] `; -exports[`api/github initRepo should initialise the config for the repo - 1 2`] = ` +exports[`platform/github initRepo should initialise the config for the repo - 1 2`] = ` Object { "isFork": false, "privateRepo": false, @@ -974,7 +974,7 @@ Object { } `; -exports[`api/github initRepo should initialise the config for the repo - 2 1`] = ` +exports[`platform/github initRepo should initialise the config for the repo - 2 1`] = ` Array [ Array [ "repos/some/repo", @@ -998,7 +998,7 @@ Array [ ] `; -exports[`api/github initRepo should initialise the config for the repo - 2 2`] = ` +exports[`platform/github initRepo should initialise the config for the repo - 2 2`] = ` Object { "isFork": false, "privateRepo": false, @@ -1006,7 +1006,7 @@ Object { } `; -exports[`api/github initRepo should merge 1`] = ` +exports[`platform/github initRepo should merge 1`] = ` Object { "isFork": false, "privateRepo": false, @@ -1014,7 +1014,7 @@ Object { } `; -exports[`api/github initRepo should not guess at merge 1`] = ` +exports[`platform/github initRepo should not guess at merge 1`] = ` Object { "isFork": false, "privateRepo": false, @@ -1022,7 +1022,7 @@ Object { } `; -exports[`api/github initRepo should rebase 1`] = ` +exports[`platform/github initRepo should rebase 1`] = ` Object { "isFork": false, "privateRepo": false, @@ -1030,7 +1030,7 @@ Object { } `; -exports[`api/github initRepo should squash 1`] = ` +exports[`platform/github initRepo should squash 1`] = ` Object { "isFork": false, "privateRepo": false, @@ -1038,7 +1038,7 @@ Object { } `; -exports[`api/github mergeBranch(branchName, mergeType) should perform a branch-merge-commit merge 1`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should perform a branch-merge-commit merge 1`] = ` Array [ Array [ "repos/some/repo", @@ -1065,9 +1065,9 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should perform a branch-merge-commit merge 2`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should perform a branch-merge-commit merge 2`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should perform a branch-merge-commit merge 3`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should perform a branch-merge-commit merge 3`] = ` Array [ Array [ "repos/some/repo/merges", @@ -1081,9 +1081,9 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should perform a branch-merge-commit merge 4`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should perform a branch-merge-commit merge 4`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should perform a branch-merge-commit merge 5`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should perform a branch-merge-commit merge 5`] = ` Array [ Array [ "repos/some/repo/git/refs/heads/thebranchname", @@ -1091,7 +1091,7 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should perform a branch-push merge 1`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should perform a branch-push merge 1`] = ` Array [ Array [ "repos/some/repo", @@ -1121,7 +1121,7 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should perform a branch-push merge 2`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should perform a branch-push merge 2`] = ` Array [ Array [ "repos/some/repo/git/refs/heads/master", @@ -1134,11 +1134,11 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should perform a branch-push merge 3`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should perform a branch-push merge 3`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should perform a branch-push merge 4`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should perform a branch-push merge 4`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should perform a branch-push merge 5`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should perform a branch-push merge 5`] = ` Array [ Array [ "repos/some/repo/git/refs/heads/thebranchname", @@ -1146,9 +1146,9 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 1`] = `[Error: branch-merge-commit failed]`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 1`] = `[Error: branch-merge-commit failed]`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 2`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 2`] = ` Array [ Array [ "repos/some/repo", @@ -1172,9 +1172,9 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 3`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 3`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 4`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 4`] = ` Array [ Array [ "repos/some/repo/merges", @@ -1188,13 +1188,13 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 5`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 5`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 6`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-merge-commit throws 6`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 1`] = `[Error: branch-push failed]`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 1`] = `[Error: branch-push failed]`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 2`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 2`] = ` Array [ Array [ "repos/some/repo", @@ -1221,7 +1221,7 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 3`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 3`] = ` Array [ Array [ "repos/some/repo/git/refs/heads/master", @@ -1234,15 +1234,15 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 4`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 4`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 5`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 5`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 6`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if branch-push merge throws 6`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if unknown merge type 1`] = `[Error: Unsupported branch merge type: wrong-merge-type]`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if unknown merge type 1`] = `[Error: Unsupported branch merge type: wrong-merge-type]`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if unknown merge type 2`] = ` +exports[`platform/github mergeBranch(branchName, mergeType) should throw if unknown merge type 2`] = ` Array [ Array [ "repos/some/repo", @@ -1266,15 +1266,15 @@ Array [ ] `; -exports[`api/github mergeBranch(branchName, mergeType) should throw if unknown merge type 3`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if unknown merge type 3`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if unknown merge type 4`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if unknown merge type 4`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if unknown merge type 5`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if unknown merge type 5`] = `Array []`; -exports[`api/github mergeBranch(branchName, mergeType) should throw if unknown merge type 6`] = `Array []`; +exports[`platform/github mergeBranch(branchName, mergeType) should throw if unknown merge type 6`] = `Array []`; -exports[`api/github setBaseBranch(branchName) sets the base branch 1`] = ` +exports[`platform/github setBaseBranch(branchName) sets the base branch 1`] = ` Array [ Array [ "repos/some/repo", @@ -1301,7 +1301,7 @@ Array [ ] `; -exports[`api/github updatePr(prNo, title, body) should update the PR 1`] = ` +exports[`platform/github updatePr(prNo, title, body) should update the PR 1`] = ` Array [ Array [ "repos/some/repo/pulls/1234", diff --git a/test/api/__snapshots__/gitlab.spec.js.snap b/test/platform/__snapshots__/gitlab.spec.js.snap similarity index 55% rename from test/api/__snapshots__/gitlab.spec.js.snap rename to test/platform/__snapshots__/gitlab.spec.js.snap index 97378b8644..0bd6371145 100644 --- a/test/api/__snapshots__/gitlab.spec.js.snap +++ b/test/platform/__snapshots__/gitlab.spec.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`api/gitlab addAssignees(issueNo, assignees) should add the given assignees to the issue 1`] = ` +exports[`platform/gitlab addAssignees(issueNo, assignees) should add the given assignees to the issue 1`] = ` Array [ Array [ "projects/some%2Frepo/merge_requests/42?assignee_id=someuser", @@ -8,7 +8,7 @@ Array [ ] `; -exports[`api/gitlab addAssignees(issueNo, assignees) should log error if more than one assignee 1`] = ` +exports[`platform/gitlab addAssignees(issueNo, assignees) should log error if more than one assignee 1`] = ` Array [ Array [ "projects/some%2Frepo/merge_requests/42?assignee_id=someuser", @@ -16,7 +16,7 @@ Array [ ] `; -exports[`api/gitlab addLabels(issueNo, labels) should add the given labels to the issue 1`] = ` +exports[`platform/gitlab addLabels(issueNo, labels) should add the given labels to the issue 1`] = ` Array [ Array [ "projects/some%2Frepo/merge_requests/42?labels=foo,bar", @@ -24,7 +24,7 @@ Array [ ] `; -exports[`api/gitlab createFile(branchName, filePath, fileContents, message) createBranch(branchName) creates file with v3 1`] = ` +exports[`platform/gitlab createFile(branchName, filePath, fileContents, message) createBranch(branchName) creates file with v3 1`] = ` Array [ Array [ "projects/some-repo/repository/branches", @@ -38,7 +38,7 @@ Array [ ] `; -exports[`api/gitlab createFile(branchName, filePath, fileContents, message) createBranch(branchName) creates file with v4 1`] = ` +exports[`platform/gitlab createFile(branchName, filePath, fileContents, message) createBranch(branchName) creates file with v4 1`] = ` Array [ Array [ "projects/undefined/repository/branches", @@ -52,7 +52,7 @@ Array [ ] `; -exports[`api/gitlab createFile(branchName, filePath, fileContents, message) creates file with v3 1`] = ` +exports[`platform/gitlab createFile(branchName, filePath, fileContents, message) creates file with v3 1`] = ` Array [ Array [ "projects/some-repo/repository/files", @@ -69,7 +69,7 @@ Array [ ] `; -exports[`api/gitlab createFile(branchName, filePath, fileContents, message) creates file with v4 1`] = ` +exports[`platform/gitlab createFile(branchName, filePath, fileContents, message) creates file with v4 1`] = ` Array [ Array [ "projects/undefined/repository/files/some-path", @@ -85,7 +85,7 @@ Array [ ] `; -exports[`api/gitlab createFile(branchName, filePath, fileContents, message) getSubDirectories(path) should return subdirectories 1`] = ` +exports[`platform/gitlab createFile(branchName, filePath, fileContents, message) getSubDirectories(path) should return subdirectories 1`] = ` Array [ Array [ "projects/owned", @@ -102,13 +102,13 @@ Array [ ] `; -exports[`api/gitlab createFile(branchName, filePath, fileContents, message) getSubDirectories(path) should return subdirectories 2`] = ` +exports[`platform/gitlab createFile(branchName, filePath, fileContents, message) getSubDirectories(path) should return subdirectories 2`] = ` Array [ "a", ] `; -exports[`api/gitlab createFile(branchName, filePath, fileContents, message) updateFile(branchName, filePath, fileContents, message) creates file with v3 1`] = ` +exports[`platform/gitlab createFile(branchName, filePath, fileContents, message) updateFile(branchName, filePath, fileContents, message) creates file with v3 1`] = ` Array [ Array [ "projects/some-repo/repository/files", @@ -125,7 +125,7 @@ Array [ ] `; -exports[`api/gitlab createFile(branchName, filePath, fileContents, message) updateFile(branchName, filePath, fileContents, message) creates file with v4 1`] = ` +exports[`platform/gitlab createFile(branchName, filePath, fileContents, message) updateFile(branchName, filePath, fileContents, message) creates file with v4 1`] = ` Array [ Array [ "projects/undefined/repository/files/some-path", @@ -141,7 +141,7 @@ Array [ ] `; -exports[`api/gitlab createPr(branchName, title, body) returns the PR 1`] = ` +exports[`platform/gitlab createPr(branchName, title, body) returns the PR 1`] = ` Object { "displayNumber": "Merge Request #12345", "id": 1, @@ -150,7 +150,7 @@ Object { } `; -exports[`api/gitlab createPr(branchName, title, body) returns the PR 2`] = ` +exports[`platform/gitlab createPr(branchName, title, body) returns the PR 2`] = ` Array [ Array [ "projects/undefined/merge_requests", @@ -167,7 +167,7 @@ Array [ ] `; -exports[`api/gitlab createPr(branchName, title, body) uses default branch 1`] = ` +exports[`platform/gitlab createPr(branchName, title, body) uses default branch 1`] = ` Object { "displayNumber": "Merge Request #12345", "id": 1, @@ -176,7 +176,7 @@ Object { } `; -exports[`api/gitlab createPr(branchName, title, body) uses default branch 2`] = ` +exports[`platform/gitlab createPr(branchName, title, body) uses default branch 2`] = ` Array [ Array [ "projects/undefined/merge_requests", @@ -193,7 +193,7 @@ Array [ ] `; -exports[`api/gitlab findFilePaths(fileName) should return the files matching the fileName 1`] = ` +exports[`platform/gitlab findFilePaths(fileName) should return the files matching the fileName 1`] = ` Array [ "package.json", "src/app/package.json", @@ -201,11 +201,11 @@ Array [ ] `; -exports[`api/gitlab getBranch returns a branch 1`] = `"foo"`; +exports[`platform/gitlab getBranch returns a branch 1`] = `"foo"`; -exports[`api/gitlab getBranchLastCommitTime should return a Date 1`] = `2012-09-20T08:50:22.000Z`; +exports[`platform/gitlab getBranchLastCommitTime should return a Date 1`] = `2012-09-20T08:50:22.000Z`; -exports[`api/gitlab getBranchPr(branchName) should return null if no PR exists 1`] = ` +exports[`platform/gitlab getBranchPr(branchName) should return null if no PR exists 1`] = ` Array [ Array [ "projects/owned", @@ -225,7 +225,7 @@ Array [ ] `; -exports[`api/gitlab getBranchPr(branchName) should return the PR object 1`] = ` +exports[`platform/gitlab getBranchPr(branchName) should return the PR object 1`] = ` Array [ Array [ "projects/owned", @@ -251,7 +251,7 @@ Array [ ] `; -exports[`api/gitlab getBranchPr(branchName) should return the PR object 2`] = ` +exports[`platform/gitlab getBranchPr(branchName) should return the PR object 2`] = ` Object { "additions": 1, "base": Object { @@ -267,28 +267,28 @@ Object { } `; -exports[`api/gitlab getCommitMessages() returns commits messages 1`] = ` +exports[`platform/gitlab getCommitMessages() returns commits messages 1`] = ` Array [ "foo", "bar", ] `; -exports[`api/gitlab getFile(filePath, branchName) gets the file with v3 1`] = `Object {}`; +exports[`platform/gitlab getFile(filePath, branchName) gets the file with v3 1`] = `Object {}`; -exports[`api/gitlab getFile(filePath, branchName) gets the file with v3 2`] = `"foo"`; +exports[`platform/gitlab getFile(filePath, branchName) gets the file with v3 2`] = `"foo"`; -exports[`api/gitlab getFile(filePath, branchName) gets the file with v4 by default 1`] = `"foo"`; +exports[`platform/gitlab getFile(filePath, branchName) gets the file with v4 by default 1`] = `"foo"`; -exports[`api/gitlab getFileContent(filePath, branchName) gets the file 1`] = `"~�"`; +exports[`platform/gitlab getFileContent(filePath, branchName) gets the file 1`] = `"~�"`; -exports[`api/gitlab getFileContent(filePath, branchName) throws error for non-404 1`] = ` +exports[`platform/gitlab getFileContent(filePath, branchName) throws error for non-404 1`] = ` Object { "statusCode": 403, } `; -exports[`api/gitlab getPr(prNo) returns the PR 1`] = ` +exports[`platform/gitlab getPr(prNo) returns the PR 1`] = ` Object { "body": "a merge request", "canRebase": true, @@ -305,7 +305,7 @@ Object { } `; -exports[`api/gitlab getRepos should return an array of repos 1`] = ` +exports[`platform/gitlab getRepos should return an array of repos 1`] = ` Array [ Array [ "projects?membership=true&per_page=100", @@ -316,14 +316,14 @@ Array [ ] `; -exports[`api/gitlab getRepos should return an array of repos 2`] = ` +exports[`platform/gitlab getRepos should return an array of repos 2`] = ` Array [ "a/b", "c/d", ] `; -exports[`api/gitlab getRepos should support a custom endpoint 1`] = ` +exports[`platform/gitlab getRepos should support a custom endpoint 1`] = ` Array [ Array [ "projects?membership=true&per_page=100", @@ -334,14 +334,14 @@ Array [ ] `; -exports[`api/gitlab getRepos should support a custom endpoint 2`] = ` +exports[`platform/gitlab getRepos should support a custom endpoint 2`] = ` Array [ "a/b", "c/d", ] `; -exports[`api/gitlab initRepo should initialise the config for the repo - 0 1`] = ` +exports[`platform/gitlab initRepo should initialise the config for the repo - 0 1`] = ` Array [ Array [ "projects/owned", @@ -355,9 +355,9 @@ Array [ ] `; -exports[`api/gitlab initRepo should initialise the config for the repo - 0 2`] = `Object {}`; +exports[`platform/gitlab initRepo should initialise the config for the repo - 0 2`] = `Object {}`; -exports[`api/gitlab initRepo should initialise the config for the repo - 1 1`] = ` +exports[`platform/gitlab initRepo should initialise the config for the repo - 1 1`] = ` Array [ Array [ "projects/owned", @@ -371,9 +371,9 @@ Array [ ] `; -exports[`api/gitlab initRepo should initialise the config for the repo - 1 2`] = `Object {}`; +exports[`platform/gitlab initRepo should initialise the config for the repo - 1 2`] = `Object {}`; -exports[`api/gitlab initRepo should initialise the config for the repo - 2 1`] = ` +exports[`platform/gitlab initRepo should initialise the config for the repo - 2 1`] = ` Array [ Array [ "projects/owned", @@ -387,13 +387,13 @@ Array [ ] `; -exports[`api/gitlab initRepo should initialise the config for the repo - 2 2`] = `Object {}`; +exports[`platform/gitlab initRepo should initialise the config for the repo - 2 2`] = `Object {}`; -exports[`api/gitlab initRepo should use api v4 1`] = `Object {}`; +exports[`platform/gitlab initRepo should use api v4 1`] = `Object {}`; -exports[`api/gitlab initRepo uses provided logger 1`] = `Object {}`; +exports[`platform/gitlab initRepo uses provided logger 1`] = `Object {}`; -exports[`api/gitlab setBaseBranch(branchName) sets the base branch 1`] = ` +exports[`platform/gitlab setBaseBranch(branchName) sets the base branch 1`] = ` Array [ Array [ "projects/owned", diff --git a/test/api/gh-got-wrapper.spec.js b/test/platform/gh-got-wrapper.spec.js similarity index 97% rename from test/api/gh-got-wrapper.spec.js rename to test/platform/gh-got-wrapper.spec.js index adf439a933..785c5b70a2 100644 --- a/test/api/gh-got-wrapper.spec.js +++ b/test/platform/gh-got-wrapper.spec.js @@ -1,9 +1,9 @@ -const get = require('../../lib/api/gh-got-wrapper'); +const get = require('../../lib/platform/gh-got-wrapper'); const ghGot = require('gh-got'); jest.mock('gh-got'); -describe('api/gh-got-wrapper', () => { +describe('platform/gh-got-wrapper', () => { const body = ['a', 'b']; beforeEach(() => { jest.resetAllMocks(); diff --git a/test/api/github.spec.js b/test/platform/github.spec.js similarity index 99% rename from test/api/github.spec.js rename to test/platform/github.spec.js index 4dab883001..d798f1f1bd 100644 --- a/test/api/github.spec.js +++ b/test/platform/github.spec.js @@ -1,6 +1,6 @@ const logger = require('../_fixtures/logger'); -describe('api/github', () => { +describe('platform/github', () => { let github; let get; beforeEach(() => { @@ -10,9 +10,9 @@ describe('api/github', () => { // reset module jest.resetModules(); - jest.mock('../../lib/api/gh-got-wrapper'); - get = require('../../lib/api/gh-got-wrapper'); - github = require('../../lib/api/github'); + jest.mock('../../lib/platform/gh-got-wrapper'); + get = require('../../lib/platform/gh-got-wrapper'); + github = require('../../lib/platform/github'); }); describe('getInstallations', () => { diff --git a/test/api/gitlab.spec.js b/test/platform/gitlab.spec.js similarity index 99% rename from test/api/gitlab.spec.js rename to test/platform/gitlab.spec.js index bf86986367..775e955195 100644 --- a/test/api/gitlab.spec.js +++ b/test/platform/gitlab.spec.js @@ -1,6 +1,6 @@ const logger = require('../_fixtures/logger'); -describe('api/gitlab', () => { +describe('platform/gitlab', () => { let gitlab; let get; beforeEach(() => { @@ -10,9 +10,9 @@ describe('api/gitlab', () => { // reset module jest.resetModules(); - jest.mock('../../lib/api/gl-got-wrapper'); - gitlab = require('../../lib/api/gitlab'); - get = require('../../lib/api/gl-got-wrapper'); + jest.mock('../../lib/platform/gl-got-wrapper'); + gitlab = require('../../lib/platform/gitlab'); + get = require('../../lib/platform/gl-got-wrapper'); }); describe('getRepos', () => { diff --git a/test/api/gl-got-wrapper.spec.js b/test/platform/gl-got-wrapper.spec.js similarity index 94% rename from test/api/gl-got-wrapper.spec.js rename to test/platform/gl-got-wrapper.spec.js index 3f2fd4bcdd..0e2b632613 100644 --- a/test/api/gl-got-wrapper.spec.js +++ b/test/platform/gl-got-wrapper.spec.js @@ -1,9 +1,9 @@ -const get = require('../../lib/api/gl-got-wrapper'); +const get = require('../../lib/platform/gl-got-wrapper'); const glGot = require('gl-got'); jest.mock('gl-got'); -describe('api/gl-got-wrapper', () => { +describe('platform/gl-got-wrapper', () => { const body = ['a', 'b']; beforeEach(() => { jest.resetAllMocks(); diff --git a/test/workers/repository/apis.spec.js b/test/workers/repository/apis.spec.js index 2b21ad5e3f..f1d4fab817 100644 --- a/test/workers/repository/apis.spec.js +++ b/test/workers/repository/apis.spec.js @@ -3,14 +3,14 @@ const jsonValidator = require('json-dup-key-validator'); const apis = require('../../../lib/workers/repository/apis'); const logger = require('../../_fixtures/logger'); -const githubApi = require('../../../lib/api/github'); -const gitlabApi = require('../../../lib/api/gitlab'); +const githubApi = require('../../../lib/platform/github'); +const gitlabApi = require('../../../lib/platform/gitlab'); const npmApi = require('../../../lib/api/npm'); const defaultConfig = require('../../../lib/config/defaults').getConfig(); -jest.mock('../../../lib/api/github'); -jest.mock('../../../lib/api/gitlab'); +jest.mock('../../../lib/platform/github'); +jest.mock('../../../lib/platform/gitlab'); jest.mock('../../../lib/api/npm'); describe('workers/repository/apis', () => { -- GitLab