From 0936ac67f63bd790d7d71e6a2d0892cba4bc6abd Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Tue, 1 Nov 2022 11:12:33 +0100 Subject: [PATCH] feat(platform/gitea): configurable autodiscover repo sorting (#18636) Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com> --- docs/usage/self-hosted-experimental.md | 33 ++++++++++++++++++++++++ lib/modules/platform/gitea/index.md | 6 +++++ lib/modules/platform/gitea/index.spec.ts | 23 +++++++++++++++++ lib/modules/platform/gitea/index.ts | 8 ++++++ lib/modules/platform/gitea/types.ts | 14 ++++++++++ 5 files changed, 84 insertions(+) diff --git a/docs/usage/self-hosted-experimental.md b/docs/usage/self-hosted-experimental.md index d5f08ab2c2..2c0b6625f3 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 a9af7ebc48..c883172144 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 a27a9755ab..b90c0880d9 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 285f297673..3b49895a7e 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 b1d04ab558..68ec97fc85 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> & -- GitLab