mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-02 18:43:40 +00:00
fb9303c190
Co-authored-by: Rhys Arkins <rhys@arkins.net>
38 lines
931 B
TypeScript
38 lines
931 B
TypeScript
import {
|
|
GITHUB_API_USING_HOST_TYPES,
|
|
GITLAB_API_USING_HOST_TYPES,
|
|
} from '../../constants';
|
|
import * as hostRules from '../../util/host-rules';
|
|
import { parseUrl } from '../../util/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' | null {
|
|
const { hostname } = parseUrl(url) ?? {};
|
|
if (hostname === 'github.com' || hostname?.includes('github')) {
|
|
return 'github';
|
|
}
|
|
if (hostname === 'gitlab.com' || hostname?.includes('gitlab')) {
|
|
return 'gitlab';
|
|
}
|
|
|
|
const hostType = hostRules.hostType({ url: 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;
|
|
}
|