From aff618fa8e8d89168d80feb8198ba9fd971390de Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Thu, 6 Feb 2020 13:44:53 +0000 Subject: [PATCH] feat: dynamic platform list retrieval (#5394) --- lib/config/definitions.ts | 17 +++-------------- lib/platform/index.ts | 15 +++++++++------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/config/definitions.ts b/lib/config/definitions.ts index 313f3eaab3..55c368b5bf 100644 --- a/lib/config/definitions.ts +++ b/lib/config/definitions.ts @@ -17,13 +17,8 @@ import { VERSION_SCHEME_SWIFT, } from '../constants/version-schemes'; import { getVersionSchemeList } from '../versioning'; -import { - PLATFORM_TYPE_AZURE, - PLATFORM_TYPE_BITBUCKET, - PLATFORM_TYPE_BITBUCKET_SERVER, - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, -} from '../constants/platforms'; +import { PLATFORM_TYPE_GITHUB } from '../constants/platforms'; +import { platformList } from '../platform'; export interface RenovateOptionBase { admin?: boolean; @@ -463,13 +458,7 @@ const options: RenovateOptions[] = [ name: 'platform', description: 'Platform type of repository', type: 'string', - allowedValues: [ - PLATFORM_TYPE_AZURE, - PLATFORM_TYPE_BITBUCKET, - PLATFORM_TYPE_BITBUCKET_SERVER, - PLATFORM_TYPE_GITHUB, - PLATFORM_TYPE_GITLAB, - ], + allowedValues: platformList, default: PLATFORM_TYPE_GITHUB, admin: true, }, diff --git a/lib/platform/index.ts b/lib/platform/index.ts index c9d0715eac..f13da5e1ba 100644 --- a/lib/platform/index.ts +++ b/lib/platform/index.ts @@ -1,17 +1,20 @@ +import fs from 'fs'; import URL from 'url'; import addrs from 'email-addresses'; import * as hostRules from '../util/host-rules'; import { logger } from '../logger'; import { Platform } from './common'; import { RenovateConfig } from '../config/common'; -import { getOptions } from '../config/definitions'; import { PLATFORM_NOT_FOUND } from '../constants/error-messages'; export * from './common'; -const supportedPlatforms = getOptions().find( - option => option.name === 'platform' -).allowedValues; +export const platformList = fs + .readdirSync(__dirname, { withFileTypes: true }) + .filter(dirent => dirent.isDirectory()) + .map(dirent => dirent.name) + .filter(name => name !== 'git' && name !== 'utils') // TODO: should be cleaner + .sort(); let _platform: Platform; @@ -28,9 +31,9 @@ const handler: ProxyHandler<Platform> = { export const platform = new Proxy<Platform>({} as any, handler); export async function setPlatformApi(name: string): Promise<void> { - if (!supportedPlatforms.includes(name)) + if (!platformList.includes(name)) throw new Error( - `Init: Platform "${name}" not found. Must be one of: ${supportedPlatforms.join( + `Init: Platform "${name}" not found. Must be one of: ${platformList.join( ', ' )}` ); -- GitLab