feat(platform/gitea): configurable autodiscover repo sorting (#18636)

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
This commit is contained in:
Michael Kriese 2022-11-01 11:12:33 +01:00 committed by GitHub
parent 1bacabcb7e
commit 0936ac67f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 84 additions and 0 deletions

View file

@ -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. 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` ## `OTEL_EXPORTER_OTLP_ENDPOINT`
If set, Renovate will export OpenTelemetry data to the supplied endpoint. If set, Renovate will export OpenTelemetry data to the supplied endpoint.

View file

@ -24,3 +24,9 @@ Either the account should have full name and email address set to allow Renovate
## Features awaiting implementation ## Features awaiting implementation
- none - 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.

View file

@ -216,6 +216,9 @@ describe('modules/platform/gitea/index', () => {
hostRules.clear(); hostRules.clear();
setBaseUrl('https://gitea.renovatebot.com/'); 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> { function initFakePlatform(version = GITEA_VERSION): Promise<PlatformResult> {
@ -305,6 +308,26 @@ describe('modules/platform/gitea/index', () => {
const repos = await gitea.getRepos(); const repos = await gitea.getRepos();
expect(repos).toEqual(['a/b', 'c/d']); 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',
});
}); });
}); });

View file

@ -45,6 +45,8 @@ import type {
PR, PR,
PRMergeMethod, PRMergeMethod,
Repo, Repo,
RepoSortMethod,
SortMethod,
} from './types'; } from './types';
import { import {
getMergeMethod, getMergeMethod,
@ -345,6 +347,12 @@ const platform: Platform = {
const repos = await helper.searchRepos({ const repos = await helper.searchRepos({
uid: botUserID, uid: botUserID,
archived: false, 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); return repos.filter((r) => !r.mirror).map((r) => r.full_name);
} catch (err) { } catch (err) {

View file

@ -133,9 +133,23 @@ export interface CombinedCommitStatus {
statuses: CommitStatus[]; statuses: CommitStatus[];
} }
export type RepoSortMethod = 'alpha' | 'created' | 'updated' | 'size' | 'id';
export type SortMethod = 'asc' | 'desc';
export interface RepoSearchParams { export interface RepoSearchParams {
uid?: number; uid?: number;
archived?: boolean; archived?: boolean;
/**
* Repo sort type, defaults to `alpha`.
*/
sort?: RepoSortMethod;
/**
* Repo sort order, defaults to `asc`
*/
order?: SortMethod;
} }
export type IssueCreateParams = Partial<IssueUpdateLabelsParams> & export type IssueCreateParams = Partial<IssueUpdateLabelsParams> &