Skip to content

Commit

Permalink
feat(gitlab): allow override server version (#11416)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Aug 26, 2021
1 parent f061fd0 commit 7261bec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
7 changes: 7 additions & 0 deletions docs/usage/self-hosted-experimental.md
Expand Up @@ -39,3 +39,10 @@ If set to any string, Renovate will use this as the `user-agent` it sends with H

If set to any value, Renovate will use a "hard" `process.exit()` once all work is done, even if a sub-process is otherwise delaying Node.js from exiting.
See <https://github.com/renovatebot/renovate/issues/8660> for background on why this was created.

## RENOVATE_X_PLATFORM_VERSION

If set, Renovate will use this string as GitLab server version instead of checking via the GitLab API.
This can be useful when you use the GitLab `CI_JOB_TOKEN` to authenticate Renovate.

Read [platform details](modules/platform/gitlab/index.md) to learn why we need the server version on GitLab.
10 changes: 10 additions & 0 deletions lib/platform/gitlab/index.md
Expand Up @@ -3,3 +3,13 @@
## Features awaiting implementation

- The `automergeStrategy` configuration option has not been implemented for this platform, and all values behave as if the value `auto` was used. Renovate will accept the Merge Request without further configuration, and respect the strategy defined in the Merge Request, and this cannot be overridden yet

## Server version dependent features

We use the GitLab [version API](https://docs.gitlab.com/ee/api/version.html) to fetch the server version.
You can use the experimental feature flag [`RENOVATE_X_PLATFORM_VERSION`](https://docs.renovatebot.com/self-hosted-experimental/#renovate_x_platform_version) to set a specific server version.
By setting the server version yourself, you save a API call that fetches the server version.

- Use `Draft:` MR prefix instead of `WIP:` prefix since `v13.2.0`
- Do not truncate Markdown body to 25K chars since `v13.4.0`
- Allow configure reviewers since `v13.9.0`
17 changes: 12 additions & 5 deletions lib/platform/gitlab/index.ts
Expand Up @@ -104,11 +104,18 @@ export async function initPlatform({
).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 })
).body.version.split('-')[0];
// istanbul ignore if: experimental feature
if (process.env.RENOVATE_X_PLATFORM_VERSION) {
gitlabVersion = process.env.RENOVATE_X_PLATFORM_VERSION;
} else {
const version = (
await gitlabApi.getJson<{ version: string }>('version', { token })
).body;
gitlabVersion = version.version;
}
logger.debug('GitLab version is: ' + gitlabVersion);
// version is 'x.y.z-edition', so not strictly semver; need to strip edition
[gitlabVersion] = gitlabVersion.split('-');
defaults.version = gitlabVersion;
} catch (err) {
logger.debug(
Expand All @@ -117,7 +124,7 @@ export async function initPlatform({
);
throw new Error('Init: Authentication failure');
}
draftPrefix = lt(gitlabVersion, '13.2.0')
draftPrefix = lt(defaults.version, '13.2.0')
? DRAFT_PREFIX_DEPRECATED
: DRAFT_PREFIX;

Expand Down

0 comments on commit 7261bec

Please sign in to comment.