From ec549af1c4f362ce490a59c07e0cc66c50c4084e Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Tue, 24 Aug 2021 19:07:06 +0200 Subject: [PATCH] feat(gitlab): allow override gitAuthor (#11408) --- lib/platform/github/index.ts | 8 ++------ lib/platform/gitlab/index.spec.ts | 13 +++++++++++++ lib/platform/gitlab/index.ts | 26 ++++++++++++++------------ lib/platform/types.ts | 5 +++-- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index a4c7070edb..b9b3ca365d 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -35,6 +35,7 @@ import type { FindPRConfig, Issue, MergePRConfig, + PlatformParams, PlatformResult, Pr, RepoParams, @@ -80,12 +81,7 @@ export async function initPlatform({ token, username, gitAuthor, -}: { - endpoint: string; - token: string; - username?: string; - gitAuthor?: string; -}): Promise<PlatformResult> { +}: PlatformParams): Promise<PlatformResult> { if (!token) { throw new Error('Init: You must configure a GitHub personal access token'); } diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts index ba8effbea1..e31a3a5523 100644 --- a/lib/platform/gitlab/index.spec.ts +++ b/lib/platform/gitlab/index.spec.ts @@ -115,6 +115,19 @@ describe('platform/gitlab/index', () => { ).toMatchSnapshot(); expect(httpMock.getTrace()).toMatchSnapshot(); }); + + it(`should reuse existing gitAuthor`, async () => { + httpMock.scope(gitlabApiHost).get('/api/v4/version').reply(200, { + version: '13.3.6-ee', + }); + expect( + await gitlab.initPlatform({ + token: 'some-token', + endpoint: undefined, + gitAuthor: 'somebody', + }) + ).toEqual({ endpoint: 'https://gitlab.com/api/v4/' }); + }); }); describe('getRepos', () => { diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index bd2e7afd6d..13ab464a81 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -79,6 +79,7 @@ let draftPrefix = DRAFT_PREFIX; export async function initPlatform({ endpoint, token, + gitAuthor, }: PlatformParams): Promise<PlatformResult> { if (!token) { throw new Error('Init: You must configure a GitLab personal access token'); @@ -89,16 +90,20 @@ export async function initPlatform({ } else { logger.debug('Using default GitLab endpoint: ' + defaults.endpoint); } - let gitAuthor: string; + const platformConfig: PlatformResult = { + endpoint: defaults.endpoint, + }; let gitlabVersion: string; try { - const user = ( - await gitlabApi.getJson<{ email: string; name: string; id: number }>( - `user`, - { token } - ) - ).body; - gitAuthor = `${user.name} <${user.email}>`; + if (!gitAuthor) { + const user = ( + await gitlabApi.getJson<{ email: string; name: string; id: number }>( + `user`, + { token } + ) + ).body; + platformConfig.gitAuthor = `${user.name} <${user.email}>`; + } // version is 'x.y.z-edition', so not strictly semver; need to strip edition gitlabVersion = ( await gitlabApi.getJson<{ version: string }>('version', { token }) @@ -115,10 +120,7 @@ export async function initPlatform({ draftPrefix = lt(gitlabVersion, '13.2.0') ? DRAFT_PREFIX_DEPRECATED : DRAFT_PREFIX; - const platformConfig: PlatformResult = { - endpoint: defaults.endpoint, - gitAuthor, - }; + return platformConfig; } diff --git a/lib/platform/types.ts b/lib/platform/types.ts index 04981cff72..2f95f8c609 100644 --- a/lib/platform/types.ts +++ b/lib/platform/types.ts @@ -14,12 +14,13 @@ export interface PlatformParams { token?: string; username?: string; password?: string; + gitAuthor?: string; } export interface PlatformResult { endpoint: string; - renovateUsername?: any; - gitAuthor?: any; + renovateUsername?: string; + gitAuthor?: string; } export interface RepoResult { -- GitLab