diff --git a/lib/constants/platform.spec.ts b/lib/constants/platform.spec.ts index d17b855807bc2b..54b9e718df242a 100644 --- a/lib/constants/platform.spec.ts +++ b/lib/constants/platform.spec.ts @@ -1,4 +1,5 @@ import { BitbucketTagsDatasource } from '../modules/datasource/bitbucket-tags'; +import { GiteaTagsDatasource } from '../modules/datasource/gitea-tags'; import { GithubReleasesDatasource } from '../modules/datasource/github-releases'; import { GithubTagsDatasource } from '../modules/datasource/github-tags'; import { GitlabPackagesDatasource } from '../modules/datasource/gitlab-packages'; @@ -10,11 +11,19 @@ import { id as GITHUB_CHANGELOG_ID } from '../workers/repository/update/pr/chang import { id as GITLAB_CHANGELOG_ID } from '../workers/repository/update/pr/changelog/gitlab'; import { BITBUCKET_API_USING_HOST_TYPES, + GITEA_API_USING_HOST_TYPES, GITHUB_API_USING_HOST_TYPES, GITLAB_API_USING_HOST_TYPES, } from './platforms'; describe('constants/platform', () => { + it('should be part of the GITEA_API_USING_HOST_TYPES', () => { + expect( + GITEA_API_USING_HOST_TYPES.includes(GiteaTagsDatasource.id) + ).toBeTrue(); + expect(GITEA_API_USING_HOST_TYPES.includes('gitea')).toBeTrue(); + }); + it('should be part of the GITLAB_API_USING_HOST_TYPES', () => { expect( GITLAB_API_USING_HOST_TYPES.includes(GitlabTagsDatasource.id) diff --git a/lib/constants/platforms.ts b/lib/constants/platforms.ts index 47f16640debaa1..4d1abf74ec786f 100644 --- a/lib/constants/platforms.ts +++ b/lib/constants/platforms.ts @@ -8,6 +8,8 @@ export type PlatformId = | 'gitlab' | 'local'; +export const GITEA_API_USING_HOST_TYPES = ['gitea', 'gitea-tags']; + export const GITHUB_API_USING_HOST_TYPES = [ 'github', 'github-releases', diff --git a/lib/modules/datasource/api.ts b/lib/modules/datasource/api.ts index 0abd7bfd7ee9c2..dbb68d7a6c83f9 100644 --- a/lib/modules/datasource/api.ts +++ b/lib/modules/datasource/api.ts @@ -23,6 +23,7 @@ import { GalaxyDatasource } from './galaxy'; import { GalaxyCollectionDatasource } from './galaxy-collection'; import { GitRefsDatasource } from './git-refs'; import { GitTagsDatasource } from './git-tags'; +import { GiteaTagsDatasource } from './gitea-tags'; import { GithubReleaseAttachmentsDatasource } from './github-release-attachments'; import { GithubReleasesDatasource } from './github-releases'; import { GithubRunnersDatasource } from './github-runners'; @@ -86,6 +87,7 @@ api.set(GalaxyDatasource.id, new GalaxyDatasource()); api.set(GalaxyCollectionDatasource.id, new GalaxyCollectionDatasource()); api.set(GitRefsDatasource.id, new GitRefsDatasource()); api.set(GitTagsDatasource.id, new GitTagsDatasource()); +api.set(GiteaTagsDatasource.id, new GiteaTagsDatasource()); api.set( GithubReleaseAttachmentsDatasource.id, new GithubReleaseAttachmentsDatasource() diff --git a/lib/modules/datasource/gitea-tags/index.spec.ts b/lib/modules/datasource/gitea-tags/index.spec.ts new file mode 100644 index 00000000000000..577ded586605d8 --- /dev/null +++ b/lib/modules/datasource/gitea-tags/index.spec.ts @@ -0,0 +1,310 @@ +import { getDigest, getPkgReleases } from '..'; +import * as httpMock from '../../../../test/http-mock'; +import { GiteaTagsDatasource } from '.'; + +const datasource = GiteaTagsDatasource.id; + +describe('modules/datasource/gitea-tags/index', () => { + describe('getReleases', () => { + it('returns tags from gitea.com', async () => { + const body = [ + { + name: 'v9.2.0', + message: + 'v9.2.0\n\nBump to Gitea 1.20.3\n\nFull changes found here: https://gitea.com/gitea/helm-chart/compare/v9.1.0...v9.2.0', + id: '949a0213a49b4a3d6f7696a09bd19ad295e51513', + commit: { + url: 'https://gitea.com/api/v1/repos/gitea/helm-chart/git/commits/949a0213a49b4a3d6f7696a09bd19ad295e51513', + sha: '35fcb41ce2d03b44186cc82d4ea619dc2fcb6f7d', + created: '2023-08-21T16:27:29Z', + }, + zipball_url: 'https://gitea.com/gitea/helm-chart/archive/v9.2.0.zip', + tarball_url: + 'https://gitea.com/gitea/helm-chart/archive/v9.2.0.tar.gz', + }, + { + name: 'v9.1.0', + message: '9.1.0', + id: '4439267777d70ccd16733c8e95da1e4437cc2378', + commit: { + url: 'https://gitea.com/api/v1/repos/gitea/helm-chart/git/commits/4439267777d70ccd16733c8e95da1e4437cc2378', + sha: '1ea6cb4633c2e01d02dc910bcb67d7710842abc7', + created: '2023-07-31T09:04:49+02:00', + }, + zipball_url: 'https://gitea.com/gitea/helm-chart/archive/v9.1.0.zip', + tarball_url: + 'https://gitea.com/gitea/helm-chart/archive/v9.1.0.tar.gz', + }, + { + name: 'v9.0.4', + message: '9.0.4', + id: '9b9301e008226fe02c5cc6bcab59c03c01abffea', + commit: { + url: 'https://gitea.com/api/v1/repos/gitea/helm-chart/git/commits/9b9301e008226fe02c5cc6bcab59c03c01abffea', + sha: '478fd6044e971d3c991e34fa449201397c2f5ea8', + created: '2023-07-22T14:06:30+02:00', + }, + zipball_url: 'https://gitea.com/gitea/helm-chart/archive/v9.0.4.zip', + tarball_url: + 'https://gitea.com/gitea/helm-chart/archive/v9.0.4.tar.gz', + }, + { + name: 'v9.0.3', + message: '0.9.3', + id: 'a3f37d2b698e4e4d16e396f2d002da269845267b', + commit: { + url: 'https://gitea.com/api/v1/repos/gitea/helm-chart/git/commits/a3f37d2b698e4e4d16e396f2d002da269845267b', + sha: 'aa8f543c08f874754ccc3e5f136e0b46742b3992', + created: '2023-07-19T23:45:28+02:00', + }, + zipball_url: 'https://gitea.com/gitea/helm-chart/archive/v9.0.3.zip', + tarball_url: + 'https://gitea.com/gitea/helm-chart/archive/v9.0.3.tar.gz', + }, + { + name: 'v9.0.2', + message: '9.0.2', + id: '86c80d22cd12c98e3639ba00bd6b266d901a5af3', + commit: { + url: 'https://gitea.com/api/v1/repos/gitea/helm-chart/git/commits/86c80d22cd12c98e3639ba00bd6b266d901a5af3', + sha: '81612bd7882f0b3b5d70308a8e7fcfb5d165ec7c', + created: '2023-07-19T21:54:12+02:00', + }, + zipball_url: 'https://gitea.com/gitea/helm-chart/archive/v9.0.2.zip', + tarball_url: + 'https://gitea.com/gitea/helm-chart/archive/v9.0.2.tar.gz', + }, + ]; + httpMock + .scope('https://gitea.com') + .get('/api/v1/repos/gitea/helm-chart/tags') + .reply(200, body); + const res = await getPkgReleases({ + datasource, + packageName: 'gitea/helm-chart', + }); + expect(res).toEqual({ + registryUrl: 'https://gitea.com', + releases: [ + { + gitRef: 'v9.0.2', + newDigest: '81612bd7882f0b3b5d70308a8e7fcfb5d165ec7c', + releaseTimestamp: '2023-07-19T19:54:12.000Z', + version: 'v9.0.2', + }, + { + gitRef: 'v9.0.3', + newDigest: 'aa8f543c08f874754ccc3e5f136e0b46742b3992', + releaseTimestamp: '2023-07-19T21:45:28.000Z', + version: 'v9.0.3', + }, + { + gitRef: 'v9.0.4', + newDigest: '478fd6044e971d3c991e34fa449201397c2f5ea8', + releaseTimestamp: '2023-07-22T12:06:30.000Z', + version: 'v9.0.4', + }, + { + gitRef: 'v9.1.0', + newDigest: '1ea6cb4633c2e01d02dc910bcb67d7710842abc7', + releaseTimestamp: '2023-07-31T07:04:49.000Z', + version: 'v9.1.0', + }, + { + gitRef: 'v9.2.0', + newDigest: '35fcb41ce2d03b44186cc82d4ea619dc2fcb6f7d', + releaseTimestamp: '2023-08-21T16:27:29.000Z', + version: 'v9.2.0', + }, + ], + sourceUrl: 'https://gitea.com/gitea/helm-chart', + }); + }); + + it('returns tags from codeberg.org', async () => { + const body = [ + { + name: '0.11.0', + message: + 'fix(deps): update helm release postgresql to v12.9.0 (#174)\n\nReviewed-on: https://codeberg.org/forgejo-contrib/forgejo-helm/pulls/174\nCo-authored-by: Michael Kriese \nCo-committed-by: Michael Kriese ', + id: '7eb7edcfd00ffab9dddbae9e9b2deace305c9a84', + commit: { + url: 'https://codeberg.org/api/v1/repos/forgejo-contrib/forgejo-helm/git/commits/7eb7edcfd00ffab9dddbae9e9b2deace305c9a84', + sha: '7eb7edcfd00ffab9dddbae9e9b2deace305c9a84', + created: '2023-08-25T08:26:28Z', + }, + zipball_url: + 'https://codeberg.org/forgejo-contrib/forgejo-helm/archive/0.11.0.zip', + tarball_url: + 'https://codeberg.org/forgejo-contrib/forgejo-helm/archive/0.11.0.tar.gz', + }, + { + name: 'v0.10.1', + message: + 'fix(deps): update forgejo docker tag to v1.20.2-0 (#171)\n\nCo-authored-by: Michael Kriese \nReviewed-on: https://codeberg.org/forgejo-contrib/forgejo-helm/pulls/171', + id: 'ecd9b535a128d4e6d643fde37bb05cd751b8d9f4', + commit: { + url: 'https://codeberg.org/api/v1/repos/forgejo-contrib/forgejo-helm/git/commits/ecd9b535a128d4e6d643fde37bb05cd751b8d9f4', + sha: 'ecd9b535a128d4e6d643fde37bb05cd751b8d9f4', + created: '2023-08-02T20:30:48Z', + }, + zipball_url: + 'https://codeberg.org/forgejo-contrib/forgejo-helm/archive/v0.10.1.zip', + tarball_url: + 'https://codeberg.org/forgejo-contrib/forgejo-helm/archive/v0.10.1.tar.gz', + }, + { + name: 'v0.10.0', + message: + 'feat(deps)!: update forgejo docker tag to v1.20.1-0 (#167)\n\nBREAKING CHANGE: Forgejo minor update\n\nCo-authored-by: Michael Kriese \nReviewed-on: https://codeberg.org/forgejo-contrib/forgejo-helm/pulls/167', + id: '5677cf39d4818da26931783a3438a660ae5f427d', + commit: { + url: 'https://codeberg.org/api/v1/repos/forgejo-contrib/forgejo-helm/git/commits/5677cf39d4818da26931783a3438a660ae5f427d', + sha: '5677cf39d4818da26931783a3438a660ae5f427d', + created: '2023-07-27T06:18:23Z', + }, + zipball_url: + 'https://codeberg.org/forgejo-contrib/forgejo-helm/archive/v0.10.0.zip', + tarball_url: + 'https://codeberg.org/forgejo-contrib/forgejo-helm/archive/v0.10.0.tar.gz', + }, + ]; + httpMock + .scope('https://codeberg.org') + .get('/api/v1/repos/forgejo-contrib/forgejo-helm/tags') + .reply(200, body); + const res = await getPkgReleases({ + datasource, + registryUrls: ['https://codeberg.org'], + packageName: 'forgejo-contrib/forgejo-helm', + }); + expect(res).toEqual({ + registryUrl: 'https://codeberg.org', + releases: [ + { + gitRef: 'v0.10.0', + newDigest: '5677cf39d4818da26931783a3438a660ae5f427d', + releaseTimestamp: '2023-07-27T06:18:23.000Z', + version: 'v0.10.0', + }, + { + gitRef: 'v0.10.1', + newDigest: 'ecd9b535a128d4e6d643fde37bb05cd751b8d9f4', + releaseTimestamp: '2023-08-02T20:30:48.000Z', + version: 'v0.10.1', + }, + { + gitRef: '0.11.0', + newDigest: '7eb7edcfd00ffab9dddbae9e9b2deace305c9a84', + releaseTimestamp: '2023-08-25T08:26:28.000Z', + version: '0.11.0', + }, + ], + sourceUrl: 'https://codeberg.org/forgejo-contrib/forgejo-helm', + }); + }); + }); + + describe('getDigest', () => { + it('returns commits from codeberg.org', async () => { + const body = [ + { + url: 'https://codeberg.org/api/v1/repos/forgejo-contrib/forgejo-helm/git/commits/7eb7edcfd00ffab9dddbae9e9b2deace305c9a84', + sha: '7eb7edcfd00ffab9dddbae9e9b2deace305c9a84', + created: '2023-08-25T08:26:28Z', + html_url: + 'https://codeberg.org/forgejo-contrib/forgejo-helm/commit/7eb7edcfd00ffab9dddbae9e9b2deace305c9a84', + commit: { + url: 'https://codeberg.org/api/v1/repos/forgejo-contrib/forgejo-helm/git/commits/7eb7edcfd00ffab9dddbae9e9b2deace305c9a84', + author: { + name: 'Michael Kriese', + email: 'viceice@noreply.codeberg.org', + date: '2023-08-25T08:26:28Z', + }, + committer: { + name: 'Michael Kriese', + email: 'viceice@noreply.codeberg.org', + date: '2023-08-25T08:26:28Z', + }, + message: + 'fix(deps): update helm release postgresql to v12.9.0 (#174)\n\nReviewed-on: https://codeberg.org/forgejo-contrib/forgejo-helm/pulls/174\nCo-authored-by: Michael Kriese \nCo-committed-by: Michael Kriese \n', + tree: { + url: 'https://codeberg.org/api/v1/repos/forgejo-contrib/forgejo-helm/git/trees/7eb7edcfd00ffab9dddbae9e9b2deace305c9a84', + sha: '7eb7edcfd00ffab9dddbae9e9b2deace305c9a84', + created: '2023-08-25T08:26:28Z', + }, + verification: null, + }, + + parents: [ + { + url: 'https://codeberg.org/api/v1/repos/forgejo-contrib/forgejo-helm/git/commits/f19d22c6643b4643c4b2e96482b07527c84d2106', + sha: 'f19d22c6643b4643c4b2e96482b07527c84d2106', + created: '0001-01-01T00:00:00Z', + }, + ], + files: null, + stats: null, + }, + ]; + httpMock + .scope('https://codeberg.org') + .get( + '/api/v1/repos/forgejo-contrib/forgejo-helm/commits?stat=false&verification=false&files=false&page=1&limit=1' + ) + .reply(200, body); + + const res = await getDigest({ + datasource, + registryUrls: ['https://codeberg.org'], + packageName: 'forgejo-contrib/forgejo-helm', + }); + expect(res).toBe('7eb7edcfd00ffab9dddbae9e9b2deace305c9a84'); + }); + }); + + describe('getDigest with no commits', () => { + it('returns commits from gitea.com', async () => { + httpMock + .scope('https://gitea.com') + .get( + '/api/v1/repos/some/dep2/commits?stat=false&verification=false&files=false&page=1&limit=1' + ) + .reply(200, []); + const res = await getDigest({ + datasource, + packageName: 'some/dep2', + }); + expect(res).toBeNull(); + }); + }); + + describe('getTagCommit', () => { + it('returns tags commit hash from gitea.com', async () => { + const body = { + name: 'v9.0.1', + message: 'v9.0.1', + id: 'fb4d493a588380ac7a4037d81664363415f31650', + commit: { + url: 'https://gitea.com/api/v1/repos/gitea/helm-chart/git/commits/fb4d493a588380ac7a4037d81664363415f31650', + sha: '29c9bbb4bfec04ab22761cc2d999eb0fcb8acbed', + created: '2023-07-19T08:42:55+02:00', + }, + zipball_url: 'https://gitea.com/gitea/helm-chart/archive/v9.0.1.zip', + tarball_url: 'https://gitea.com/gitea/helm-chart/archive/v9.0.1.tar.gz', + }; + httpMock + .scope('https://gitea.com') + .get('/api/v1/repos/gitea/helm-chart/tags/v9.0.1') + .reply(200, body); + const res = await getDigest( + { + datasource, + packageName: 'gitea/helm-chart', + }, + 'v9.0.1' + ); + expect(res).toBe('29c9bbb4bfec04ab22761cc2d999eb0fcb8acbed'); + }); + }); +}); diff --git a/lib/modules/datasource/gitea-tags/index.ts b/lib/modules/datasource/gitea-tags/index.ts new file mode 100644 index 00000000000000..cea258201d634f --- /dev/null +++ b/lib/modules/datasource/gitea-tags/index.ts @@ -0,0 +1,136 @@ +import { cache } from '../../../util/cache/package/decorator'; +import { GiteaHttp } from '../../../util/http/gitea'; +import { regEx } from '../../../util/regex'; +import { ensureTrailingSlash } from '../../../util/url'; +import { Datasource } from '../datasource'; +import type { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types'; +import { CommitsSchema, TagSchema, TagsSchema } from './schema'; + +export class GiteaTagsDatasource extends Datasource { + override http = new GiteaHttp(GiteaTagsDatasource.id); + + static readonly id = 'gitea-tags'; + + static readonly customRegistrySupport = true; + + static readonly registryStrategy = 'first'; + + static readonly defaultRegistryUrls = ['https://gitea.com']; + + static readonly cacheNamespace = `datasource-${GiteaTagsDatasource.id}`; + + constructor() { + super(GiteaTagsDatasource.id); + } + + static getRegistryURL(registryUrl?: string): string { + // fallback to default API endpoint if custom not provided + return registryUrl ?? this.defaultRegistryUrls[0]; + } + + private static getApiUrl(registryUrl?: string): string { + const res = GiteaTagsDatasource.getRegistryURL(registryUrl).replace( + regEx(/\/api\/v1$/), + '' + ); + return `${ensureTrailingSlash(res)}api/v1/`; + } + + static getCacheKey( + registryUrl: string | undefined, + repo: string, + type: string + ): string { + return `${GiteaTagsDatasource.getRegistryURL(registryUrl)}:${repo}:${type}`; + } + + static getSourceUrl(packageName: string, registryUrl?: string): string { + const url = GiteaTagsDatasource.getRegistryURL(registryUrl); + const normalizedUrl = ensureTrailingSlash(url); + return `${normalizedUrl}${packageName}`; + } + + // getReleases fetches list of tags for the repository + @cache({ + namespace: GiteaTagsDatasource.cacheNamespace, + key: ({ registryUrl, packageName }: GetReleasesConfig) => + GiteaTagsDatasource.getCacheKey(registryUrl, packageName, 'tags'), + }) + async getReleases({ + registryUrl, + packageName: repo, + }: GetReleasesConfig): Promise { + const url = `${GiteaTagsDatasource.getApiUrl( + registryUrl + )}repos/${repo}/tags`; + const tags = ( + await this.http.getJson( + url, + { + paginate: true, + }, + TagsSchema + ) + ).body; + + const dependency: ReleaseResult = { + sourceUrl: GiteaTagsDatasource.getSourceUrl(repo, registryUrl), + registryUrl: GiteaTagsDatasource.getRegistryURL(registryUrl), + releases: tags.map(({ name, commit }) => ({ + version: name, + gitRef: name, + newDigest: commit.sha, + releaseTimestamp: commit.created, + })), + }; + + return dependency; + } + + // getTagCommit fetched the commit has for specified tag + @cache({ + namespace: GiteaTagsDatasource.cacheNamespace, + key: (registryUrl: string | undefined, repo: string, tag: string): string => + GiteaTagsDatasource.getCacheKey(registryUrl, repo, `tag-${tag}`), + }) + async getTagCommit( + registryUrl: string | undefined, + repo: string, + tag: string + ): Promise { + const url = `${GiteaTagsDatasource.getApiUrl( + registryUrl + )}repos/${repo}/tags/${tag}`; + + const { body } = await this.http.getJson(url, TagSchema); + + return body.commit.sha; + } + + // getDigest fetched the latest commit for repository main branch + // however, if newValue is provided, then getTagCommit is called + @cache({ + namespace: GiteaTagsDatasource.cacheNamespace, + key: ({ registryUrl, packageName }: DigestConfig) => + GiteaTagsDatasource.getCacheKey(registryUrl, packageName, 'digest'), + }) + override async getDigest( + { packageName: repo, registryUrl }: DigestConfig, + newValue?: string + ): Promise { + if (newValue?.length) { + return this.getTagCommit(registryUrl, repo, newValue); + } + + const url = `${GiteaTagsDatasource.getApiUrl( + registryUrl + )}repos/${repo}/commits?stat=false&verification=false&files=false&page=1&limit=1`; + const { body } = await this.http.getJson(url, CommitsSchema); + + if (body.length === 0) { + return null; + } + + return body[0].sha; + } +} diff --git a/lib/modules/datasource/gitea-tags/readme.md b/lib/modules/datasource/gitea-tags/readme.md new file mode 100644 index 00000000000000..8fe820ca3357a5 --- /dev/null +++ b/lib/modules/datasource/gitea-tags/readme.md @@ -0,0 +1,3 @@ +This datasource allows to lookup git tags from a [Gitea](https://about.gitea.com/) or [Forjeo](https://forgejo.org/) repositories. + +By default it will use `https://gitea.com` to lookup tags. diff --git a/lib/modules/datasource/gitea-tags/schema.ts b/lib/modules/datasource/gitea-tags/schema.ts new file mode 100644 index 00000000000000..603730de8f1dbf --- /dev/null +++ b/lib/modules/datasource/gitea-tags/schema.ts @@ -0,0 +1,18 @@ +import { z } from 'zod'; + +export const CommitSchema = z.object({ + sha: z.string(), +}); + +export const CommitsSchema = z.array(CommitSchema); + +const TagCommitSchema = z.object({ + sha: z.string(), + created: z.string().datetime({ offset: true }), +}); + +export const TagSchema = z.object({ + name: z.string(), + commit: TagCommitSchema, +}); +export const TagsSchema = z.array(TagSchema); diff --git a/lib/util/http/auth.ts b/lib/util/http/auth.ts index d2ba89b4919fba..ccdc74d5dfb4fe 100644 --- a/lib/util/http/auth.ts +++ b/lib/util/http/auth.ts @@ -1,6 +1,7 @@ import is from '@sindresorhus/is'; import type { Options } from 'got'; import { + GITEA_API_USING_HOST_TYPES, GITHUB_API_USING_HOST_TYPES, GITLAB_API_USING_HOST_TYPES, } from '../../constants'; @@ -28,7 +29,10 @@ export function applyAuthorization( options.headers ??= {}; if (options.token) { - if (options.hostType === 'gitea') { + if ( + options.hostType && + GITEA_API_USING_HOST_TYPES.includes(options.hostType) + ) { options.headers.authorization = `token ${options.token}`; } else if ( options.hostType && diff --git a/lib/util/http/gitea.ts b/lib/util/http/gitea.ts index 32e2ea27d7aed1..eb292e105663b7 100644 --- a/lib/util/http/gitea.ts +++ b/lib/util/http/gitea.ts @@ -35,8 +35,8 @@ function resolveUrl(path: string, base: string): URL { } export class GiteaHttp extends Http { - constructor(options?: HttpOptions) { - super('gitea', options); + constructor(hostType?: string, options?: HttpOptions) { + super(hostType ?? 'gitea', options); } protected override async request( diff --git a/lib/util/http/host-rules.spec.ts b/lib/util/http/host-rules.spec.ts index 8f86156e5c32d4..aeff4e65d11393 100644 --- a/lib/util/http/host-rules.spec.ts +++ b/lib/util/http/host-rules.spec.ts @@ -334,4 +334,30 @@ describe('util/http/host-rules', () => { token: 'cdef', }); }); + + it('no fallback to gitea', () => { + hostRules.add({ + hostType: 'gitea-tags', + token: 'abc', + }); + expect(applyHostRules(url, { ...options, hostType: 'gitea-tags' })).toEqual( + { + context: { + authType: undefined, + }, + hostType: 'gitea-tags', + token: 'abc', + } + ); + }); + + it('fallback to gitea', () => { + expect(applyHostRules(url, { ...options, hostType: 'gitea-tags' })).toEqual( + { + hostType: 'gitea-tags', + password: 'password', + username: undefined, + } + ); + }); }); diff --git a/lib/util/http/host-rules.ts b/lib/util/http/host-rules.ts index b112988f8858af..bf88e5e888cccc 100644 --- a/lib/util/http/host-rules.ts +++ b/lib/util/http/host-rules.ts @@ -1,6 +1,7 @@ import is from '@sindresorhus/is'; import { BITBUCKET_API_USING_HOST_TYPES, + GITEA_API_USING_HOST_TYPES, GITHUB_API_USING_HOST_TYPES, GITLAB_API_USING_HOST_TYPES, } from '../../constants'; @@ -92,6 +93,21 @@ export function findMatchingRules( }; } + // Fallback to `gitea` hostType + if ( + hostType && + GITEA_API_USING_HOST_TYPES.includes(hostType) && + hostType !== 'gitea' + ) { + res = { + ...hostRules.find({ + hostType: 'gitea', + url, + }), + ...res, + }; + } + return res; }