diff --git a/docs/usage/self-hosted-experimental.md b/docs/usage/self-hosted-experimental.md index d5f08ab2c22d43b33e4ef1ce236cd558b6e95300..2c0b6625f3d4716e5f3c385aa525145cfde9f20e 100644 --- a/docs/usage/self-hosted-experimental.md +++ b/docs/usage/self-hosted-experimental.md @@ -63,6 +63,39 @@ Source: [AWS s3 documentation - Interface BucketEndpointInputConfig](https://doc If set, Renovate will terminate the whole process group of a terminated child process spawned by Renovate. +## `RENOVATE_X_AUTODISCOVER_REPO_SORT` + +<!-- prettier-ignore --> +!!! note + For the Gitea platform only. + +The sort method for autodiscover server side repository search. + +Allowed values: + +- `alpha` +- `created` +- `updated` +- `size` +- `id` + +Default value: `alpha`. + +## `RENOVATE_X_AUTODISCOVER_REPO_ORDER` + +<!-- prettier-ignore --> +!!! note + For the Gitea platform only. + +The order method for autodiscover server side repository search. + +Allowed values: + +- `asc` +- `desc` + +Default value: `asc`. + ## `OTEL_EXPORTER_OTLP_ENDPOINT` If set, Renovate will export OpenTelemetry data to the supplied endpoint. diff --git a/lib/modules/platform/gitea/index.md b/lib/modules/platform/gitea/index.md index a9af7ebc483e35c41d82037e70ea002b1c1b1d13..c883172144548fca66937276600f870b003b7ad6 100644 --- a/lib/modules/platform/gitea/index.md +++ b/lib/modules/platform/gitea/index.md @@ -24,3 +24,9 @@ Either the account should have full name and email address set to allow Renovate ## Features awaiting implementation - none + +## Repo autodiscover sorting + +You can change the default server-side sort method and order for autodiscover API. +Set those via [`RENOVATE_X_AUTODISCOVER_REPO_SORT`](https://docs.renovatebot.com/self-hosted-experimental/#renovate_x_autodiscover_repo_sort) and [`RENOVATE_X_AUTODISCOVER_REPO_ORDER`](https://docs.renovatebot.com/self-hosted-experimental/#renovate_x_autodiscover_repo_order). +Read the [Gitea swagger docs](https://try.gitea.io/api/swagger#/repository/repoSearch) for more details. diff --git a/lib/modules/platform/gitea/index.spec.ts b/lib/modules/platform/gitea/index.spec.ts index a27a9755ab1ce4e93ec8febaf682c69043fca866..b90c0880d968c603e0dcabaec7a0466553e95c73 100644 --- a/lib/modules/platform/gitea/index.spec.ts +++ b/lib/modules/platform/gitea/index.spec.ts @@ -216,6 +216,9 @@ describe('modules/platform/gitea/index', () => { hostRules.clear(); setBaseUrl('https://gitea.renovatebot.com/'); + + delete process.env.RENOVATE_X_AUTODISCOVER_REPO_SORT; + delete process.env.RENOVATE_X_AUTODISCOVER_REPO_ORDER; }); function initFakePlatform(version = GITEA_VERSION): Promise<PlatformResult> { @@ -305,6 +308,26 @@ describe('modules/platform/gitea/index', () => { const repos = await gitea.getRepos(); expect(repos).toEqual(['a/b', 'c/d']); + expect(helper.searchRepos).toHaveBeenCalledWith({ + uid: undefined, + archived: false, + }); + }); + + it('Sorts repos', async () => { + process.env.RENOVATE_X_AUTODISCOVER_REPO_SORT = 'updated'; + process.env.RENOVATE_X_AUTODISCOVER_REPO_ORDER = 'desc'; + helper.searchRepos.mockResolvedValueOnce(mockRepos); + + const repos = await gitea.getRepos(); + expect(repos).toEqual(['a/b', 'c/d']); + + expect(helper.searchRepos).toHaveBeenCalledWith({ + uid: undefined, + archived: false, + sort: 'updated', + order: 'desc', + }); }); }); diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index 285f297673c0cf3aff7c504656dc020a6be6e026..3b49895a7ec9aba1b2a7a202b41faa18ae4aed3c 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -45,6 +45,8 @@ import type { PR, PRMergeMethod, Repo, + RepoSortMethod, + SortMethod, } from './types'; import { getMergeMethod, @@ -345,6 +347,12 @@ const platform: Platform = { const repos = await helper.searchRepos({ uid: botUserID, archived: false, + ...(process.env.RENOVATE_X_AUTODISCOVER_REPO_SORT && { + sort: process.env.RENOVATE_X_AUTODISCOVER_REPO_SORT as RepoSortMethod, + }), + ...(process.env.RENOVATE_X_AUTODISCOVER_REPO_ORDER && { + order: process.env.RENOVATE_X_AUTODISCOVER_REPO_ORDER as SortMethod, + }), }); return repos.filter((r) => !r.mirror).map((r) => r.full_name); } catch (err) { diff --git a/lib/modules/platform/gitea/types.ts b/lib/modules/platform/gitea/types.ts index b1d04ab5589b98ee9c436dfc02f1cbf3483a5b2e..68ec97fc8530f533bab247414cf0dc6688f2302c 100644 --- a/lib/modules/platform/gitea/types.ts +++ b/lib/modules/platform/gitea/types.ts @@ -133,9 +133,23 @@ 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; + + /** + * Repo sort type, defaults to `alpha`. + */ + sort?: RepoSortMethod; + + /** + * Repo sort order, defaults to `asc` + */ + order?: SortMethod; } export type IssueCreateParams = Partial<IssueUpdateLabelsParams> &