From 7261bec9010878998df575db7442177f8ccd9afc Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Thu, 26 Aug 2021 06:56:28 +0200 Subject: [PATCH] feat(gitlab): allow override server version (#11416) --- docs/usage/self-hosted-experimental.md | 7 +++++++ lib/platform/gitlab/index.md | 10 ++++++++++ lib/platform/gitlab/index.ts | 17 ++++++++++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/docs/usage/self-hosted-experimental.md b/docs/usage/self-hosted-experimental.md index 23b90e9ca1..947824e673 100644 --- a/docs/usage/self-hosted-experimental.md +++ b/docs/usage/self-hosted-experimental.md @@ -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. diff --git a/lib/platform/gitlab/index.md b/lib/platform/gitlab/index.md index cd05a459cd..e39eef5c6b 100644 --- a/lib/platform/gitlab/index.md +++ b/lib/platform/gitlab/index.md @@ -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` diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 13ab464a81..688437f3cc 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -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( @@ -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; -- GitLab