Skip to content

Commit

Permalink
fix(bitbucket-tags): Add hostType and fallback for bitbucket-tags dat…
Browse files Browse the repository at this point in the history
…asource (#13697)
  • Loading branch information
rv2673 committed Jan 20, 2022
1 parent c378317 commit 599958a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
11 changes: 11 additions & 0 deletions lib/constants/platform.spec.ts
@@ -1,10 +1,12 @@
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';
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,
Expand Down Expand Up @@ -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();
});
});
5 changes: 5 additions & 0 deletions lib/constants/platforms.ts
Expand Up @@ -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',
];
2 changes: 1 addition & 1 deletion lib/datasource/bitbucket-tags/index.ts
Expand Up @@ -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';

Expand Down
4 changes: 2 additions & 2 deletions lib/util/http/bitbucket.ts
Expand Up @@ -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<T>(
Expand Down
32 changes: 32 additions & 0 deletions lib/util/http/host-rules.spec.ts
Expand Up @@ -44,6 +44,11 @@ describe('util/http/host-rules', () => {
username: 'some',
password: 'xxx',
});

hostRules.add({
hostType: PlatformId.Bitbucket,
token: 'cdef',
});
});

afterEach(() => {
Expand Down Expand Up @@ -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',
});
});
});
16 changes: 16 additions & 0 deletions 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,
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 599958a

Please sign in to comment.