diff --git a/lib/constants/platform.spec.ts b/lib/constants/platform.spec.ts index c02a997356c320..3fe0b31b33d85a 100644 --- a/lib/constants/platform.spec.ts +++ b/lib/constants/platform.spec.ts @@ -1,3 +1,4 @@ +import { BitBucketTagsDatasource } from '../datasource/bitbucket-tags'; import { id as GH_RELEASES_DS } from '../datasource/github-releases'; import { id as GH_TAGS_DS } from '../datasource/github-tags'; import { GitlabPackagesDatasource } from '../datasource/gitlab-packages'; @@ -5,6 +6,7 @@ import { GitlabReleasesDatasource } from '../datasource/gitlab-releases'; import { id as GL_TAGS_DS } from '../datasource/gitlab-tags'; import { id as POD_DS } from '../datasource/pod'; import { + BITBUCKET_API_USING_HOST_TYPES, GITHUB_API_USING_HOST_TYPES, GITLAB_API_USING_HOST_TYPES, PlatformId, @@ -36,4 +38,13 @@ describe('constants/platform', () => { it('should be not part of the GITHUB_API_USING_HOST_TYPES ', () => { expect(GITHUB_API_USING_HOST_TYPES.includes(PlatformId.Gitlab)).toBeFalse(); }); + + it('should be part of the BITBUCKET_API_USING_HOST_TYPES ', () => { + expect( + BITBUCKET_API_USING_HOST_TYPES.includes(BitBucketTagsDatasource.id) + ).toBeTrue(); + expect( + BITBUCKET_API_USING_HOST_TYPES.includes(PlatformId.Bitbucket) + ).toBeTrue(); + }); }); diff --git a/lib/constants/platforms.ts b/lib/constants/platforms.ts index 83ce1e763c20ab..a203234a3c2f1d 100644 --- a/lib/constants/platforms.ts +++ b/lib/constants/platforms.ts @@ -20,3 +20,8 @@ export const GITLAB_API_USING_HOST_TYPES = [ 'gitlab-tags', 'gitlab-packages', ]; + +export const BITBUCKET_API_USING_HOST_TYPES = [ + PlatformId.Bitbucket, + 'bitbucket-tags', +]; diff --git a/lib/datasource/bitbucket-tags/index.ts b/lib/datasource/bitbucket-tags/index.ts index 53fe34d340eb2c..074e5bf3474ce0 100644 --- a/lib/datasource/bitbucket-tags/index.ts +++ b/lib/datasource/bitbucket-tags/index.ts @@ -7,7 +7,7 @@ import type { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types'; import { BitbucketCommit, BitbucketTag } from './types'; export class BitBucketTagsDatasource extends Datasource { - bitbucketHttp = new BitbucketHttp(); + bitbucketHttp = new BitbucketHttp(BitBucketTagsDatasource.id); static readonly id = 'bitbucket-tags'; diff --git a/lib/util/http/bitbucket.ts b/lib/util/http/bitbucket.ts index 1445d0e84723fb..575b70c87f607e 100644 --- a/lib/util/http/bitbucket.ts +++ b/lib/util/http/bitbucket.ts @@ -8,8 +8,8 @@ export const setBaseUrl = (url: string): void => { }; export class BitbucketHttp extends Http { - constructor(options?: HttpOptions) { - super(PlatformId.Bitbucket, options); + constructor(type: string = PlatformId.Bitbucket, options?: HttpOptions) { + super(type, options); } protected override request( diff --git a/lib/util/http/host-rules.spec.ts b/lib/util/http/host-rules.spec.ts index cad61c7a493961..fa33fa9df0a01d 100644 --- a/lib/util/http/host-rules.spec.ts +++ b/lib/util/http/host-rules.spec.ts @@ -44,6 +44,11 @@ describe('util/http/host-rules', () => { username: 'some', password: 'xxx', }); + + hostRules.add({ + hostType: PlatformId.Bitbucket, + token: 'cdef', + }); }); afterEach(() => { @@ -224,4 +229,31 @@ describe('util/http/host-rules', () => { token: 'abc', }); }); + + it('no fallback to bitbucket', () => { + hostRules.add({ + hostType: 'bitbucket-tags', + username: 'some', + password: 'xxx', + }); + expect( + applyHostRules(url, { ...options, hostType: 'bitbucket-tags' }) + ).toEqual({ + hostType: 'bitbucket-tags', + username: 'some', + password: 'xxx', + }); + }); + + it('fallback to bitbucket', () => { + expect( + applyHostRules(url, { ...options, hostType: 'bitbucket-tags' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'bitbucket-tags', + token: 'cdef', + }); + }); }); diff --git a/lib/util/http/host-rules.ts b/lib/util/http/host-rules.ts index 3c786d17093789..92d23a7df83ec7 100644 --- a/lib/util/http/host-rules.ts +++ b/lib/util/http/host-rules.ts @@ -1,4 +1,5 @@ import { + BITBUCKET_API_USING_HOST_TYPES, GITHUB_API_USING_HOST_TYPES, GITLAB_API_USING_HOST_TYPES, PlatformId, @@ -48,6 +49,21 @@ function findMatchingRules(options: GotOptions, url: string): HostRule { }; } + // Fallback to `bitbucket` hostType + if ( + hostType && + BITBUCKET_API_USING_HOST_TYPES.includes(hostType) && + hostType !== PlatformId.Bitbucket + ) { + res = { + ...hostRules.find({ + hostType: PlatformId.Bitbucket, + url, + }), + ...res, + }; + } + return res; }