Skip to content

Commit

Permalink
feat(gitlab): allow override gitAuthor (#11408)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Aug 24, 2021
1 parent 2f6e2ec commit ec549af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
8 changes: 2 additions & 6 deletions lib/platform/github/index.ts
Expand Up @@ -35,6 +35,7 @@ import type {
FindPRConfig,
Issue,
MergePRConfig,
PlatformParams,
PlatformResult,
Pr,
RepoParams,
Expand Down Expand Up @@ -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');
}
Expand Down
13 changes: 13 additions & 0 deletions lib/platform/gitlab/index.spec.ts
Expand Up @@ -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', () => {
Expand Down
26 changes: 14 additions & 12 deletions lib/platform/gitlab/index.ts
Expand Up @@ -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');
Expand All @@ -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 })
Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/platform/types.ts
Expand Up @@ -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 {
Expand Down

0 comments on commit ec549af

Please sign in to comment.