mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-08 13:12:59 +00:00
d3da0bcef0
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import {
|
|
BITBUCKET_API_USING_HOST_TYPES,
|
|
GITEA_API_USING_HOST_TYPES,
|
|
GITHUB_API_USING_HOST_TYPES,
|
|
GITLAB_API_USING_HOST_TYPES,
|
|
} from '../constants';
|
|
import * as hostRules from './host-rules';
|
|
import { parseUrl } from './url';
|
|
|
|
/**
|
|
* Tries to detect the `platform` from a url.
|
|
*
|
|
* @param url the url to detect `platform` from
|
|
* @returns matched `platform` if found, otherwise `null`
|
|
*/
|
|
export function detectPlatform(
|
|
url: string
|
|
): 'azure' | 'bitbucket' | 'gitea' | 'github' | 'gitlab' | null {
|
|
const { hostname } = parseUrl(url) ?? {};
|
|
if (hostname === 'dev.azure.com' || hostname?.endsWith('.visualstudio.com')) {
|
|
return 'azure';
|
|
}
|
|
if (hostname === 'bitbucket.org' || hostname?.includes('bitbucket')) {
|
|
return 'bitbucket';
|
|
}
|
|
if (
|
|
hostname &&
|
|
(['gitea.com', 'codeberg.org'].includes(hostname) ||
|
|
hostname.includes('gitea') ||
|
|
hostname.includes('forgejo'))
|
|
) {
|
|
return 'gitea';
|
|
}
|
|
if (hostname === 'github.com' || hostname?.includes('github')) {
|
|
return 'github';
|
|
}
|
|
if (hostname === 'gitlab.com' || hostname?.includes('gitlab')) {
|
|
return 'gitlab';
|
|
}
|
|
|
|
const hostType = hostRules.hostType({ url });
|
|
|
|
if (!hostType) {
|
|
return null;
|
|
}
|
|
|
|
if (BITBUCKET_API_USING_HOST_TYPES.includes(hostType)) {
|
|
return 'bitbucket';
|
|
}
|
|
if (GITEA_API_USING_HOST_TYPES.includes(hostType)) {
|
|
return 'gitea';
|
|
}
|
|
if (GITHUB_API_USING_HOST_TYPES.includes(hostType)) {
|
|
return 'github';
|
|
}
|
|
if (GITLAB_API_USING_HOST_TYPES.includes(hostType)) {
|
|
return 'gitlab';
|
|
}
|
|
|
|
return null;
|
|
}
|