From 1f86b71fd5f9175cdb6ab8c673dbdf83082c2c2e Mon Sep 17 00:00:00 2001 From: Maksim Date: Wed, 6 Oct 2021 07:43:32 +0200 Subject: [PATCH] refactor: constants (#11690) --- lib/config/migration.spec.ts | 4 ++-- lib/config/options/index.ts | 4 ++-- lib/config/presets/local/index.ts | 21 ++++++----------- lib/constants/index.ts | 1 + lib/constants/platform.spec.ts | 19 ++++----------- lib/constants/platforms.ts | 18 ++++++++------- lib/datasource/go/index.ts | 4 ++-- lib/manager/composer/artifacts.spec.ts | 9 +++----- lib/manager/composer/artifacts.ts | 9 +++----- lib/manager/gomod/artifacts.ts | 4 ++-- lib/manager/pre-commit/extract.ts | 12 ++++------ lib/platform/azure/azure-got-wrapper.spec.ts | 8 +++---- lib/platform/azure/azure-got-wrapper.ts | 4 ++-- lib/platform/azure/index.ts | 4 ++-- lib/platform/bitbucket-server/index.ts | 4 ++-- lib/platform/bitbucket/index.ts | 4 ++-- lib/platform/gitea/index.ts | 6 ++--- lib/platform/github/index.ts | 10 ++++---- lib/platform/gitlab/index.ts | 4 ++-- lib/platform/index.spec.ts | 6 ++--- lib/util/host-rules.spec.ts | 23 ++++++++----------- lib/util/http/auth.spec.ts | 16 +++++-------- lib/util/http/auth.ts | 6 ++--- lib/util/http/bitbucket-server.spec.ts | 4 ++-- lib/util/http/bitbucket-server.ts | 4 ++-- lib/util/http/bitbucket.spec.ts | 4 ++-- lib/util/http/bitbucket.ts | 4 ++-- lib/util/http/gitea.ts | 4 ++-- lib/util/http/github.ts | 14 +++++------ lib/util/http/gitlab.spec.ts | 8 +++---- lib/util/http/gitlab.ts | 13 ++++------- lib/util/http/host-rules.spec.ts | 16 +++++-------- lib/util/http/host-rules.ts | 13 +++++------ lib/workers/global/autodiscover.spec.ts | 10 ++++---- lib/workers/global/config/parse/env.spec.ts | 13 ++++------- lib/workers/global/config/parse/env.ts | 4 ++-- lib/workers/global/index.spec.ts | 11 ++++----- lib/workers/pr/changelog/github.spec.ts | 8 +++---- lib/workers/pr/changelog/gitlab.spec.ts | 10 ++++---- lib/workers/pr/changelog/index.spec.ts | 10 ++++---- lib/workers/pr/changelog/source-github.ts | 4 ++-- lib/workers/pr/index.spec.ts | 4 ++-- .../repository/dependency-dashboard.spec.ts | 4 ++-- lib/workers/repository/finalise/prune.spec.ts | 4 ++-- 44 files changed, 161 insertions(+), 205 deletions(-) create mode 100644 lib/constants/index.ts diff --git a/lib/config/migration.spec.ts b/lib/config/migration.spec.ts index 462124b8e28b83..4aa9d4625c0db6 100644 --- a/lib/config/migration.spec.ts +++ b/lib/config/migration.spec.ts @@ -1,4 +1,4 @@ -import { PLATFORM_TYPE_GITHUB } from '../constants/platforms'; +import { PlatformId } from '../constants'; import { getConfig } from './defaults'; import { setGlobalConfig } from './global'; import * as configMigration from './migration'; @@ -20,7 +20,7 @@ describe('config/migration', () => { const config: TestRenovateConfig = { endpoints: [{}] as never, enabled: true, - platform: PLATFORM_TYPE_GITHUB, + platform: PlatformId.Github, hostRules: [ { platform: 'docker', diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index dc557c23e756fc..5030ea0a24d250 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -1,4 +1,4 @@ -import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import { getManagers } from '../../manager'; import { getPlatformList } from '../../platform'; import { getVersioningList } from '../../versioning'; @@ -559,7 +559,7 @@ const options: RenovateOptions[] = [ description: 'Platform type of repository.', type: 'string', allowedValues: getPlatformList(), - default: PLATFORM_TYPE_GITHUB, + default: PlatformId.Github, globalOnly: true, }, { diff --git a/lib/config/presets/local/index.ts b/lib/config/presets/local/index.ts index 319d513ce58b70..440197771eb268 100644 --- a/lib/config/presets/local/index.ts +++ b/lib/config/presets/local/index.ts @@ -1,11 +1,4 @@ -import { - PLATFORM_TYPE_AZURE, - PLATFORM_TYPE_BITBUCKET, - PLATFORM_TYPE_BITBUCKET_SERVER, - PLATFORM_TYPE_GITEA, - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, -} from '../../../constants/platforms'; +import { PlatformId } from '../../../constants'; import * as azure from '../azure'; import * as bitbucket from '../bitbucket'; import * as bitbucketServer from '../bitbucket-server'; @@ -15,12 +8,12 @@ import * as gitlab from '../gitlab'; import type { Preset, PresetConfig } from '../types'; const resolvers = { - [PLATFORM_TYPE_AZURE]: azure, - [PLATFORM_TYPE_BITBUCKET]: bitbucket, - [PLATFORM_TYPE_BITBUCKET_SERVER]: bitbucketServer, - [PLATFORM_TYPE_GITEA]: gitea, - [PLATFORM_TYPE_GITHUB]: github, - [PLATFORM_TYPE_GITLAB]: gitlab, + [PlatformId.Azure]: azure, + [PlatformId.Bitbucket]: bitbucket, + [PlatformId.BitbucketServer]: bitbucketServer, + [PlatformId.Gitea]: gitea, + [PlatformId.Github]: github, + [PlatformId.Gitlab]: gitlab, }; export function getPreset({ diff --git a/lib/constants/index.ts b/lib/constants/index.ts new file mode 100644 index 00000000000000..fef29321c3b365 --- /dev/null +++ b/lib/constants/index.ts @@ -0,0 +1 @@ +export * from './platforms'; diff --git a/lib/constants/platform.spec.ts b/lib/constants/platform.spec.ts index 7b2f536b8d3e40..c02a997356c320 100644 --- a/lib/constants/platform.spec.ts +++ b/lib/constants/platform.spec.ts @@ -7,8 +7,7 @@ import { id as POD_DS } from '../datasource/pod'; import { GITHUB_API_USING_HOST_TYPES, GITLAB_API_USING_HOST_TYPES, - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, + PlatformId, } from './platforms'; describe('constants/platform', () => { @@ -20,29 +19,21 @@ describe('constants/platform', () => { expect( GITLAB_API_USING_HOST_TYPES.includes(GitlabPackagesDatasource.id) ).toBeTrue(); - expect( - GITLAB_API_USING_HOST_TYPES.includes(PLATFORM_TYPE_GITLAB) - ).toBeTrue(); + expect(GITLAB_API_USING_HOST_TYPES.includes(PlatformId.Gitlab)).toBeTrue(); }); it('should be not part of the GITLAB_API_USING_HOST_TYPES ', () => { - expect( - GITLAB_API_USING_HOST_TYPES.includes(PLATFORM_TYPE_GITHUB) - ).toBeFalse(); + expect(GITLAB_API_USING_HOST_TYPES.includes(PlatformId.Github)).toBeFalse(); }); it('should be part of the GITHUB_API_USING_HOST_TYPES ', () => { expect(GITHUB_API_USING_HOST_TYPES.includes(GH_TAGS_DS)).toBeTrue(); expect(GITHUB_API_USING_HOST_TYPES.includes(GH_RELEASES_DS)).toBeTrue(); expect(GITHUB_API_USING_HOST_TYPES.includes(POD_DS)).toBeTrue(); - expect( - GITHUB_API_USING_HOST_TYPES.includes(PLATFORM_TYPE_GITHUB) - ).toBeTrue(); + expect(GITHUB_API_USING_HOST_TYPES.includes(PlatformId.Github)).toBeTrue(); }); it('should be not part of the GITHUB_API_USING_HOST_TYPES ', () => { - expect( - GITHUB_API_USING_HOST_TYPES.includes(PLATFORM_TYPE_GITLAB) - ).toBeFalse(); + expect(GITHUB_API_USING_HOST_TYPES.includes(PlatformId.Gitlab)).toBeFalse(); }); }); diff --git a/lib/constants/platforms.ts b/lib/constants/platforms.ts index 0bee6d8191f78b..83ce1e763c20ab 100644 --- a/lib/constants/platforms.ts +++ b/lib/constants/platforms.ts @@ -1,19 +1,21 @@ -export const PLATFORM_TYPE_AZURE = 'azure'; -export const PLATFORM_TYPE_BITBUCKET = 'bitbucket'; -export const PLATFORM_TYPE_BITBUCKET_SERVER = 'bitbucket-server'; -export const PLATFORM_TYPE_GITEA = 'gitea'; -export const PLATFORM_TYPE_GITHUB = 'github'; -export const PLATFORM_TYPE_GITLAB = 'gitlab'; +export const enum PlatformId { + Azure = 'azure', + Bitbucket = 'bitbucket', + BitbucketServer = 'bitbucket-server', + Gitea = 'gitea', + Github = 'github', + Gitlab = 'gitlab', +} export const GITHUB_API_USING_HOST_TYPES = [ - PLATFORM_TYPE_GITHUB, + PlatformId.Github, 'github-releases', 'github-tags', 'pod', ]; export const GITLAB_API_USING_HOST_TYPES = [ - PLATFORM_TYPE_GITLAB, + PlatformId.Gitlab, 'gitlab-releases', 'gitlab-tags', 'gitlab-packages', diff --git a/lib/datasource/go/index.ts b/lib/datasource/go/index.ts index 4936c3a721970f..42581e7c6dc335 100644 --- a/lib/datasource/go/index.ts +++ b/lib/datasource/go/index.ts @@ -1,5 +1,5 @@ import URL from 'url'; -import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import { logger } from '../../logger'; import * as hostRules from '../../util/host-rules'; import { regEx } from '../../util/regex'; @@ -92,7 +92,7 @@ async function getDatasource(goModule: string): Promise { } const opts = hostRules.find({ - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, url: goSourceUrl, }); if (opts.token) { diff --git a/lib/manager/composer/artifacts.spec.ts b/lib/manager/composer/artifacts.spec.ts index 0f168ff823842e..42cfe6ea50ad2f 100644 --- a/lib/manager/composer/artifacts.spec.ts +++ b/lib/manager/composer/artifacts.spec.ts @@ -3,10 +3,7 @@ import { envMock, exec, mockExecAll } from '../../../test/exec-util'; import { env, fs, git, mocked, partial } from '../../../test/util'; import { setGlobalConfig } from '../../config/global'; import type { RepoGlobalConfig } from '../../config/types'; -import { - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, -} from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import * as _datasource from '../../datasource'; import * as datasourcePackagist from '../../datasource/packagist'; import * as docker from '../../util/exec/docker'; @@ -97,12 +94,12 @@ describe('manager/composer/artifacts', () => { it('uses hostRules to set COMPOSER_AUTH', async () => { hostRules.add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'api.github.com', token: 'github-token', }); hostRules.add({ - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, matchHost: 'gitlab.com', token: 'gitlab-token', }); diff --git a/lib/manager/composer/artifacts.ts b/lib/manager/composer/artifacts.ts index 916cde6b32281a..50862c753bbcd9 100644 --- a/lib/manager/composer/artifacts.ts +++ b/lib/manager/composer/artifacts.ts @@ -1,14 +1,11 @@ import is from '@sindresorhus/is'; import { quote } from 'shlex'; import { getGlobalConfig } from '../../config/global'; +import { PlatformId } from '../../constants'; import { SYSTEM_INSUFFICIENT_DISK_SPACE, TEMPORARY_ERROR, } from '../../constants/error-messages'; -import { - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, -} from '../../constants/platforms'; import * as datasourcePackagist from '../../datasource/packagist'; import { logger } from '../../logger'; import { ExecOptions, exec } from '../../util/exec'; @@ -36,7 +33,7 @@ function getAuthJson(): string | null { const authJson: AuthJson = {}; const githubCredentials = hostRules.find({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, url: 'https://api.github.com/', }); if (githubCredentials?.token) { @@ -46,7 +43,7 @@ function getAuthJson(): string | null { } hostRules - .findAll({ hostType: PLATFORM_TYPE_GITLAB }) + .findAll({ hostType: PlatformId.Gitlab }) ?.forEach((gitlabHostRule) => { if (gitlabHostRule?.token) { const host = gitlabHostRule.resolvedHost || 'gitlab.com'; diff --git a/lib/manager/gomod/artifacts.ts b/lib/manager/gomod/artifacts.ts index 63faa1101dac48..a4dc7a33b89141 100644 --- a/lib/manager/gomod/artifacts.ts +++ b/lib/manager/gomod/artifacts.ts @@ -2,8 +2,8 @@ import is from '@sindresorhus/is'; import { quote } from 'shlex'; import { dirname, join } from 'upath'; import { getGlobalConfig } from '../../config/global'; +import { PlatformId } from '../../constants'; import { TEMPORARY_ERROR } from '../../constants/error-messages'; -import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; import { logger } from '../../logger'; import { ExecOptions, exec } from '../../util/exec'; import { ensureCacheDir, readLocalFile, writeLocalFile } from '../../util/fs'; @@ -19,7 +19,7 @@ import type { function getPreCommands(): string[] | null { const credentials = find({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, url: 'https://api.github.com/', }); let preCommands = null; diff --git a/lib/manager/pre-commit/extract.ts b/lib/manager/pre-commit/extract.ts index 2708d1ddd86e2f..aef244b22b20cf 100644 --- a/lib/manager/pre-commit/extract.ts +++ b/lib/manager/pre-commit/extract.ts @@ -1,10 +1,6 @@ import is from '@sindresorhus/is'; import { load } from 'js-yaml'; -import { - PLATFORM_TYPE_GITEA, - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, -} from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import { id as githubTagsId } from '../../datasource/github-tags'; import { id as gitlabTagsId } from '../../datasource/gitlab-tags'; import { logger } from '../../logger'; @@ -55,9 +51,9 @@ function determineDatasource( return { skipReason: SkipReason.UnknownRegistry, registryUrls: [hostname] }; } for (const [hostType, sourceId] of [ - [PLATFORM_TYPE_GITEA, gitlabTagsId], - [PLATFORM_TYPE_GITHUB, githubTagsId], - [PLATFORM_TYPE_GITLAB, gitlabTagsId], + [PlatformId.Gitea, gitlabTagsId], + [PlatformId.Github, githubTagsId], + [PlatformId.Gitlab, gitlabTagsId], ]) { if (!isEmptyObject(find({ hostType, url: hostUrl }))) { logger.debug( diff --git a/lib/platform/azure/azure-got-wrapper.spec.ts b/lib/platform/azure/azure-got-wrapper.spec.ts index 1907cb3285faf9..bf7e14a4eb5c04 100644 --- a/lib/platform/azure/azure-got-wrapper.spec.ts +++ b/lib/platform/azure/azure-got-wrapper.spec.ts @@ -1,4 +1,4 @@ -import { PLATFORM_TYPE_AZURE } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import * as _hostRules from '../../util/host-rules'; describe('platform/azure/azure-got-wrapper', () => { @@ -19,7 +19,7 @@ describe('platform/azure/azure-got-wrapper', () => { }); it('should set personal access token and endpoint', () => { hostRules.add({ - hostType: PLATFORM_TYPE_AZURE, + hostType: PlatformId.Azure, token: '123test', matchHost: 'https://dev.azure.com/renovate1', }); @@ -35,7 +35,7 @@ describe('platform/azure/azure-got-wrapper', () => { }); it('should set bearer token and endpoint', () => { hostRules.add({ - hostType: PLATFORM_TYPE_AZURE, + hostType: PlatformId.Azure, token: 'testtoken', matchHost: 'https://dev.azure.com/renovate2', }); @@ -52,7 +52,7 @@ describe('platform/azure/azure-got-wrapper', () => { it('should set password and endpoint', () => { hostRules.add({ - hostType: PLATFORM_TYPE_AZURE, + hostType: PlatformId.Azure, username: 'user', password: 'pass', matchHost: 'https://dev.azure.com/renovate3', diff --git a/lib/platform/azure/azure-got-wrapper.ts b/lib/platform/azure/azure-got-wrapper.ts index 9b1c6c76aed3ed..e0f06a0ccaf8ee 100644 --- a/lib/platform/azure/azure-got-wrapper.ts +++ b/lib/platform/azure/azure-got-wrapper.ts @@ -4,11 +4,11 @@ import { ICoreApi } from 'azure-devops-node-api/CoreApi'; import { IGitApi } from 'azure-devops-node-api/GitApi'; import { IPolicyApi } from 'azure-devops-node-api/PolicyApi'; import { IRequestHandler } from 'azure-devops-node-api/interfaces/common/VsoBaseInterfaces'; -import { PLATFORM_TYPE_AZURE } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import { HostRule } from '../../types'; import * as hostRules from '../../util/host-rules'; -const hostType = PLATFORM_TYPE_AZURE; +const hostType = PlatformId.Azure; let endpoint: string; function getAuthenticationHandler(config: HostRule): IRequestHandler { diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index a280295d6262bf..9d19e3d2ef283b 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -8,8 +8,8 @@ import { PullRequestStatus, } from 'azure-devops-node-api/interfaces/GitInterfaces'; import delay from 'delay'; +import { PlatformId } from '../../constants'; import { REPOSITORY_EMPTY } from '../../constants/error-messages'; -import { PLATFORM_TYPE_AZURE } from '../../constants/platforms'; import { logger } from '../../logger'; import { BranchStatus, PrState, VulnerabilityAlert } from '../../types'; import * as git from '../../util/git'; @@ -73,7 +73,7 @@ const defaults: { endpoint?: string; hostType: string; } = { - hostType: PLATFORM_TYPE_AZURE, + hostType: PlatformId.Azure, }; export function initPlatform({ diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index 2bc866b66464fd..d88faecdf32dfe 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -2,12 +2,12 @@ import url from 'url'; import is from '@sindresorhus/is'; import delay from 'delay'; import type { PartialDeep } from 'type-fest'; +import { PlatformId } from '../../constants'; import { REPOSITORY_CHANGED, REPOSITORY_EMPTY, REPOSITORY_NOT_FOUND, } from '../../constants/error-messages'; -import { PLATFORM_TYPE_BITBUCKET_SERVER } from '../../constants/platforms'; import { logger } from '../../logger'; import { BranchStatus, PrState, VulnerabilityAlert } from '../../types'; import { GitProtocol } from '../../types/git'; @@ -68,7 +68,7 @@ const defaults: { endpoint?: string; hostType: string; } = { - hostType: PLATFORM_TYPE_BITBUCKET_SERVER, + hostType: PlatformId.BitbucketServer, }; /* istanbul ignore next */ diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index d9df2f0870e30f..04ff05b3cd90de 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -1,8 +1,8 @@ import URL from 'url'; import is from '@sindresorhus/is'; import parseDiff from 'parse-diff'; +import { PlatformId } from '../../constants'; import { REPOSITORY_NOT_FOUND } from '../../constants/error-messages'; -import { PLATFORM_TYPE_BITBUCKET } from '../../constants/platforms'; import { logger } from '../../logger'; import { BranchStatus, PrState, VulnerabilityAlert } from '../../types'; import * as git from '../../util/git'; @@ -127,7 +127,7 @@ export async function initRepo({ }: RepoParams): Promise { logger.debug(`initRepo("${repository}")`); const opts = hostRules.find({ - hostType: PLATFORM_TYPE_BITBUCKET, + hostType: PlatformId.Bitbucket, url: defaults.endpoint, }); config = { diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index c6f34b19bd1c19..fa055a6ce78e48 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -1,6 +1,7 @@ import URL from 'url'; import is from '@sindresorhus/is'; import { lt } from 'semver'; +import { PlatformId } from '../../constants'; import { REPOSITORY_ACCESS_FORBIDDEN, REPOSITORY_ARCHIVED, @@ -9,7 +10,6 @@ import { REPOSITORY_EMPTY, REPOSITORY_MIRRORED, } from '../../constants/error-messages'; -import { PLATFORM_TYPE_GITEA } from '../../constants/platforms'; import { logger } from '../../logger'; import { BranchStatus, PrState, VulnerabilityAlert } from '../../types'; import * as git from '../../util/git'; @@ -50,7 +50,7 @@ interface GiteaRepoConfig { } const defaults = { - hostType: PLATFORM_TYPE_GITEA, + hostType: PlatformId.Gitea, endpoint: 'https://gitea.com/api/v1/', version: '0.0.0', }; @@ -287,7 +287,7 @@ const platform: Platform = { // Find options for current host and determine Git endpoint const opts = hostRules.find({ - hostType: PLATFORM_TYPE_GITEA, + hostType: PlatformId.Gitea, url: defaults.endpoint, }); const gitEndpoint = URL.parse(repo.clone_url); diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index bc76286e56fb65..04b4c146d7d37c 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -2,6 +2,7 @@ import URL from 'url'; import is from '@sindresorhus/is'; import delay from 'delay'; import { DateTime } from 'luxon'; +import { PlatformId } from '../../constants'; import { PLATFORM_INTEGRATION_UNAUTHORIZED, REPOSITORY_ACCESS_FORBIDDEN, @@ -15,7 +16,6 @@ import { REPOSITORY_NOT_FOUND, REPOSITORY_RENAMED, } from '../../constants/error-messages'; -import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; import { logger } from '../../logger'; import { BranchStatus, PrState, VulnerabilityAlert } from '../../types'; import { ExternalHostError } from '../../types/errors/external-host-error'; @@ -69,7 +69,7 @@ const githubApi = new githubHttp.GithubHttp(); let config: LocalRepoConfig = {} as any; const defaults = { - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, endpoint: 'https://api.github.com/', }; @@ -188,7 +188,7 @@ export async function initRepo({ githubHttp.setBaseUrl(endpoint); } const opts = hostRules.find({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, url: defaults.endpoint, }); config.isGhe = URL.parse(defaults.endpoint).host !== 'api.github.com'; @@ -665,7 +665,7 @@ export async function getPrList(): Promise { ).body; } catch (err) /* istanbul ignore next */ { logger.debug({ err }, 'getPrList err'); - throw new ExternalHostError(err, PLATFORM_TYPE_GITHUB); + throw new ExternalHostError(err, PlatformId.Github); } config.prList = prList .filter( @@ -1275,7 +1275,7 @@ async function getComments(issueNo: number): Promise { } catch (err) /* istanbul ignore next */ { if (err.statusCode === 404) { logger.debug('404 response when retrieving comments'); - throw new ExternalHostError(err, PLATFORM_TYPE_GITHUB); + throw new ExternalHostError(err, PlatformId.Github); } throw err; } diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 236bc5f8595385..25ba11b2a0a9b2 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -3,6 +3,7 @@ import is from '@sindresorhus/is'; import delay from 'delay'; import pAll from 'p-all'; import { lt } from 'semver'; +import { PlatformId } from '../../constants'; import { CONFIG_GIT_URL_UNAVAILABLE, PLATFORM_AUTHENTICATION_ERROR, @@ -15,7 +16,6 @@ import { REPOSITORY_NOT_FOUND, TEMPORARY_ERROR, } from '../../constants/error-messages'; -import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms'; import { logger } from '../../logger'; import { BranchStatus, PrState, VulnerabilityAlert } from '../../types'; import * as git from '../../util/git'; @@ -66,7 +66,7 @@ let config: { } = {} as any; const defaults = { - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, endpoint: 'https://gitlab.com/api/v4/', version: '0.0.0', }; diff --git a/lib/platform/index.spec.ts b/lib/platform/index.spec.ts index 1a29be4909fd66..08262220769875 100644 --- a/lib/platform/index.spec.ts +++ b/lib/platform/index.spec.ts @@ -1,6 +1,6 @@ import * as httpMock from '../../test/http-mock'; +import { PlatformId } from '../constants'; import { PLATFORM_NOT_FOUND } from '../constants/error-messages'; -import { PLATFORM_TYPE_BITBUCKET } from '../constants/platforms'; import { loadModules } from '../util/modules'; import type { Platform } from './types'; import * as platform from '.'; @@ -51,7 +51,7 @@ describe('platform/index', () => { .basicAuth({ user: 'abc', pass: '123' }) .reply(200, { uuid: 123 }); const config = { - platform: PLATFORM_TYPE_BITBUCKET, + platform: PlatformId.Bitbucket, gitAuthor: 'user@domain.com', username: 'abc', password: '123', @@ -67,7 +67,7 @@ describe('platform/index', () => { username: 'abc', }, ], - platform: PLATFORM_TYPE_BITBUCKET, + platform: PlatformId.Bitbucket, }); }); }); diff --git a/lib/util/host-rules.spec.ts b/lib/util/host-rules.spec.ts index 7bc63e902dde7d..04c965b43d5f3e 100644 --- a/lib/util/host-rules.spec.ts +++ b/lib/util/host-rules.spec.ts @@ -1,7 +1,4 @@ -import { - PLATFORM_TYPE_AZURE, - PLATFORM_TYPE_GITHUB, -} from '../constants/platforms'; +import { PlatformId } from '../constants'; import * as datasourceNuget from '../datasource/nuget'; import { add, clear, find, findAll, hosts } from './host-rules'; @@ -13,7 +10,7 @@ describe('util/host-rules', () => { it('throws if both domainName and hostName', () => { expect(() => add({ - hostType: PLATFORM_TYPE_AZURE, + hostType: PlatformId.Azure, domainName: 'github.com', hostName: 'api.github.com', } as any) @@ -22,7 +19,7 @@ describe('util/host-rules', () => { it('throws if both domainName and baseUrl', () => { expect(() => add({ - hostType: PLATFORM_TYPE_AZURE, + hostType: PlatformId.Azure, domainName: 'github.com', matchHost: 'https://api.github.com', } as any) @@ -31,7 +28,7 @@ describe('util/host-rules', () => { it('throws if both hostName and baseUrl', () => { expect(() => add({ - hostType: PLATFORM_TYPE_AZURE, + hostType: PlatformId.Azure, hostName: 'api.github.com', matchHost: 'https://api.github.com', } as any) @@ -113,25 +110,25 @@ describe('util/host-rules', () => { it('matches on specific path', () => { // Initialized platform holst rule add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'https://api.github.com', token: 'abc', }); // Initialized generic host rule for github platform add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'https://api.github.com', token: 'abc', }); // specific host rule for using other token in different org add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'https://api.github.com/repos/org-b/', token: 'def', }); expect( find({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, url: 'https://api.github.com/repos/org-b/someRepo/tags?per_page=100', }).token ).toEqual('def'); @@ -144,7 +141,7 @@ describe('util/host-rules', () => { }); expect( find({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, url: 'https://api.github.com/repos/org-b/someRepo/tags?per_page=100', }).token ).toEqual('abc'); @@ -158,7 +155,7 @@ describe('util/host-rules', () => { it('matches if hostType is configured and host rule is filtered with datasource', () => { add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'https://api.github.com', token: 'abc', }); diff --git a/lib/util/http/auth.spec.ts b/lib/util/http/auth.spec.ts index 8737d084b25933..72da33c84b21fc 100644 --- a/lib/util/http/auth.spec.ts +++ b/lib/util/http/auth.spec.ts @@ -1,10 +1,6 @@ import { NormalizedOptions } from 'got'; import { partial } from '../../../test/util'; -import { - PLATFORM_TYPE_GITEA, - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, -} from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import { applyAuthorization, removeAuthorization } from './auth'; import { GotOptions } from './types'; @@ -33,7 +29,7 @@ describe('util/http/auth', () => { it('gitea password', () => { const opts: GotOptions = { headers: {}, - hostType: PLATFORM_TYPE_GITEA, + hostType: PlatformId.Gitea, password: 'XXXX', }; @@ -54,7 +50,7 @@ describe('util/http/auth', () => { const opts: GotOptions = { headers: {}, token: 'XXXX', - hostType: PLATFORM_TYPE_GITEA, + hostType: PlatformId.Gitea, }; applyAuthorization(opts); @@ -74,7 +70,7 @@ describe('util/http/auth', () => { const opts: GotOptions = { headers: {}, token: 'XXX', - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, }; applyAuthorization(opts); @@ -112,7 +108,7 @@ describe('util/http/auth', () => { headers: {}, // Personal Access Token is exactly 20 characters long token: '0123456789012345test', - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, }; applyAuthorization(opts); @@ -133,7 +129,7 @@ describe('util/http/auth', () => { headers: {}, token: 'a40bdd925a0c0b9c4cdd19d101c0df3b2bcd063ab7ad6706f03bcffcec01test', - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, }; applyAuthorization(opts); diff --git a/lib/util/http/auth.ts b/lib/util/http/auth.ts index a8dfc3f42f4448..59dba806f71564 100644 --- a/lib/util/http/auth.ts +++ b/lib/util/http/auth.ts @@ -3,8 +3,8 @@ import type { NormalizedOptions } from 'got'; import { GITHUB_API_USING_HOST_TYPES, GITLAB_API_USING_HOST_TYPES, - PLATFORM_TYPE_GITEA, -} from '../../constants/platforms'; + PlatformId, +} from '../../constants'; import type { GotOptions } from './types'; export function applyAuthorization(inOptions: GotOptions): GotOptions { @@ -15,7 +15,7 @@ export function applyAuthorization(inOptions: GotOptions): GotOptions { } if (options.token) { - if (options.hostType === PLATFORM_TYPE_GITEA) { + if (options.hostType === PlatformId.Gitea) { options.headers.authorization = `token ${options.token}`; } else if (GITHUB_API_USING_HOST_TYPES.includes(options.hostType)) { options.headers.authorization = `token ${options.token}`; diff --git a/lib/util/http/bitbucket-server.spec.ts b/lib/util/http/bitbucket-server.spec.ts index 65cf77d7d607ae..a1608178e7e833 100644 --- a/lib/util/http/bitbucket-server.spec.ts +++ b/lib/util/http/bitbucket-server.spec.ts @@ -1,5 +1,5 @@ import * as httpMock from '../../../test/http-mock'; -import { PLATFORM_TYPE_BITBUCKET_SERVER } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import * as hostRules from '../host-rules'; import { BitbucketServerHttp, setBaseUrl } from './bitbucket-server'; @@ -16,7 +16,7 @@ describe('util/http/bitbucket-server', () => { // clean up hostRules hostRules.clear(); hostRules.add({ - hostType: PLATFORM_TYPE_BITBUCKET_SERVER, + hostType: PlatformId.BitbucketServer, matchHost: baseUrl, token: 'token', }); diff --git a/lib/util/http/bitbucket-server.ts b/lib/util/http/bitbucket-server.ts index dd96385b99d0b1..6d2d91aa3e96a7 100644 --- a/lib/util/http/bitbucket-server.ts +++ b/lib/util/http/bitbucket-server.ts @@ -1,4 +1,4 @@ -import { PLATFORM_TYPE_BITBUCKET_SERVER } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import { resolveBaseUrl } from '../url'; import { Http, HttpOptions, HttpResponse, InternalHttpOptions } from '.'; @@ -9,7 +9,7 @@ export const setBaseUrl = (url: string): void => { export class BitbucketServerHttp extends Http { constructor(options?: HttpOptions) { - super(PLATFORM_TYPE_BITBUCKET_SERVER, options); + super(PlatformId.BitbucketServer, options); } protected override request( diff --git a/lib/util/http/bitbucket.spec.ts b/lib/util/http/bitbucket.spec.ts index ace4b8a50c755a..ae38ead34ebdda 100644 --- a/lib/util/http/bitbucket.spec.ts +++ b/lib/util/http/bitbucket.spec.ts @@ -1,5 +1,5 @@ import * as httpMock from '../../../test/http-mock'; -import { PLATFORM_TYPE_BITBUCKET } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import * as hostRules from '../host-rules'; import { BitbucketHttp, setBaseUrl } from './bitbucket'; @@ -16,7 +16,7 @@ describe('util/http/bitbucket', () => { // clean up hostRules hostRules.clear(); hostRules.add({ - hostType: PLATFORM_TYPE_BITBUCKET, + hostType: PlatformId.Bitbucket, matchHost: baseUrl, token: 'token', }); diff --git a/lib/util/http/bitbucket.ts b/lib/util/http/bitbucket.ts index 10f56e4a25664c..1eaaab9e531d3e 100644 --- a/lib/util/http/bitbucket.ts +++ b/lib/util/http/bitbucket.ts @@ -1,4 +1,4 @@ -import { PLATFORM_TYPE_BITBUCKET } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import { Http, HttpOptions, HttpResponse, InternalHttpOptions } from '.'; let baseUrl = 'https://api.bitbucket.org/'; @@ -9,7 +9,7 @@ export const setBaseUrl = (url: string): void => { export class BitbucketHttp extends Http { constructor(options?: HttpOptions) { - super(PLATFORM_TYPE_BITBUCKET, options); + super(PlatformId.Bitbucket, options); } protected override request( diff --git a/lib/util/http/gitea.ts b/lib/util/http/gitea.ts index 5410284e3852eb..ff53983fc856d7 100644 --- a/lib/util/http/gitea.ts +++ b/lib/util/http/gitea.ts @@ -1,4 +1,4 @@ -import { PLATFORM_TYPE_GITEA } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import { resolveBaseUrl } from '../url'; import { Http, HttpOptions, HttpResponse, InternalHttpOptions } from '.'; @@ -30,7 +30,7 @@ function resolveUrl(path: string, base: string): URL { export class GiteaHttp extends Http { constructor(options?: HttpOptions) { - super(PLATFORM_TYPE_GITEA, options); + super(PlatformId.Gitea, options); } protected override async request( diff --git a/lib/util/http/github.ts b/lib/util/http/github.ts index 478c72f54f1233..e555fed6310891 100644 --- a/lib/util/http/github.ts +++ b/lib/util/http/github.ts @@ -1,13 +1,13 @@ import is from '@sindresorhus/is'; import pAll from 'p-all'; import parseLinkHeader from 'parse-link-header'; +import { PlatformId } from '../../constants'; import { PLATFORM_BAD_CREDENTIALS, PLATFORM_INTEGRATION_UNAUTHORIZED, PLATFORM_RATE_LIMIT_EXCEEDED, REPOSITORY_CHANGED, } from '../../constants/error-messages'; -import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; import { logger } from '../../logger'; import { ExternalHostError } from '../../types/errors/external-host-error'; import { maskToken } from '../mask'; @@ -55,15 +55,15 @@ function handleGotError( err.code === 'ECONNRESET') ) { logger.debug({ err }, 'GitHub failure: RequestError'); - throw new ExternalHostError(err, PLATFORM_TYPE_GITHUB); + throw new ExternalHostError(err, PlatformId.Github); } if (err.name === 'ParseError') { logger.debug({ err }, ''); - throw new ExternalHostError(err, PLATFORM_TYPE_GITHUB); + throw new ExternalHostError(err, PlatformId.Github); } if (err.statusCode >= 500 && err.statusCode < 600) { logger.debug({ err }, 'GitHub failure: 5xx'); - throw new ExternalHostError(err, PLATFORM_TYPE_GITHUB); + throw new ExternalHostError(err, PlatformId.Github); } if ( err.statusCode === 403 && @@ -100,7 +100,7 @@ function handleGotError( 'GitHub failure: Bad credentials' ); if (rateLimit === '60') { - throw new ExternalHostError(err, PLATFORM_TYPE_GITHUB); + throw new ExternalHostError(err, PlatformId.Github); } throw new Error(PLATFORM_BAD_CREDENTIALS); } @@ -120,7 +120,7 @@ function handleGotError( throw err; } logger.debug({ err }, '422 Error thrown from GitHub'); - throw new ExternalHostError(err, PLATFORM_TYPE_GITHUB); + throw new ExternalHostError(err, PlatformId.Github); } if ( err.statusCode === 410 && @@ -159,7 +159,7 @@ function constructAcceptString(input?: any): string { export class GithubHttp extends Http { constructor( - hostType: string = PLATFORM_TYPE_GITHUB, + hostType: string = PlatformId.Github, options?: GithubHttpOptions ) { super(hostType, options); diff --git a/lib/util/http/gitlab.spec.ts b/lib/util/http/gitlab.spec.ts index 103640c7b078b2..729ac29c28dacc 100644 --- a/lib/util/http/gitlab.spec.ts +++ b/lib/util/http/gitlab.spec.ts @@ -1,12 +1,12 @@ import * as httpMock from '../../../test/http-mock'; +import { PlatformId } from '../../constants'; import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages'; -import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms'; import { GitlabReleasesDatasource } from '../../datasource/gitlab-releases'; import * as hostRules from '../host-rules'; import { GitlabHttp, setBaseUrl } from './gitlab'; hostRules.add({ - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, token: '123test', }); @@ -22,7 +22,7 @@ describe('util/http/gitlab', () => { delete process.env.GITLAB_IGNORE_REPO_URL; hostRules.add({ - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, token: 'abc123', }); }); @@ -79,7 +79,7 @@ describe('util/http/gitlab', () => { it('supports different datasources', async () => { const gitlabApiDatasource = new GitlabHttp(GitlabReleasesDatasource.id); - hostRules.add({ hostType: PLATFORM_TYPE_GITLAB, token: 'abc' }); + hostRules.add({ hostType: PlatformId.Gitlab, token: 'abc' }); hostRules.add({ hostType: GitlabReleasesDatasource.id, token: 'def', diff --git a/lib/util/http/gitlab.ts b/lib/util/http/gitlab.ts index 18eacdd2240f81..7c6589ce98aa50 100644 --- a/lib/util/http/gitlab.ts +++ b/lib/util/http/gitlab.ts @@ -1,5 +1,5 @@ import parseLinkHeader from 'parse-link-header'; -import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import { logger } from '../../logger'; import { ExternalHostError } from '../../types/errors/external-host-error'; import { parseUrl } from '../url'; @@ -20,10 +20,7 @@ export interface GitlabHttpOptions extends InternalHttpOptions { } export class GitlabHttp extends Http { - constructor( - type: string = PLATFORM_TYPE_GITLAB, - options?: GitlabHttpOptions - ) { + constructor(type: string = PlatformId.Gitlab, options?: GitlabHttpOptions) { super(type, options); } @@ -73,7 +70,7 @@ export class GitlabHttp extends Http { err.statusCode === 429 || (err.statusCode >= 500 && err.statusCode < 600) ) { - throw new ExternalHostError(err, PLATFORM_TYPE_GITLAB); + throw new ExternalHostError(err, PlatformId.Gitlab); } const platformFailureCodes = [ 'EAI_AGAIN', @@ -82,10 +79,10 @@ export class GitlabHttp extends Http { 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', ]; if (platformFailureCodes.includes(err.code)) { - throw new ExternalHostError(err, PLATFORM_TYPE_GITLAB); + throw new ExternalHostError(err, PlatformId.Gitlab); } if (err.name === 'ParseError') { - throw new ExternalHostError(err, PLATFORM_TYPE_GITLAB); + throw new ExternalHostError(err, PlatformId.Gitlab); } throw err; } diff --git a/lib/util/http/host-rules.spec.ts b/lib/util/http/host-rules.spec.ts index b4c8ebfd944c50..00e04a386ee76c 100644 --- a/lib/util/http/host-rules.spec.ts +++ b/lib/util/http/host-rules.spec.ts @@ -1,8 +1,4 @@ -import { - PLATFORM_TYPE_GITEA, - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, -} from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import { bootstrap } from '../../proxy'; import * as hostRules from '../host-rules'; import { applyHostRules } from './host-rules'; @@ -13,7 +9,7 @@ jest.mock('global-agent'); describe('util/http/host-rules', () => { const options = { - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, }; beforeEach(() => { // reset module @@ -24,11 +20,11 @@ describe('util/http/host-rules', () => { // clean up hostRules hostRules.clear(); hostRules.add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, token: 'token', }); hostRules.add({ - hostType: PLATFORM_TYPE_GITEA, + hostType: PlatformId.Gitea, password: 'password', }); @@ -39,7 +35,7 @@ describe('util/http/host-rules', () => { }); hostRules.add({ - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, token: 'abc', }); @@ -67,7 +63,7 @@ describe('util/http/host-rules', () => { }); it('adds auth', () => { - expect(applyHostRules(url, { hostType: PLATFORM_TYPE_GITEA })) + expect(applyHostRules(url, { hostType: PlatformId.Gitea })) .toMatchInlineSnapshot(` Object { "hostType": "gitea", diff --git a/lib/util/http/host-rules.ts b/lib/util/http/host-rules.ts index 86537e4ea12c17..4d86c913d65219 100644 --- a/lib/util/http/host-rules.ts +++ b/lib/util/http/host-rules.ts @@ -1,9 +1,8 @@ import { GITHUB_API_USING_HOST_TYPES, GITLAB_API_USING_HOST_TYPES, - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, -} from '../../constants/platforms'; + PlatformId, +} from '../../constants'; import { logger } from '../../logger'; import { hasProxy } from '../../proxy'; import type { HostRule } from '../../types'; @@ -22,11 +21,11 @@ function findMatchingRules(options: GotOptions, url: string): HostRule { // Fallback to `github` hostType if ( GITHUB_API_USING_HOST_TYPES.includes(hostType) && - hostType !== PLATFORM_TYPE_GITHUB + hostType !== PlatformId.Github ) { res = { ...hostRules.find({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, url, }), ...res, @@ -36,11 +35,11 @@ function findMatchingRules(options: GotOptions, url: string): HostRule { // Fallback to `gitlab` hostType if ( GITLAB_API_USING_HOST_TYPES.includes(hostType) && - hostType !== PLATFORM_TYPE_GITLAB + hostType !== PlatformId.Gitlab ) { res = { ...hostRules.find({ - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, url, }), ...res, diff --git a/lib/workers/global/autodiscover.spec.ts b/lib/workers/global/autodiscover.spec.ts index b5cdaaa7700f5b..076d179cc3fa9c 100644 --- a/lib/workers/global/autodiscover.spec.ts +++ b/lib/workers/global/autodiscover.spec.ts @@ -1,5 +1,5 @@ import type { RenovateConfig } from '../../config/types'; -import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import * as platform from '../../platform'; import * as _ghApi from '../../platform/github'; import * as _hostRules from '../../util/host-rules'; @@ -18,7 +18,7 @@ describe('workers/global/autodiscover', () => { jest.resetAllMocks(); config = {}; await platform.initPlatform({ - platform: PLATFORM_TYPE_GITHUB, + platform: PlatformId.Github, token: '123test', endpoint: 'endpoint', }); @@ -28,7 +28,7 @@ describe('workers/global/autodiscover', () => { }); it('autodiscovers github but empty', async () => { config.autodiscover = true; - config.platform = PLATFORM_TYPE_GITHUB; + config.platform = PlatformId.Github; hostRules.find = jest.fn(() => ({ token: 'abc', })); @@ -38,7 +38,7 @@ describe('workers/global/autodiscover', () => { }); it('autodiscovers github repos', async () => { config.autodiscover = true; - config.platform = PLATFORM_TYPE_GITHUB; + config.platform = PlatformId.Github; hostRules.find = jest.fn(() => ({ token: 'abc', })); @@ -49,7 +49,7 @@ describe('workers/global/autodiscover', () => { it('filters autodiscovered github repos', async () => { config.autodiscover = true; config.autodiscoverFilter = 'project/re*'; - config.platform = PLATFORM_TYPE_GITHUB; + config.platform = PlatformId.Github; hostRules.find = jest.fn(() => ({ token: 'abc', })); diff --git a/lib/workers/global/config/parse/env.spec.ts b/lib/workers/global/config/parse/env.spec.ts index 528179ea0a99ea..714d2732eb6d0b 100644 --- a/lib/workers/global/config/parse/env.spec.ts +++ b/lib/workers/global/config/parse/env.spec.ts @@ -1,8 +1,5 @@ import type { RenovateOptions } from '../../../../config/types'; -import { - PLATFORM_TYPE_BITBUCKET, - PLATFORM_TYPE_GITLAB, -} from '../../../../constants/platforms'; +import { PlatformId } from '../../../../constants'; import * as env from './env'; describe('workers/global/config/parse/env', () => { @@ -74,7 +71,7 @@ describe('workers/global/config/parse/env', () => { }); it('supports GitLab token', () => { const envParam: NodeJS.ProcessEnv = { - RENOVATE_PLATFORM: PLATFORM_TYPE_GITLAB, + RENOVATE_PLATFORM: PlatformId.Gitlab, RENOVATE_TOKEN: 'a gitlab.com token', }; // FIXME: explicit assert condition @@ -82,7 +79,7 @@ describe('workers/global/config/parse/env', () => { }); it('supports GitLab custom endpoint', () => { const envParam: NodeJS.ProcessEnv = { - RENOVATE_PLATFORM: PLATFORM_TYPE_GITLAB, + RENOVATE_PLATFORM: PlatformId.Gitlab, RENOVATE_TOKEN: 'a gitlab token', RENOVATE_ENDPOINT: 'a gitlab endpoint', }; @@ -158,7 +155,7 @@ describe('workers/global/config/parse/env', () => { }); it('supports Bitbucket token', () => { const envParam: NodeJS.ProcessEnv = { - RENOVATE_PLATFORM: PLATFORM_TYPE_BITBUCKET, + RENOVATE_PLATFORM: PlatformId.Bitbucket, RENOVATE_ENDPOINT: 'a bitbucket endpoint', RENOVATE_USERNAME: 'some-username', RENOVATE_PASSWORD: 'app-password', @@ -168,7 +165,7 @@ describe('workers/global/config/parse/env', () => { }); it('supports Bitbucket username/password', () => { const envParam: NodeJS.ProcessEnv = { - RENOVATE_PLATFORM: PLATFORM_TYPE_BITBUCKET, + RENOVATE_PLATFORM: PlatformId.Bitbucket, RENOVATE_ENDPOINT: 'a bitbucket endpoint', RENOVATE_USERNAME: 'some-username', RENOVATE_PASSWORD: 'app-password', diff --git a/lib/workers/global/config/parse/env.ts b/lib/workers/global/config/parse/env.ts index 10dc8abcfb40e9..a6e91c219ff710 100644 --- a/lib/workers/global/config/parse/env.ts +++ b/lib/workers/global/config/parse/env.ts @@ -2,7 +2,7 @@ import is from '@sindresorhus/is'; import { getOptions } from '../../../../config/options'; import type { AllConfig, RenovateOptions } from '../../../../config/types'; -import { PLATFORM_TYPE_GITHUB } from '../../../../constants/platforms'; +import { PlatformId } from '../../../../constants'; import { getDatasourceList } from '../../../../datasource'; import { logger } from '../../../../logger'; import type { HostRule } from '../../../../types'; @@ -82,7 +82,7 @@ export function getConfig(env: NodeJS.ProcessEnv): AllConfig { if (env.GITHUB_COM_TOKEN) { logger.debug(`Converting GITHUB_COM_TOKEN into a global host rule`); config.hostRules.push({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'github.com', token: env.GITHUB_COM_TOKEN, }); diff --git a/lib/workers/global/index.spec.ts b/lib/workers/global/index.spec.ts index 13d93bcba47971..92f46e7e91ca4f 100644 --- a/lib/workers/global/index.spec.ts +++ b/lib/workers/global/index.spec.ts @@ -1,10 +1,7 @@ import { expect } from '@jest/globals'; import { ERROR, WARN } from 'bunyan'; import { fs, logger } from '../../../test/util'; -import { - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, -} from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import * as datasourceDocker from '../../datasource/docker'; import * as _platform from '../../platform'; import * as _repositoryWorker from '../repository'; @@ -114,7 +111,7 @@ describe('workers/global/index', () => { it('github', async () => { configParser.parseConfigs.mockResolvedValueOnce({ repositories: ['a'], - platform: PLATFORM_TYPE_GITHUB, + platform: PlatformId.Github, endpoint: 'https://github.com/', }); await globalWorker.start(); @@ -124,7 +121,7 @@ describe('workers/global/index', () => { it('gitlab', async () => { configParser.parseConfigs.mockResolvedValueOnce({ repositories: [{ repository: 'a' }], - platform: PLATFORM_TYPE_GITLAB, + platform: PlatformId.Gitlab, endpoint: 'https://my.gitlab.com/', }); await globalWorker.start(); @@ -137,7 +134,7 @@ describe('workers/global/index', () => { it('successfully write file', async () => { configParser.parseConfigs.mockResolvedValueOnce({ repositories: ['myOrg/myRepo'], - platform: PLATFORM_TYPE_GITHUB, + platform: PlatformId.Github, endpoint: 'https://github.com/', writeDiscoveredRepos: '/tmp/renovate-output.json', }); diff --git a/lib/workers/pr/changelog/github.spec.ts b/lib/workers/pr/changelog/github.spec.ts index 8a260df07a9327..95bfe0d6b85557 100644 --- a/lib/workers/pr/changelog/github.spec.ts +++ b/lib/workers/pr/changelog/github.spec.ts @@ -1,5 +1,5 @@ import * as httpMock from '../../../../test/http-mock'; -import { PLATFORM_TYPE_GITHUB } from '../../../constants/platforms'; +import { PlatformId } from '../../../constants'; import * as hostRules from '../../../util/host-rules'; import * as semverVersioning from '../../../versioning/semver'; import type { BranchUpgradeConfig } from '../../types'; @@ -39,7 +39,7 @@ describe('workers/pr/changelog/github', () => { beforeEach(() => { hostRules.clear(); hostRules.add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'https://api.github.com/', token: 'abc', }); @@ -167,7 +167,7 @@ describe('workers/pr/changelog/github', () => { it('supports github enterprise and github.com changelog', async () => { hostRules.add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, token: 'super_secret', matchHost: 'https://github-enterprise.example.com/', }); @@ -182,7 +182,7 @@ describe('workers/pr/changelog/github', () => { it('supports github enterprise and github enterprise changelog', async () => { hostRules.add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'https://github-enterprise.example.com/', token: 'abc', }); diff --git a/lib/workers/pr/changelog/gitlab.spec.ts b/lib/workers/pr/changelog/gitlab.spec.ts index 1235d29d958f5e..7894bc600812a7 100644 --- a/lib/workers/pr/changelog/gitlab.spec.ts +++ b/lib/workers/pr/changelog/gitlab.spec.ts @@ -1,5 +1,5 @@ import * as httpMock from '../../../../test/http-mock'; -import { PLATFORM_TYPE_GITLAB } from '../../../constants/platforms'; +import { PlatformId } from '../../../constants'; import * as hostRules from '../../../util/host-rules'; import * as semverVersioning from '../../../versioning/semver'; import type { BranchUpgradeConfig } from '../../types'; @@ -40,7 +40,7 @@ describe('workers/pr/changelog/gitlab', () => { beforeEach(() => { hostRules.clear(); hostRules.add({ - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, matchHost, token: 'abc', }); @@ -181,7 +181,7 @@ describe('workers/pr/changelog/gitlab', () => { }); it('supports gitlab enterprise and gitlab enterprise changelog', async () => { hostRules.add({ - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, matchHost: 'https://gitlab-enterprise.example.com/', token: 'abc', }); @@ -198,7 +198,7 @@ describe('workers/pr/changelog/gitlab', () => { it('supports self-hosted gitlab changelog', async () => { httpMock.scope('https://git.test.com').persist().get(/.*/).reply(200, []); hostRules.add({ - hostType: PLATFORM_TYPE_GITLAB, + hostType: PlatformId.Gitlab, matchHost: 'https://git.test.com/', token: 'abc', }); @@ -207,7 +207,7 @@ describe('workers/pr/changelog/gitlab', () => { expect( await getChangeLogJSON({ ...upgrade, - platform: PLATFORM_TYPE_GITLAB, + platform: PlatformId.Gitlab, sourceUrl: 'https://git.test.com/meno/dropzone/', endpoint: 'https://git.test.com/api/v4/', }) diff --git a/lib/workers/pr/changelog/index.spec.ts b/lib/workers/pr/changelog/index.spec.ts index ae462fceeca812..051a141def702d 100644 --- a/lib/workers/pr/changelog/index.spec.ts +++ b/lib/workers/pr/changelog/index.spec.ts @@ -1,6 +1,6 @@ import * as httpMock from '../../../../test/http-mock'; import { partial } from '../../../../test/util'; -import { PLATFORM_TYPE_GITHUB } from '../../../constants/platforms'; +import { PlatformId } from '../../../constants'; import * as hostRules from '../../../util/host-rules'; import * as semverVersioning from '../../../versioning/semver'; import type { BranchConfig } from '../../types'; @@ -36,7 +36,7 @@ describe('workers/pr/changelog/index', () => { beforeEach(() => { hostRules.clear(); hostRules.add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'https://api.github.com/', token: 'abc', }); @@ -193,7 +193,7 @@ describe('workers/pr/changelog/index', () => { it('supports github enterprise and github.com changelog', async () => { httpMock.scope(githubApiHost).persist().get(/.*/).reply(200, []); hostRules.add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, token: 'super_secret', matchHost: 'https://github-enterprise.example.com/', }); @@ -213,7 +213,7 @@ describe('workers/pr/changelog/index', () => { .get(/.*/) .reply(200, []); hostRules.add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'https://github-enterprise.example.com/', token: 'abc', }); @@ -236,7 +236,7 @@ describe('workers/pr/changelog/index', () => { .get(/.*/) .reply(200, []); hostRules.add({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, matchHost: 'https://github-enterprise.example.com/', token: 'abc', }); diff --git a/lib/workers/pr/changelog/source-github.ts b/lib/workers/pr/changelog/source-github.ts index 3dee765d2e0825..720ef8c4d8b0c1 100644 --- a/lib/workers/pr/changelog/source-github.ts +++ b/lib/workers/pr/changelog/source-github.ts @@ -1,5 +1,5 @@ import URL from 'url'; -import { PLATFORM_TYPE_GITHUB } from '../../../constants/platforms'; +import { PlatformId } from '../../../constants'; import type { Release } from '../../../datasource/types'; import { logger } from '../../../logger'; import * as memCache from '../../../util/cache/memory'; @@ -47,7 +47,7 @@ export async function getChangeLogJSON({ ? 'https://api.github.com/' : sourceUrl; const config = hostRules.find({ - hostType: PLATFORM_TYPE_GITHUB, + hostType: PlatformId.Github, url, }); // istanbul ignore if diff --git a/lib/workers/pr/index.spec.ts b/lib/workers/pr/index.spec.ts index d82283479371cd..63e7ae7cab6f42 100644 --- a/lib/workers/pr/index.spec.ts +++ b/lib/workers/pr/index.spec.ts @@ -1,5 +1,5 @@ import { getConfig, git, mocked, partial, platform } from '../../../test/util'; -import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import type { Pr } from '../../platform/types'; import { BranchStatus } from '../../types'; import * as _limits from '../global/limits'; @@ -621,7 +621,7 @@ describe('workers/pr/index', () => { git.getBranchLastCommitTime.mockResolvedValueOnce(new Date()); config.prCreation = 'not-pending'; config.artifactErrors = [{}]; - config.platform = PLATFORM_TYPE_GITLAB; + config.platform = PlatformId.Gitlab; const { pr } = await prWorker.ensurePr(config); expect(pr).toMatchObject({ displayNumber: 'New Pull Request' }); }); diff --git a/lib/workers/repository/dependency-dashboard.spec.ts b/lib/workers/repository/dependency-dashboard.spec.ts index d2c34f78cfd011..ef16629b7a969c 100644 --- a/lib/workers/repository/dependency-dashboard.spec.ts +++ b/lib/workers/repository/dependency-dashboard.spec.ts @@ -8,7 +8,7 @@ import { platform, } from '../../../test/util'; import { setGlobalConfig } from '../../config/global'; -import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; +import { PlatformId } from '../../constants'; import type { Platform } from '../../platform'; import { BranchConfig, BranchResult, BranchUpgradeConfig } from '../types'; import * as dependencyDashboard from './dependency-dashboard'; @@ -19,7 +19,7 @@ let config: RenovateConfig; beforeEach(() => { jest.clearAllMocks(); config = getConfig(); - config.platform = PLATFORM_TYPE_GITHUB; + config.platform = PlatformId.Github; config.errors = []; config.warnings = []; }); diff --git a/lib/workers/repository/finalise/prune.spec.ts b/lib/workers/repository/finalise/prune.spec.ts index 05868f977131b0..6e2c0c7418e180 100644 --- a/lib/workers/repository/finalise/prune.spec.ts +++ b/lib/workers/repository/finalise/prune.spec.ts @@ -5,7 +5,7 @@ import { platform, } from '../../../../test/util'; import { setGlobalConfig } from '../../../config/global'; -import { PLATFORM_TYPE_GITHUB } from '../../../constants/platforms'; +import { PlatformId } from '../../../constants'; import * as cleanup from './prune'; jest.mock('../../../util/git'); @@ -14,7 +14,7 @@ let config: RenovateConfig; beforeEach(() => { jest.resetAllMocks(); config = getConfig(); - config.platform = PLATFORM_TYPE_GITHUB; + config.platform = PlatformId.Github; config.errors = []; config.warnings = []; });