From 513fc08bba63bd8044960237489081a046d6183c Mon Sep 17 00:00:00 2001 From: Ronald van Butselaar Date: Fri, 2 Feb 2024 14:59:15 +0100 Subject: [PATCH 1/5] Update docs --- docs/usage/self-hosted-configuration.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 672d71d06d71ac..786fc26e7a72c6 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -185,6 +185,11 @@ For example: } ``` + +!!! note + On Gitea/Forgejo, you can't use `autodiscoverTopics` together with `autodiscoverNamespaces` because both platforms do not support this. + Topics are preferred and `autodiscoverNamespaces` will be ignored when you configure `autodiscoverTopics` on Gitea/Forgejo. + ## autodiscoverTopics Some platforms allow you to add tags, or topics, to repositories and retrieve repository lists by specifying those From e3b429ddff47563c8b019eead24929bf43ab8efe Mon Sep 17 00:00:00 2001 From: Ronald van Butselaar Date: Fri, 2 Feb 2024 15:01:45 +0100 Subject: [PATCH 2/5] Gitea namespaces support --- lib/config/options/index.ts | 2 +- .../platform/gitea/gitea-helper.spec.ts | 10 +++++++++ lib/modules/platform/gitea/gitea-helper.ts | 13 ++++++++++++ lib/modules/platform/gitea/index.spec.ts | 20 ++++++++++++++++++ lib/modules/platform/gitea/index.ts | 21 +++++++++++++++---- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 17a556a8c69597..51b716741b3f48 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -852,7 +852,7 @@ const options: RenovateOptions[] = [ subType: 'string', default: null, globalOnly: true, - supportedPlatforms: ['gitlab'], + supportedPlatforms: ['gitea', 'gitlab'], }, { name: 'autodiscoverTopics', diff --git a/lib/modules/platform/gitea/gitea-helper.spec.ts b/lib/modules/platform/gitea/gitea-helper.spec.ts index 28bcf498247421..9ee88efbffe430 100644 --- a/lib/modules/platform/gitea/gitea-helper.spec.ts +++ b/lib/modules/platform/gitea/gitea-helper.spec.ts @@ -22,6 +22,7 @@ import { getRepoLabels, getVersion, mergePR, + orgListRepos, requestPrReviewers, searchIssues, searchRepos, @@ -250,6 +251,15 @@ describe('modules/platform/gitea/gitea-helper', () => { }); }); + describe('orgListRepos', () => { + it('should call /api/v1/orgs/[organization]/repos endpoint', async () => { + httpMock.scope(baseUrl).get('/orgs/some/repos').reply(200, mockRepo); + + const res = await orgListRepos('some'); + expect(res).toEqual(mockRepo); + }); + }); + describe('getRepo', () => { it('should call /api/v1/repos/[repo] endpoint', async () => { httpMock diff --git a/lib/modules/platform/gitea/gitea-helper.ts b/lib/modules/platform/gitea/gitea-helper.ts index 3b25b850efeffc..fffa9dc5d13106 100644 --- a/lib/modules/platform/gitea/gitea-helper.ts +++ b/lib/modules/platform/gitea/gitea-helper.ts @@ -75,6 +75,19 @@ export async function searchRepos( return res.body.data; } +export async function orgListRepos( + organization: string, + options?: GiteaHttpOptions, +): Promise { + const url = `${API_PATH}/orgs/${organization}/repos`; + const res = await giteaHttp.getJson(url, { + ...options, + paginate: true, + }); + + return res.body; +} + export async function getRepo( repoPath: string, options?: GiteaHttpOptions, diff --git a/lib/modules/platform/gitea/index.spec.ts b/lib/modules/platform/gitea/index.spec.ts index 3084f4a3c169b0..0925a53c0eadec 100644 --- a/lib/modules/platform/gitea/index.spec.ts +++ b/lib/modules/platform/gitea/index.spec.ts @@ -72,6 +72,12 @@ describe('modules/platform/gitea/index', () => { const mockTopicRepos: Repo[] = [partial({ full_name: 'a/b' })]; + const mockNamespaceRepos: Repo[] = [ + partial({ full_name: 'org1/repo' }), + partial({ full_name: 'org2/repo' }), + partial({ full_name: 'org2/repo2', archived: true }), + ]; + const mockPRs: MockPr[] = [ partial({ number: 1, @@ -390,6 +396,20 @@ describe('modules/platform/gitea/index', () => { expect(repos).toEqual(['a/b']); }); + it('should query the organization endpoint for each namespace', async () => { + const scope = httpMock.scope('https://gitea.com/api/v1'); + + scope.get('/orgs/org1/repos').reply(200, mockNamespaceRepos); + scope.get('/orgs/org2/repos').reply(200, mockNamespaceRepos); + + await initFakePlatform(scope); + + const repos = await gitea.getRepos({ + namespaces: ['org1', 'org2'], + }); + expect(repos).toEqual(['org1/repo', 'org2/repo']); + }); + it('Sorts repos', async () => { process.env.RENOVATE_X_AUTODISCOVER_REPO_SORT = 'updated'; process.env.RENOVATE_X_AUTODISCOVER_REPO_ORDER = 'desc'; diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index 595c8402221428..ee2ae0099fa68c 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -319,12 +319,25 @@ const platform: Platform = { async getRepos(config?: AutodiscoverConfig): Promise { logger.debug('Auto-discovering Gitea repositories'); try { - if (!config?.topics) { + if (config?.topics) { + logger.debug('Auto-discovering Gitea repositories by topics'); + const repos = await map(config.topics, fetchRepositories); + return deduplicateArray(repos.flat()); + } else if (config?.namespaces) { + logger.debug('Auto-discovering Gitea repositories by organization'); + const repos = await map( + config.namespaces, + async (organization: string) => { + const orgRepos = await helper.orgListRepos(organization); + return orgRepos + .filter((r) => !r.mirror && !r.archived) + .map((r) => r.full_name); + }, + ); + return deduplicateArray(repos.flat()); + } else { return await fetchRepositories(); } - - const repos = await map(config.topics, fetchRepositories); - return deduplicateArray(repos.flat()); } catch (err) { logger.error({ err }, 'Gitea getRepos() error'); throw err; From 7ac51ebbc0d62f7280e292a39594bbd64749c82b Mon Sep 17 00:00:00 2001 From: Ronald van Butselaar <26540376+rvanbutselaar@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:40:12 +0100 Subject: [PATCH 3/5] Update lib/modules/platform/gitea/index.ts Co-authored-by: Michael Kriese --- lib/modules/platform/gitea/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index ee2ae0099fa68c..d296a837191797 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -320,7 +320,7 @@ const platform: Platform = { logger.debug('Auto-discovering Gitea repositories'); try { if (config?.topics) { - logger.debug('Auto-discovering Gitea repositories by topics'); + logger.debug({ topics: config.topics }, 'Auto-discovering by topics'); const repos = await map(config.topics, fetchRepositories); return deduplicateArray(repos.flat()); } else if (config?.namespaces) { From 61c490a047785458a3c72f65e5616d782d2ce510 Mon Sep 17 00:00:00 2001 From: Ronald van Butselaar <26540376+rvanbutselaar@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:41:04 +0100 Subject: [PATCH 4/5] Update lib/modules/platform/gitea/index.ts Co-authored-by: Michael Kriese --- lib/modules/platform/gitea/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index d296a837191797..5f6d27678e14aa 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -324,7 +324,7 @@ const platform: Platform = { const repos = await map(config.topics, fetchRepositories); return deduplicateArray(repos.flat()); } else if (config?.namespaces) { - logger.debug('Auto-discovering Gitea repositories by organization'); + logger.debug({ namespaces: config.namespaces }, 'Auto-discovering by organization'); const repos = await map( config.namespaces, async (organization: string) => { From b4966a05006c6c3af11f6161413f692da542eafc Mon Sep 17 00:00:00 2001 From: Ronald van Butselaar Date: Mon, 4 Mar 2024 21:52:32 +0100 Subject: [PATCH 5/5] Linter fix --- lib/modules/platform/gitea/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index dc2232facc54f6..4482eb1b9db37b 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -324,7 +324,10 @@ const platform: Platform = { const repos = await map(config.topics, fetchRepositories); return deduplicateArray(repos.flat()); } else if (config?.namespaces) { - logger.debug({ namespaces: config.namespaces }, 'Auto-discovering by organization'); + logger.debug( + { namespaces: config.namespaces }, + 'Auto-discovering by organization', + ); const repos = await map( config.namespaces, async (organization: string) => {