mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 15:06:27 +00:00
refactor(go): Simplify .git
suffix handling for GitLab EE (#30336)
This commit is contained in:
parent
0af6470c70
commit
5f0a23510d
1 changed files with 21 additions and 44 deletions
|
@ -141,13 +141,13 @@ export class BaseGoDatasource {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static detectDatasource(
|
private static detectDatasource(
|
||||||
goSourceUrl: string,
|
metadataUrl: string,
|
||||||
goModule: string,
|
goModule: string,
|
||||||
): DataSource | null {
|
): DataSource | null {
|
||||||
if (goSourceUrl.startsWith('https://github.com/')) {
|
if (metadataUrl.startsWith('https://github.com/')) {
|
||||||
return {
|
return {
|
||||||
datasource: GithubTagsDatasource.id,
|
datasource: GithubTagsDatasource.id,
|
||||||
packageName: goSourceUrl
|
packageName: metadataUrl
|
||||||
.replace('https://github.com/', '')
|
.replace('https://github.com/', '')
|
||||||
.replace(regEx(/\/$/), ''),
|
.replace(regEx(/\/$/), ''),
|
||||||
registryUrl: 'https://github.com',
|
registryUrl: 'https://github.com',
|
||||||
|
@ -155,27 +155,22 @@ export class BaseGoDatasource {
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitlabUrl =
|
const gitlabUrl =
|
||||||
BaseGoDatasource.gitlabHttpsRegExp.exec(goSourceUrl)?.groups
|
BaseGoDatasource.gitlabHttpsRegExp.exec(metadataUrl)?.groups
|
||||||
?.httpsRegExpUrl;
|
?.httpsRegExpUrl;
|
||||||
const gitlabUrlName =
|
const gitlabUrlName =
|
||||||
BaseGoDatasource.gitlabHttpsRegExp.exec(goSourceUrl)?.groups
|
BaseGoDatasource.gitlabHttpsRegExp.exec(metadataUrl)?.groups
|
||||||
?.httpsRegExpName;
|
?.httpsRegExpName;
|
||||||
const gitlabModuleName =
|
const gitlabModuleName =
|
||||||
BaseGoDatasource.gitlabRegExp.exec(goModule)?.groups?.regExpPath;
|
BaseGoDatasource.gitlabRegExp.exec(goModule)?.groups?.regExpPath;
|
||||||
|
const vcsIndicatedModule =
|
||||||
|
BaseGoDatasource.gitVcsRegexp.exec(goModule)?.groups?.module;
|
||||||
if (gitlabUrl && gitlabUrlName) {
|
if (gitlabUrl && gitlabUrlName) {
|
||||||
if (gitlabModuleName?.startsWith(gitlabUrlName)) {
|
if (gitlabModuleName?.startsWith(gitlabUrlName)) {
|
||||||
const vcsIndicatedModule = BaseGoDatasource.gitVcsRegexp.exec(goModule);
|
const packageName = vcsIndicatedModule ?? gitlabModuleName;
|
||||||
if (vcsIndicatedModule?.groups?.module) {
|
|
||||||
return {
|
|
||||||
datasource: GitlabTagsDatasource.id,
|
|
||||||
registryUrl: gitlabUrl,
|
|
||||||
packageName: vcsIndicatedModule.groups?.module,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
datasource: GitlabTagsDatasource.id,
|
datasource: GitlabTagsDatasource.id,
|
||||||
registryUrl: gitlabUrl,
|
registryUrl: gitlabUrl,
|
||||||
packageName: gitlabModuleName,
|
packageName,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,47 +181,29 @@ export class BaseGoDatasource {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostRules.hostType({ url: goSourceUrl }) === 'gitlab') {
|
if (hostRules.hostType({ url: metadataUrl }) === 'gitlab') {
|
||||||
const parsedUrl = parseUrl(goSourceUrl);
|
const parsedUrl = parseUrl(metadataUrl);
|
||||||
if (!parsedUrl) {
|
if (!parsedUrl) {
|
||||||
logger.trace({ goModule }, 'Could not parse go-source URL');
|
logger.trace({ goModule }, 'Could not parse go-source URL');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let packageName = trimLeadingSlash(`${parsedUrl.pathname}`);
|
const endpoint = GlobalConfig.get('endpoint', '');
|
||||||
|
const endpointPrefix = regEx(
|
||||||
|
/https:\/\/[^/]+\/(?<prefix>.*?\/)(?:api\/v4\/?)?/,
|
||||||
|
).exec(endpoint)?.groups?.prefix;
|
||||||
|
|
||||||
const endpoint = GlobalConfig.get('endpoint')!;
|
let packageName =
|
||||||
|
// a .git path indicates a concrete git repository, which can be different from metadata returned by gitlab
|
||||||
const endpointPrefix = regEx('https://[^/]*/(.*?/)(api/v4/?)?').exec(
|
vcsIndicatedModule ?? trimLeadingSlash(parsedUrl.pathname);
|
||||||
endpoint,
|
if (endpointPrefix && endpointPrefix !== 'api/') {
|
||||||
);
|
packageName = packageName.replace(endpointPrefix, '');
|
||||||
|
|
||||||
if (endpointPrefix && endpointPrefix[1] !== 'api/') {
|
|
||||||
packageName = packageName.replace(endpointPrefix[1], '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const registryUrl = endpointPrefix
|
const registryUrl = endpointPrefix
|
||||||
? endpoint.replace(regEx('api/v4/?$'), '')
|
? endpoint.replace(regEx(/\/api\/v4\/?$/), '/')
|
||||||
: `${parsedUrl.protocol}//${parsedUrl.host}`;
|
: `${parsedUrl.protocol}//${parsedUrl.host}`;
|
||||||
|
|
||||||
// a .git path indicates a concrete git repository, which can be different from metadata returned by gitlab
|
|
||||||
const vcsIndicatedModule = BaseGoDatasource.gitVcsRegexp.exec(goModule);
|
|
||||||
if (vcsIndicatedModule?.groups?.module) {
|
|
||||||
if (endpointPrefix) {
|
|
||||||
packageName = vcsIndicatedModule.groups?.module.replace(
|
|
||||||
endpointPrefix[1],
|
|
||||||
'',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
packageName = vcsIndicatedModule.groups?.module;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
datasource: GitlabTagsDatasource.id,
|
|
||||||
registryUrl,
|
|
||||||
packageName,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
datasource: GitlabTagsDatasource.id,
|
datasource: GitlabTagsDatasource.id,
|
||||||
registryUrl,
|
registryUrl,
|
||||||
|
|
Loading…
Reference in a new issue