From ff0f38c3399f48731805608c237ed5f8e03aa092 Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Mon, 29 Apr 2024 20:58:01 +0545 Subject: [PATCH 01/10] autodiscoverRepoSort & autodiscoverRepoOrder --- docs/usage/self-hosted-configuration.md | 37 ++++++++++++++++++++++++ docs/usage/self-hosted-experimental.md | 37 ------------------------ lib/config/global.ts | 2 ++ lib/config/types.ts | 2 ++ lib/modules/platform/gitea/index.spec.ts | 12 ++++---- lib/modules/platform/gitea/index.ts | 11 ++++--- lib/modules/platform/gitea/readme.md | 2 +- 7 files changed, 56 insertions(+), 47 deletions(-) diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 2c1af6afecbad4..f229191d63e451 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -233,6 +233,43 @@ This feature is useful for users who want Renovate to only work on repositories The `autodiscoverProjects` config option takes an array of minimatch-compatible globs or RE2-compatible regex strings. For more details on this syntax see Renovate's [string pattern matching documentation](./string-pattern-matching.md). +## autodiscoverRepoOrder + + +!!! note + For the Forgejo and Gitea platform only. + +The order method for autodiscover server side repository search. + +> If multiple `autodiscoverTopics` are used resulting order will be per topic not global. + +Allowed values: + +- `asc` +- `desc` + +Default value: `asc`. + +## autodiscoverRepoSort + + +!!! note + For the Forgejo and Gitea platform only. + +The sort method for autodiscover server side repository search. + +> If multiple `autodiscoverTopics` are used resulting order will be per topic not global. + +Allowed values: + +- `alpha` +- `created` +- `updated` +- `size` +- `id` + +Default value: `alpha`. + ## autodiscoverTopics Some platforms allow you to add tags, or topics, to repositories and retrieve repository lists by specifying those diff --git a/docs/usage/self-hosted-experimental.md b/docs/usage/self-hosted-experimental.md index fcf3c95a94e57e..fc9c648894249c 100644 --- a/docs/usage/self-hosted-experimental.md +++ b/docs/usage/self-hosted-experimental.md @@ -36,43 +36,6 @@ If set to any value, Renovate will always paginate requests to GitHub fully, ins If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests. -## `RENOVATE_X_AUTODISCOVER_REPO_ORDER` - - -!!! note - For the Forgejo and Gitea platform only. - -The order method for autodiscover server side repository search. - -> If multiple `autodiscoverTopics` are used resulting order will be per topic not global. - -Allowed values: - -- `asc` -- `desc` - -Default value: `asc`. - -## `RENOVATE_X_AUTODISCOVER_REPO_SORT` - - -!!! note - For the Forgejo and Gitea platform only. - -The sort method for autodiscover server side repository search. - -> If multiple `autodiscoverTopics` are used resulting order will be per topic not global. - -Allowed values: - -- `alpha` -- `created` -- `updated` -- `size` -- `id` - -Default value: `alpha`. - ## `RENOVATE_X_DELETE_CONFIG_FILE` If `true` Renovate tries to delete the self-hosted config file after reading it. diff --git a/lib/config/global.ts b/lib/config/global.ts index 21b2b56cc25f8d..b9fe34ed653d4c 100644 --- a/lib/config/global.ts +++ b/lib/config/global.ts @@ -33,6 +33,8 @@ export class GlobalConfig { 'platform', 'endpoint', 'httpCacheTtlDays', + 'autodiscoverRepoSort', + 'autodiscoverRepoOrder', ]; private static config: RepoGlobalConfig = {}; diff --git a/lib/config/types.ts b/lib/config/types.ts index 2e55575c98927a..13d21bf4770dc3 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -159,6 +159,8 @@ export interface RepoGlobalConfig { privateKey?: string; privateKeyOld?: string; httpCacheTtlDays?: number; + autodiscoverRepoSort?: 'alpha' | 'created' | 'updated' | 'size' | 'id'; + autodiscoverRepoOrder?: 'asc' | 'desc'; } export interface LegacyAdminConfig { diff --git a/lib/modules/platform/gitea/index.spec.ts b/lib/modules/platform/gitea/index.spec.ts index 77b6cb695af810..47ca5388d8965d 100644 --- a/lib/modules/platform/gitea/index.spec.ts +++ b/lib/modules/platform/gitea/index.spec.ts @@ -39,6 +39,7 @@ describe('modules/platform/gitea/index', () => { let git: jest.Mocked; let hostRules: typeof import('../../../util/host-rules'); let memCache: typeof import('../../../util/cache/memory'); + let globalConfig: typeof import('../../../config/global'); function mockedRepo(opts: Partial): Repo { return partial({ @@ -222,11 +223,10 @@ describe('modules/platform/gitea/index', () => { git.getBranchCommit.mockReturnValue(mockCommitHash); hostRules = await import('../../../util/host-rules'); hostRules.clear(); - + globalConfig = await import('../../../config/global'); setBaseUrl('https://gitea.renovatebot.com/'); - delete process.env.RENOVATE_X_AUTODISCOVER_REPO_SORT; - delete process.env.RENOVATE_X_AUTODISCOVER_REPO_ORDER; + globalConfig.GlobalConfig.reset(); }); async function initFakePlatform( @@ -421,8 +421,10 @@ describe('modules/platform/gitea/index', () => { }); it('Sorts repos', async () => { - process.env.RENOVATE_X_AUTODISCOVER_REPO_SORT = 'updated'; - process.env.RENOVATE_X_AUTODISCOVER_REPO_ORDER = 'desc'; + globalConfig.GlobalConfig.set({ + autodiscoverRepoSort: 'updated', + autodiscoverRepoOrder: 'desc', + }); const scope = httpMock .scope('https://gitea.com/api/v1') .get('/repos/search') diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index 1117fe91cd54e0..56d040f2a7a84f 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -1,5 +1,6 @@ import is from '@sindresorhus/is'; import semver from 'semver'; +import { GlobalConfig } from '../../../config/global'; import { REPOSITORY_ACCESS_FORBIDDEN, REPOSITORY_ARCHIVED, @@ -160,6 +161,8 @@ async function lookupLabelByName(name: string): Promise { } async function fetchRepositories(topic?: string): Promise { + const autodiscoverRepoSort = GlobalConfig.get('autodiscoverRepoSort'); + const autodiscoverRepoOrder = GlobalConfig.get('autodiscoverRepoOrder'); const repos = await helper.searchRepos({ uid: botUserID, archived: false, @@ -167,11 +170,11 @@ async function fetchRepositories(topic?: string): Promise { topic: true, q: topic, }), - ...(process.env.RENOVATE_X_AUTODISCOVER_REPO_SORT && { - sort: process.env.RENOVATE_X_AUTODISCOVER_REPO_SORT as RepoSortMethod, + ...(autodiscoverRepoSort && { + sort: autodiscoverRepoSort as RepoSortMethod, }), - ...(process.env.RENOVATE_X_AUTODISCOVER_REPO_ORDER && { - order: process.env.RENOVATE_X_AUTODISCOVER_REPO_ORDER as SortMethod, + ...(autodiscoverRepoOrder && { + order: autodiscoverRepoOrder as SortMethod, }), }); return repos.filter(usableRepo).map((r) => r.full_name); diff --git a/lib/modules/platform/gitea/readme.md b/lib/modules/platform/gitea/readme.md index 3ce5a31cf167fd..b130a4aa68590c 100644 --- a/lib/modules/platform/gitea/readme.md +++ b/lib/modules/platform/gitea/readme.md @@ -48,5 +48,5 @@ Repositories are ignored when one of the following conditions is met: - Pull requests are disabled for that repository You can change the default server-side sort method and order for autodiscover API. -Set those via [`RENOVATE_X_AUTODISCOVER_REPO_SORT`](../../../self-hosted-experimental.md#renovate_x_autodiscover_repo_sort) and [`RENOVATE_X_AUTODISCOVER_REPO_ORDER`](../../../self-hosted-experimental.md#renovate_x_autodiscover_repo_order). +Set those via [`autodiscoverRepoSort`](../../../self-hosted-configuration.md#autodiscoverRepoSort) and [`autodiscoverRepoOrder`](../../../self-hosted-configuration.md#autodiscoverRepoOrder). Read the [Gitea swagger docs](https://try.gitea.io/api/swagger#/repository/repoSearch) for more details. From 4bd9e7071a14a46f8b7601388b155046d5c28c33 Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Mon, 29 Apr 2024 21:02:34 +0545 Subject: [PATCH 02/10] add types --- lib/config/options/index.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 995e05b93cbb90..7fbd24e927c7f2 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -14,6 +14,26 @@ const options: RenovateOptions[] = [ subType: 'string', globalOnly: true, }, + { + name: 'autodiscoverRepoOrder', + description: + 'The order method for autodiscover server side repository search.', + type: 'string', + default: 'asc', + globalOnly: true, + allowedValues: ['asc', 'desc'], + supportedPlatforms: ['gitea'], + }, + { + name: 'autodiscoverRepoSort', + description: + 'The sort method for autodiscover server side repository search.', + type: 'string', + default: 'aplha', + globalOnly: true, + allowedValues: ['alpha', 'created', 'updated', 'size', 'id'], + supportedPlatforms: ['gitea'], + }, { name: 'allowedEnv', description: From f1c71c435859aaa32454c3e5cedb12c00d46cdb4 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Mon, 29 Apr 2024 21:21:35 +0545 Subject: [PATCH 03/10] Apply suggestions from code review Co-authored-by: Rhys Arkins --- docs/usage/self-hosted-configuration.md | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index f229191d63e451..c098517b03ff29 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -235,41 +235,16 @@ For more details on this syntax see Renovate's [string pattern matching document ## autodiscoverRepoOrder - -!!! note - For the Forgejo and Gitea platform only. - The order method for autodiscover server side repository search. > If multiple `autodiscoverTopics` are used resulting order will be per topic not global. -Allowed values: - -- `asc` -- `desc` - -Default value: `asc`. - ## autodiscoverRepoSort - -!!! note - For the Forgejo and Gitea platform only. - The sort method for autodiscover server side repository search. > If multiple `autodiscoverTopics` are used resulting order will be per topic not global. -Allowed values: - -- `alpha` -- `created` -- `updated` -- `size` -- `id` - -Default value: `alpha`. - ## autodiscoverTopics Some platforms allow you to add tags, or topics, to repositories and retrieve repository lists by specifying those From 0746a9cbf8cd281c1e1ff1e8ad037f40cc4ce4df Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Tue, 30 Apr 2024 01:24:43 +0545 Subject: [PATCH 04/10] pass sort & order along with topic --- lib/modules/platform/gitea/index.spec.ts | 14 +++------ lib/modules/platform/gitea/index.ts | 39 ++++++++++++++++++------ lib/modules/platform/types.ts | 3 ++ lib/workers/global/autodiscover.ts | 2 ++ 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/lib/modules/platform/gitea/index.spec.ts b/lib/modules/platform/gitea/index.spec.ts index 47ca5388d8965d..f74c4270c15606 100644 --- a/lib/modules/platform/gitea/index.spec.ts +++ b/lib/modules/platform/gitea/index.spec.ts @@ -39,7 +39,6 @@ describe('modules/platform/gitea/index', () => { let git: jest.Mocked; let hostRules: typeof import('../../../util/host-rules'); let memCache: typeof import('../../../util/cache/memory'); - let globalConfig: typeof import('../../../config/global'); function mockedRepo(opts: Partial): Repo { return partial({ @@ -223,10 +222,8 @@ describe('modules/platform/gitea/index', () => { git.getBranchCommit.mockReturnValue(mockCommitHash); hostRules = await import('../../../util/host-rules'); hostRules.clear(); - globalConfig = await import('../../../config/global'); - setBaseUrl('https://gitea.renovatebot.com/'); - globalConfig.GlobalConfig.reset(); + setBaseUrl('https://gitea.renovatebot.com/'); }); async function initFakePlatform( @@ -421,10 +418,6 @@ describe('modules/platform/gitea/index', () => { }); it('Sorts repos', async () => { - globalConfig.GlobalConfig.set({ - autodiscoverRepoSort: 'updated', - autodiscoverRepoOrder: 'desc', - }); const scope = httpMock .scope('https://gitea.com/api/v1') .get('/repos/search') @@ -440,7 +433,10 @@ describe('modules/platform/gitea/index', () => { }); await initFakePlatform(scope); - const repos = await gitea.getRepos(); + const repos = await gitea.getRepos({ + sort: 'updated', + order: 'desc', + }); expect(repos).toEqual(['a/b', 'c/d']); }); }); diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index 56d040f2a7a84f..1e674dfe7547a5 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -1,6 +1,5 @@ import is from '@sindresorhus/is'; import semver from 'semver'; -import { GlobalConfig } from '../../../config/global'; import { REPOSITORY_ACCESS_FORBIDDEN, REPOSITORY_ARCHIVED, @@ -160,9 +159,17 @@ async function lookupLabelByName(name: string): Promise { return labelList.find((l) => l.name === name)?.id ?? null; } -async function fetchRepositories(topic?: string): Promise { - const autodiscoverRepoSort = GlobalConfig.get('autodiscoverRepoSort'); - const autodiscoverRepoOrder = GlobalConfig.get('autodiscoverRepoOrder'); +interface FetchRepositoriesArgs { + topic?: string; + sort?: RepoSortMethod; + order?: SortMethod; +} + +async function fetchRepositories({ + topic, + sort, + order, +}: FetchRepositoriesArgs): Promise { const repos = await helper.searchRepos({ uid: botUserID, archived: false, @@ -170,11 +177,11 @@ async function fetchRepositories(topic?: string): Promise { topic: true, q: topic, }), - ...(autodiscoverRepoSort && { - sort: autodiscoverRepoSort as RepoSortMethod, + ...(sort && { + sort, }), - ...(autodiscoverRepoOrder && { - order: autodiscoverRepoOrder as SortMethod, + ...(order && { + order, }), }); return repos.filter(usableRepo).map((r) => r.full_name); @@ -333,7 +340,16 @@ const platform: Platform = { try { if (config?.topics) { logger.debug({ topics: config.topics }, 'Auto-discovering by topics'); - const repos = await map(config.topics, fetchRepositories); + const fetchRepoArgs: FetchRepositoriesArgs[] = config.topics.map( + (topic) => { + return { + topic, + sort: config.sort, + order: config.order, + }; + }, + ); + const repos = await map(fetchRepoArgs, fetchRepositories); return deduplicateArray(repos.flat()); } else if (config?.namespaces) { logger.debug( @@ -351,7 +367,10 @@ const platform: Platform = { ); return deduplicateArray(repos.flat()); } else { - return await fetchRepositories(); + return await fetchRepositories({ + sort: config?.sort, + order: config?.order, + }); } } catch (err) { logger.error({ err }, 'Gitea getRepos() error'); diff --git a/lib/modules/platform/types.ts b/lib/modules/platform/types.ts index d51e27e1e456be..1cbdf9e2c05877 100644 --- a/lib/modules/platform/types.ts +++ b/lib/modules/platform/types.ts @@ -1,6 +1,7 @@ import type { MergeStrategy } from '../../config/types'; import type { BranchStatus, HostRule, VulnerabilityAlert } from '../../types'; import type { CommitFilesConfig, LongCommitSha } from '../../util/git/types'; +import type { RepoSortMethod, SortMethod } from './gitea/types'; type VulnerabilityKey = string; type VulnerabilityRangeKey = string; @@ -203,6 +204,8 @@ export type EnsureIssueResult = 'updated' | 'created'; export interface AutodiscoverConfig { topics?: string[]; + sort?: RepoSortMethod; + order?: SortMethod; includeMirrors?: boolean; namespaces?: string[]; projects?: string[]; diff --git a/lib/workers/global/autodiscover.ts b/lib/workers/global/autodiscover.ts index e6e633df551a9b..e4da1e8c403b5b 100644 --- a/lib/workers/global/autodiscover.ts +++ b/lib/workers/global/autodiscover.ts @@ -38,6 +38,8 @@ export async function autodiscoverRepositories( // Autodiscover list of repositories let discovered = await platform.getRepos({ topics: config.autodiscoverTopics, + sort: config.autodiscoverRepoSort, + order: config.autodiscoverRepoOrder, includeMirrors: config.includeMirrors, namespaces: config.autodiscoverNamespaces, projects: config.autodiscoverProjects, From d898db6c7e32a7f6d571756afafbe2bc2f45d868 Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Tue, 30 Apr 2024 01:26:00 +0545 Subject: [PATCH 05/10] default null --- lib/config/options/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 7fbd24e927c7f2..eaf28edca80394 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -19,7 +19,7 @@ const options: RenovateOptions[] = [ description: 'The order method for autodiscover server side repository search.', type: 'string', - default: 'asc', + default: null, globalOnly: true, allowedValues: ['asc', 'desc'], supportedPlatforms: ['gitea'], @@ -29,7 +29,7 @@ const options: RenovateOptions[] = [ description: 'The sort method for autodiscover server side repository search.', type: 'string', - default: 'aplha', + default: null, globalOnly: true, allowedValues: ['alpha', 'created', 'updated', 'size', 'id'], supportedPlatforms: ['gitea'], From eb17b076598356761e7be2edb55d2d92d915dd25 Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Tue, 30 Apr 2024 01:28:42 +0545 Subject: [PATCH 06/10] use existing types --- lib/config/types.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/config/types.ts b/lib/config/types.ts index 13d21bf4770dc3..8e48cc9504e9c3 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -2,6 +2,10 @@ import type { LogLevel } from 'bunyan'; import type { PlatformId } from '../constants'; import type { LogLevelRemap } from '../logger/types'; import type { CustomManager } from '../modules/manager/custom/types'; +import type { + RepoSortMethod, + SortMethod, +} from '../modules/platform/gitea/types'; import type { HostRule } from '../types'; import type { GitNoVerifyOption } from '../util/git/types'; import type { MergeConfidence } from '../util/merge-confidence/types'; @@ -159,8 +163,8 @@ export interface RepoGlobalConfig { privateKey?: string; privateKeyOld?: string; httpCacheTtlDays?: number; - autodiscoverRepoSort?: 'alpha' | 'created' | 'updated' | 'size' | 'id'; - autodiscoverRepoOrder?: 'asc' | 'desc'; + autodiscoverRepoSort?: RepoSortMethod; + autodiscoverRepoOrder?: SortMethod; } export interface LegacyAdminConfig { From eeab9d0d67baa3c08026f07cf568c584f3d25d22 Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Tue, 30 Apr 2024 02:53:51 +0545 Subject: [PATCH 07/10] move types to platform/types --- lib/config/types.ts | 5 +---- lib/modules/platform/gitea/index.ts | 4 ++-- lib/modules/platform/gitea/types.ts | 6 +----- lib/modules/platform/types.ts | 4 +++- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/config/types.ts b/lib/config/types.ts index 15af711598c81c..6fbbe0cdea15fa 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -2,10 +2,7 @@ import type { LogLevel } from 'bunyan'; import type { PlatformId } from '../constants'; import type { LogLevelRemap } from '../logger/types'; import type { CustomManager } from '../modules/manager/custom/types'; -import type { - RepoSortMethod, - SortMethod, -} from '../modules/platform/gitea/types'; +import type { RepoSortMethod, SortMethod } from '../modules/platform/types'; import type { HostRule } from '../types'; import type { GitNoVerifyOption } from '../util/git/types'; import type { MergeConfidence } from '../util/merge-confidence/types'; diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index 1e674dfe7547a5..b4859dfe99c140 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -34,6 +34,8 @@ import type { Pr, RepoParams, RepoResult, + RepoSortMethod, + SortMethod, UpdatePrConfig, } from '../types'; import { repoFingerprint } from '../util'; @@ -49,8 +51,6 @@ import type { PRMergeMethod, PRUpdateParams, Repo, - RepoSortMethod, - SortMethod, } from './types'; import { DRAFT_PREFIX, diff --git a/lib/modules/platform/gitea/types.ts b/lib/modules/platform/gitea/types.ts index 32fa78546950d0..3025a89633ec04 100644 --- a/lib/modules/platform/gitea/types.ts +++ b/lib/modules/platform/gitea/types.ts @@ -1,5 +1,5 @@ import type { LongCommitSha } from '../../../util/git/types'; -import type { Pr } from '../types'; +import type { Pr, RepoSortMethod, SortMethod } from '../types'; export interface PrReviewersParams { reviewers?: string[]; @@ -147,10 +147,6 @@ export interface CombinedCommitStatus { statuses: CommitStatus[]; } -export type RepoSortMethod = 'alpha' | 'created' | 'updated' | 'size' | 'id'; - -export type SortMethod = 'asc' | 'desc'; - export interface RepoSearchParams { uid?: number; archived?: boolean; diff --git a/lib/modules/platform/types.ts b/lib/modules/platform/types.ts index 1cbdf9e2c05877..f9e40db5fbdf43 100644 --- a/lib/modules/platform/types.ts +++ b/lib/modules/platform/types.ts @@ -1,7 +1,6 @@ import type { MergeStrategy } from '../../config/types'; import type { BranchStatus, HostRule, VulnerabilityAlert } from '../../types'; import type { CommitFilesConfig, LongCommitSha } from '../../util/git/types'; -import type { RepoSortMethod, SortMethod } from './gitea/types'; type VulnerabilityKey = string; type VulnerabilityRangeKey = string; @@ -202,6 +201,9 @@ export type EnsureCommentRemovalConfig = export type EnsureIssueResult = 'updated' | 'created'; +export type RepoSortMethod = 'alpha' | 'created' | 'updated' | 'size' | 'id'; + +export type SortMethod = 'asc' | 'desc'; export interface AutodiscoverConfig { topics?: string[]; sort?: RepoSortMethod; From e47ccbbae977a74c03a2eeb44873415973ac00d3 Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Tue, 30 Apr 2024 12:00:46 +0545 Subject: [PATCH 08/10] fix: types --- lib/modules/platform/types.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/modules/platform/types.ts b/lib/modules/platform/types.ts index f9e40db5fbdf43..28f622cd61a33c 100644 --- a/lib/modules/platform/types.ts +++ b/lib/modules/platform/types.ts @@ -201,9 +201,15 @@ export type EnsureCommentRemovalConfig = export type EnsureIssueResult = 'updated' | 'created'; -export type RepoSortMethod = 'alpha' | 'created' | 'updated' | 'size' | 'id'; +export type RepoSortMethod = + | 'alpha' + | 'created' + | 'updated' + | 'size' + | 'id' + | null; -export type SortMethod = 'asc' | 'desc'; +export type SortMethod = 'asc' | 'desc' | null; export interface AutodiscoverConfig { topics?: string[]; sort?: RepoSortMethod; From f3ef953a050409c6ef693175f878f1dc31600103 Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Wed, 1 May 2024 00:10:44 +0545 Subject: [PATCH 09/10] massage converted env vars --- lib/workers/global/config/parse/env.spec.ts | 10 +++++++++ lib/workers/global/config/parse/env.ts | 25 +++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/workers/global/config/parse/env.spec.ts b/lib/workers/global/config/parse/env.spec.ts index 664ca142995279..7f564047a34c8e 100644 --- a/lib/workers/global/config/parse/env.spec.ts +++ b/lib/workers/global/config/parse/env.spec.ts @@ -267,6 +267,16 @@ describe('workers/global/config/parse/env', () => { expect(config.token).toBe('a'); }); + it('massages converted experimental env vars', async () => { + const envParam: NodeJS.ProcessEnv = { + RENOVATE_X_AUTODISCOVER_REPO_SORT: 'alpha', + RENOVATE_X_DOCKER_MAX_PAGES: '10', + }; + const config = await env.getConfig(envParam); + expect(config.autodiscoverRepoSort).toBe('alpha'); + expect(config.dockerMaxPages).toBeUndefined(); + }); + describe('RENOVATE_CONFIG tests', () => { let processExit: jest.SpyInstance; diff --git a/lib/workers/global/config/parse/env.ts b/lib/workers/global/config/parse/env.ts index cc1c4f8fb38405..a37141cff4bba7 100644 --- a/lib/workers/global/config/parse/env.ts +++ b/lib/workers/global/config/parse/env.ts @@ -83,6 +83,30 @@ function massageEnvKeyValues(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv { return result; } +const convertedExperimentalEnvVars = [ + 'RENOVATE_X_AUTODISCOVER_REPO_SORT', + 'RENOVATE_X_AUTODISCOVER_REPO_ORDER', +]; + +/** + * Massages the experimental env vars which have been converted to config options + * + * e.g. RENOVATE_X_AUTODISCOVER_REPO_SORT -> RENOVATE_AUTODISCOVER_REPO_SORT + */ +function massageConvertedExperimentalVars( + env: NodeJS.ProcessEnv, +): NodeJS.ProcessEnv { + const result = { ...env }; + for (const key of convertedExperimentalEnvVars) { + if (env[key] !== undefined) { + const newKey = key.replace('RENOVATE_X_', 'RENOVATE_'); + result[newKey] = env[key]; + delete result[key]; + } + } + return result; +} + export async function getConfig( inputEnv: NodeJS.ProcessEnv, ): Promise { @@ -91,6 +115,7 @@ export async function getConfig( env = renameEnvKeys(env); // massage the values of migrated configuration keys env = massageEnvKeyValues(env); + env = massageConvertedExperimentalVars(env); const options = getOptions(); From 227eee6eb60b92ba0a55f1af879a14a312d625fa Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Wed, 1 May 2024 00:11:57 +0545 Subject: [PATCH 10/10] add test --- lib/workers/global/config/parse/env.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/workers/global/config/parse/env.spec.ts b/lib/workers/global/config/parse/env.spec.ts index 7f564047a34c8e..1acaa0b5d5d040 100644 --- a/lib/workers/global/config/parse/env.spec.ts +++ b/lib/workers/global/config/parse/env.spec.ts @@ -271,9 +271,11 @@ describe('workers/global/config/parse/env', () => { const envParam: NodeJS.ProcessEnv = { RENOVATE_X_AUTODISCOVER_REPO_SORT: 'alpha', RENOVATE_X_DOCKER_MAX_PAGES: '10', + RENOVATE_AUTODISCOVER_REPO_ORDER: 'desc', }; const config = await env.getConfig(envParam); expect(config.autodiscoverRepoSort).toBe('alpha'); + expect(config.autodiscoverRepoOrder).toBe('desc'); expect(config.dockerMaxPages).toBeUndefined(); });