diff --git a/lib/util/common.spec.ts b/lib/util/common.spec.ts index b74ba87226564899d7fb9dc8d26b0d95e0498584..4ed8919ea95cc1211a3513815e0b6a4e4bddce73 100644 --- a/lib/util/common.spec.ts +++ b/lib/util/common.spec.ts @@ -9,43 +9,44 @@ describe('util/common', () => { url | hostType ${'some-invalid@url:::'} | ${null} ${'https://enterprise.example.com/chalk/chalk'} | ${null} - ${'https://github.com/semantic-release/gitlab'} | ${'github'} - ${'https://github-enterprise.example.com/chalk/chalk'} | ${'github'} - ${'https://gitlab.com/chalk/chalk'} | ${'gitlab'} - ${'https://gitlab-enterprise.example.com/chalk/chalk'} | ${'gitlab'} ${'https://dev.azure.com/my-organization/my-project/_git/my-repo.git'} | ${'azure'} ${'https://myorg.visualstudio.com/my-project/_git/my-repo.git'} | ${'azure'} ${'https://bitbucket.org/some-org/some-repo'} | ${'bitbucket'} ${'https://bitbucket.com/some-org/some-repo'} | ${'bitbucket'} + ${'https://github.com/semantic-release/gitlab'} | ${'github'} + ${'https://github-enterprise.example.com/chalk/chalk'} | ${'github'} + ${'https://gitlab.com/chalk/chalk'} | ${'gitlab'} + ${'https://gitlab-enterprise.example.com/chalk/chalk'} | ${'gitlab'} `('("$url") === $hostType', ({ url, hostType }) => { expect(detectPlatform(url)).toBe(hostType); }); it('uses host rules', () => { hostRules.add({ - hostType: 'gitlab-changelog', - matchHost: 'gl.example.com', - }); - hostRules.add({ - hostType: 'github-changelog', - matchHost: 'gh.example.com', + hostType: 'bitbucket', + matchHost: 'bb.example.com', }); hostRules.add({ hostType: 'gitea', matchHost: 'gt.example.com', }); hostRules.add({ - hostType: 'bitbucket', - matchHost: 'bb.example.com', + hostType: 'github-changelog', + matchHost: 'gh.example.com', }); - expect(detectPlatform('https://gl.example.com/chalk/chalk')).toBe( - 'gitlab' + hostRules.add({ + hostType: 'gitlab-changelog', + matchHost: 'gl.example.com', + }); + + expect(detectPlatform('https://bb.example.com/chalk/chalk')).toBe( + 'bitbucket' ); expect(detectPlatform('https://gh.example.com/chalk/chalk')).toBe( 'github' ); - expect(detectPlatform('https://bb.example.com/chalk/chalk')).toBe( - 'bitbucket' + expect(detectPlatform('https://gl.example.com/chalk/chalk')).toBe( + 'gitlab' ); expect(detectPlatform('https://gt.example.com/chalk/chalk')).toBeNull(); }); diff --git a/lib/util/common.ts b/lib/util/common.ts index 381f850c461b3c98cc28f0fa671f63e7a5950d91..7693906d657ad27fa55619ed3ffb0551cce42884 100644 --- a/lib/util/common.ts +++ b/lib/util/common.ts @@ -14,20 +14,20 @@ import { parseUrl } from './url'; */ export function detectPlatform( url: string -): 'gitlab' | 'github' | 'azure' | 'bitbucket' | null { +): 'azure' | 'bitbucket' | 'github' | 'gitlab' | null { const { hostname } = parseUrl(url) ?? {}; - if (hostname === 'github.com' || hostname?.includes('github')) { - return 'github'; - } - if (hostname === 'gitlab.com' || hostname?.includes('gitlab')) { - return 'gitlab'; - } if (hostname === 'dev.azure.com' || hostname?.endsWith('.visualstudio.com')) { return 'azure'; } if (hostname === 'bitbucket.org' || hostname?.includes('bitbucket')) { return 'bitbucket'; } + if (hostname === 'github.com' || hostname?.includes('github')) { + return 'github'; + } + if (hostname === 'gitlab.com' || hostname?.includes('gitlab')) { + return 'gitlab'; + } const hostType = hostRules.hostType({ url }); @@ -38,12 +38,12 @@ export function detectPlatform( if (BITBUCKET_API_USING_HOST_TYPES.includes(hostType)) { return 'bitbucket'; } - if (GITLAB_API_USING_HOST_TYPES.includes(hostType)) { - return 'gitlab'; - } if (GITHUB_API_USING_HOST_TYPES.includes(hostType)) { return 'github'; } + if (GITLAB_API_USING_HOST_TYPES.includes(hostType)) { + return 'gitlab'; + } return null; }