renovate/lib/util/common.ts
Hilário Coelho 8cc08e0660
fix(azure): go-import meta header support for Azure DevOps (#22664)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2023-06-11 16:58:46 +00:00

42 lines
1 KiB
TypeScript

import {
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
): 'gitlab' | 'github' | 'azure' | 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';
}
const hostType = hostRules.hostType({ url });
if (!hostType) {
return null;
}
if (GITLAB_API_USING_HOST_TYPES.includes(hostType)) {
return 'gitlab';
}
if (GITHUB_API_USING_HOST_TYPES.includes(hostType)) {
return 'github';
}
return null;
}