diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap index e265a6c591caf6..5f4f2125c497c3 100644 --- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap @@ -161,17 +161,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, ] `; @@ -303,17 +292,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, ] `; @@ -330,17 +308,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -409,17 +376,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -461,17 +417,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -513,17 +458,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -551,17 +485,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -589,17 +512,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -638,17 +550,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -922,17 +823,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -959,6 +849,7 @@ Object { "deletions": 1, "displayNumber": "Merge Request #91", "iid": 91, + "isConflicted": true, "isModified": true, "isStale": false, "number": 91, @@ -982,17 +873,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1053,17 +933,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1091,17 +960,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1129,17 +987,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1167,17 +1014,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1205,17 +1041,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1243,17 +1068,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1281,17 +1095,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, ] `; @@ -1308,17 +1111,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1346,17 +1138,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1384,17 +1165,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1540,17 +1310,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "headers": Object { "accept": "application/json", @@ -1613,17 +1372,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo%2Fproject", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, ] `; @@ -1640,17 +1388,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo%2Fproject", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, ] `; @@ -1768,17 +1505,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo%2Fproject", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, ] `; @@ -1795,17 +1521,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo%2Fproject", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, ] `; @@ -1980,17 +1695,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, ] `; @@ -2007,17 +1711,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, ] `; @@ -2034,17 +1727,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "body": "{\\"state\\":\\"success\\",\\"description\\":\\"some-description\\",\\"context\\":\\"some-context\\",\\"target_url\\":\\"some-url\\"}", "headers": Object { @@ -2086,17 +1768,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "body": "{\\"state\\":\\"failed\\",\\"description\\":\\"some-description\\",\\"context\\":\\"some-context\\",\\"target_url\\":\\"some-url\\"}", "headers": Object { @@ -2138,17 +1809,6 @@ Array [ "method": "GET", "url": "https://gitlab.com/api/v4/projects/some%2Frepo", }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, Object { "body": "{\\"state\\":\\"pending\\",\\"description\\":\\"some-description\\",\\"context\\":\\"some-context\\",\\"target_url\\":\\"some-url\\"}", "headers": Object { diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts index 4ebdce81a2170a..0ee02ac057c89a 100644 --- a/lib/platform/gitlab/index.spec.ts +++ b/lib/platform/gitlab/index.spec.ts @@ -137,19 +137,13 @@ describe('platform/gitlab', () => { ): Promise { const repo = repoParams.repository; const justRepo = repo.split('/').slice(0, 2).join('/'); - scope - .get(`/api/v4/projects/${encodeURIComponent(repo)}`) - .reply( - 200, - repoResp || { - default_branch: 'master', - http_url_to_repo: `https://gitlab.com/${justRepo}.git`, - } - ) - .get('/api/v4/user') - .reply(200, { - email: 'a@b.com', - }); + scope.get(`/api/v4/projects/${encodeURIComponent(repo)}`).reply( + 200, + repoResp || { + default_branch: 'master', + http_url_to_repo: `https://gitlab.com/${justRepo}.git`, + } + ); await gitlab.initRepo(repoParams); return scope; } @@ -182,11 +176,7 @@ describe('platform/gitlab', () => { httpMock .scope(gitlabApiHost) .get('/api/v4/projects/some%2Frepo%2Fproject') - .reply(200, []) - .get('/api/v4/user') - .reply(200, { - email: 'a@b.com', - }); + .reply(200, []); await gitlab.initRepo({ repository: 'some/repo/project', localDir: '', @@ -295,8 +285,6 @@ describe('platform/gitlab', () => { it('should fall back if http_url_to_repo is empty', async () => { httpMock .scope(gitlabApiHost) - .get('/api/v4/user') - .reply(200, {}) .get('/api/v4/projects/some%2Frepo%2Fproject') .reply(200, { default_branch: 'master', @@ -353,10 +341,6 @@ describe('platform/gitlab', () => { .reply(200, { default_branch: 'master', http_url_to_repo: `https://gitlab.com/some/repo.git`, - }) - .get('/api/v4/user') - .reply(200, { - email: 'a@b.com', }); await gitlab.initRepo({ repository: 'some/repo', @@ -373,10 +357,6 @@ describe('platform/gitlab', () => { .reply(200, { default_branch: 'master', http_url_to_repo: `https://gitlab.com/some/repo.git`, - }) - .get('/api/v4/user') - .reply(200, { - email: 'a@b.com', }); await gitlab.initRepo({ repository: 'some/repo', @@ -1075,6 +1055,15 @@ describe('platform/gitlab', () => { }); }); describe('getPr(prNo)', () => { + beforeEach(() => { + global.gitAuthor = { + name: 'abccom', + email: 'a@b.com', + }; + }); + afterEach(() => { + delete global.gitAuthor; + }); it('returns the PR', async () => { httpMock .scope(gitlabApiHost) @@ -1092,7 +1081,7 @@ describe('platform/gitlab', () => { target_branch: 'master', }) .get('/api/v4/projects/undefined/repository/branches/some-branch') - .reply(200, { commit: {} }); + .reply(200, { commit: { author_email: global.gitAuthor.email } }); const pr = await gitlab.getPr(12345); expect(pr).toMatchSnapshot(); expect(httpMock.getTrace()).toMatchSnapshot(); diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index ea8c26f2809d07..5f81f17376fc6c 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -204,11 +204,6 @@ export async function initRepo({ config.baseBranch = config.defaultBranch; config.mergeMethod = res.body.merge_method || 'merge'; logger.debug(`${repository} default branch = ${config.baseBranch}`); - // Discover our user email - config.email = ( - await gitlabApi.getJson<{ email: string }>(`user`) - ).body.email; - logger.debug('Bot email=' + config.email); delete config.prList; logger.debug('Enabling Git FS'); const opts = hostRules.find({ @@ -481,12 +476,11 @@ export async function getPr(iid: number): Promise { ).body; const branchCommitEmail = branch && branch.commit ? branch.commit.author_email : null; - // istanbul ignore if - if (branchCommitEmail === config.email) { + if (branchCommitEmail === global.gitAuthor.email) { pr.isModified = false; } else { logger.debug( - { branchCommitEmail, configEmail: config.email, iid: pr.iid }, + { branchCommitEmail, configEmail: global.gitAuthor.email, iid: pr.iid }, 'Last committer to branch does not match bot email, so PR cannot be rebased.' ); pr.isModified = true;