From a9525062596e82a69ea3b1e822e40ac0ebfce367 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@keylocation.sg> Date: Wed, 28 Jun 2017 10:10:40 +0200 Subject: [PATCH] Perform gitlab terminology translation in api (#366) --- lib/api/gitlab.js | 10 ++++++++-- lib/workers/repository/onboarding.js | 6 +----- test/api/gitlab.spec.js | 2 +- test/workers/repository/onboarding.spec.js | 10 ---------- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/api/gitlab.js b/lib/api/gitlab.js index 36afaccba3..745eca25f0 100644 --- a/lib/api/gitlab.js +++ b/lib/api/gitlab.js @@ -254,13 +254,16 @@ async function checkForClosedPr(branchName, prTitle) { async function createPr(branchName, title, body) { logger.debug(`Creating Merge Request: ${title}`); + const description = body + .replace(/Pull Request/g, 'Merge Request') + .replace(/PR/g, 'MR'); const res = await glGot.post(`projects/${config.repoName}/merge_requests`, { body: { source_branch: branchName, target_branch: config.defaultBranch, remove_source_branch: true, title, - description: body, + description, }, }); const pr = res.body; @@ -295,10 +298,13 @@ async function getPr(prNo) { } async function updatePr(prNo, title, body) { + const description = body + .replace(/Pull Request/g, 'Merge Request') + .replace(/PR/g, 'MR'); await glGot.put(`projects/${config.repoName}/merge_requests/${prNo}`, { body: { title, - description: body, + description, }, }); } diff --git a/lib/workers/repository/onboarding.js b/lib/workers/repository/onboarding.js index 591d636e35..4ee7ad0c48 100644 --- a/lib/workers/repository/onboarding.js +++ b/lib/workers/repository/onboarding.js @@ -9,7 +9,7 @@ module.exports = { async function onboardRepository(config) { const defaultConfig = defaultsParser.getOnboardingConfig(); - let prBody = `Welcome to [Renovate](https://keylocation.sg/our-tech/renovate)! Once you close this Pull Request, we will begin keeping your dependencies up-to-date via automated Pull Requests. + const prBody = `Welcome to [Renovate](https://keylocation.sg/our-tech/renovate)! Once you close this Pull Request, we will begin keeping your dependencies up-to-date via automated Pull Requests. The [Configuration](https://github.com/singapore/renovate/blob/master/docs/configuration.md) and [Configuration FAQ](https://github.com/singapore/renovate/blob/master/docs/faq.md) documents should be helpful. @@ -19,10 +19,6 @@ You do not need to *merge* this Pull Request - renovate will begin even if it's In fact, you only need to add a \`renovate.json\` file to your repository if you wish to override any default settings. The file is included as part of this PR only in case you wish to change default settings before you start. If the default settings are all suitable for you, simply close this Pull Request unmerged and your first renovation will begin the next time the program is run.`; - if (config.platform === 'gitlab') { - defaultConfig.platform = 'gitlab'; - prBody = prBody.replace(/Pull Request/g, 'Merge Request'); - } const defaultConfigString = `${stringify(defaultConfig)}\n`; await config.api.commitFilesToBranch( 'renovate/configure', diff --git a/test/api/gitlab.spec.js b/test/api/gitlab.spec.js index b4fc7a0a40..2ae6ff3d97 100644 --- a/test/api/gitlab.spec.js +++ b/test/api/gitlab.spec.js @@ -417,7 +417,7 @@ describe('api/gitlab', () => { describe('updatePr(prNo, title, body)', () => { jest.resetAllMocks(); it('updates the PR', async () => { - await gitlab.updatePr(); + await gitlab.updatePr(1, 'title', 'body'); expect(glGot.put.mock.calls.length).toEqual(1); }); }); diff --git a/test/workers/repository/onboarding.spec.js b/test/workers/repository/onboarding.spec.js index d11814fda2..24ca1ff910 100644 --- a/test/workers/repository/onboarding.spec.js +++ b/test/workers/repository/onboarding.spec.js @@ -26,16 +26,6 @@ describe('lib/workers/repository/onboarding', () => { ).toBe(-1); expect(config.api.commitFilesToBranch.mock.calls).toMatchSnapshot(); }); - it('should adapt for gitlab phrasing', async () => { - config.platform = 'gitlab'; - await onboarding.onboardRepository(config); - expect(config.api.createPr.mock.calls[0][2].indexOf('Pull Request')).toBe( - -1 - ); - expect( - config.api.createPr.mock.calls[0][2].indexOf('Merge Request') - ).not.toBe(-1); - }); }); describe('getOnboardingStatus(config)', () => { let config; -- GitLab