Skip to content

Commit

Permalink
refactor: reorder platforms alphabetically (#23077)
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy authored Jul 1, 2023
1 parent db91079 commit 21f984f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
33 changes: 17 additions & 16 deletions lib/util/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
20 changes: 10 additions & 10 deletions lib/util/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand All @@ -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;
}

0 comments on commit 21f984f

Please sign in to comment.