Skip to content
Snippets Groups Projects
Unverified Commit fa71763a authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

refactor(gitlab): Extract getSourceUrl function (#12511)

parent 3cd70f8c
No related branches found
Tags 12.31.0
No related merge requests found
import * as packageCache from '../../util/cache/package'; import * as packageCache from '../../util/cache/package';
import { GitlabHttp } from '../../util/http/gitlab'; import { GitlabHttp } from '../../util/http/gitlab';
import { regEx } from '../../util/regex';
import { joinUrlParts } from '../../util/url'; import { joinUrlParts } from '../../util/url';
import type { GetReleasesConfig, ReleaseResult } from '../types'; import type { GetReleasesConfig, ReleaseResult } from '../types';
import type { GitlabTag } from './types'; import type { GitlabTag } from './types';
import { defaultRegistryUrl, getDepHost, getSourceUrl } from './util';
export const id = 'gitlab-tags'; export const id = 'gitlab-tags';
const gitlabApi = new GitlabHttp(id); const gitlabApi = new GitlabHttp(id);
export const customRegistrySupport = true; export const customRegistrySupport = true;
export const defaultRegistryUrls = ['https://gitlab.com']; export const defaultRegistryUrls = [defaultRegistryUrl];
export const registryStrategy = 'first'; export const registryStrategy = 'first';
const cacheNamespace = 'datasource-gitlab'; const cacheNamespace = 'datasource-gitlab';
...@@ -23,7 +23,7 @@ export async function getReleases({ ...@@ -23,7 +23,7 @@ export async function getReleases({
registryUrl, registryUrl,
lookupName: repo, lookupName: repo,
}: GetReleasesConfig): Promise<ReleaseResult | null> { }: GetReleasesConfig): Promise<ReleaseResult | null> {
const depHost = registryUrl.replace(regEx(/\/api\/v4$/), ''); const depHost = getDepHost(registryUrl);
const cachedResult = await packageCache.get<ReleaseResult>( const cachedResult = await packageCache.get<ReleaseResult>(
cacheNamespace, cacheNamespace,
...@@ -51,7 +51,7 @@ export async function getReleases({ ...@@ -51,7 +51,7 @@ export async function getReleases({
).body; ).body;
const dependency: ReleaseResult = { const dependency: ReleaseResult = {
sourceUrl: joinUrlParts(depHost, repo), sourceUrl: getSourceUrl(repo, registryUrl),
releases: null, releases: null,
}; };
dependency.releases = gitlabTags.map(({ name, commit }) => ({ dependency.releases = gitlabTags.map(({ name, commit }) => ({
......
import { regEx } from '../../util/regex';
import { joinUrlParts } from '../../util/url';
export const defaultRegistryUrl = 'https://gitlab.com';
export function getDepHost(registryUrl: string = defaultRegistryUrl): string {
return registryUrl.replace(regEx(/\/api\/v4$/), '');
}
export function getSourceUrl(lookupName: string, registryUrl?: string): string {
const depHost = getDepHost(registryUrl);
return joinUrlParts(depHost, lookupName);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment