mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
feat(datasource/helm): handle github source directoy (#13058)
This commit is contained in:
parent
579059cc52
commit
b81e380c62
4 changed files with 21 additions and 11 deletions
|
@ -12,9 +12,9 @@ describe('datasource/helm/common', () => {
|
||||||
describe('findSourceUrl', () => {
|
describe('findSourceUrl', () => {
|
||||||
test.each`
|
test.each`
|
||||||
input | output
|
input | output
|
||||||
${'airflow'} | ${'https://github.com/bitnami/charts'}
|
${'airflow'} | ${{ sourceUrl: 'https://github.com/bitnami/charts', sourceDirectory: 'bitnami/airflow' }}
|
||||||
${'coredns'} | ${'https://github.com/coredns/helm'}
|
${'coredns'} | ${{ sourceUrl: 'https://github.com/coredns/helm', sourceDirectory: undefined }}
|
||||||
${'pgadmin4'} | ${'https://github.com/rowanruseler/helm-charts'}
|
${'pgadmin4'} | ${{ sourceUrl: 'https://github.com/rowanruseler/helm-charts', sourceDirectory: undefined }}
|
||||||
${'dummy'} | ${undefined}
|
${'dummy'} | ${undefined}
|
||||||
`(
|
`(
|
||||||
'$input -> $output',
|
'$input -> $output',
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
import { regEx } from '../../util/regex';
|
import { regEx } from '../../util/regex';
|
||||||
import type { HelmRelease } from './types';
|
import type { HelmRelease, RepoSource } from './types';
|
||||||
|
|
||||||
const chartRepo = regEx(/charts?|helm|helm-charts/i);
|
const chartRepo = regEx(/charts?|helm|helm-charts/i);
|
||||||
const githubUrl = regEx(
|
const githubUrl = regEx(
|
||||||
/^(?<url>https:\/\/github\.com\/[^/]+\/(?<repo>[^/]+))(?:\/|$)/
|
/^(?<url>https:\/\/github\.com\/[^/]+\/(?<repo>[^/]+))(:?\/|\/tree\/[^/]+\/(?<path>.+))?$/
|
||||||
);
|
);
|
||||||
const githubRelease = regEx(
|
const githubRelease = regEx(
|
||||||
/^(https:\/\/github\.com\/[^/]+\/[^/]+)\/releases\//
|
/^(https:\/\/github\.com\/[^/]+\/[^/]+)\/releases\//
|
||||||
);
|
);
|
||||||
|
|
||||||
export function findSourceUrl(release: HelmRelease): string {
|
export function findSourceUrl(release: HelmRelease): RepoSource {
|
||||||
// it's a github release :)
|
// it's a github release :)
|
||||||
let match = githubRelease.exec(release.urls[0]);
|
let match = githubRelease.exec(release.urls[0]);
|
||||||
if (match) {
|
if (match) {
|
||||||
return match[1];
|
return { sourceUrl: match[1] };
|
||||||
}
|
}
|
||||||
|
|
||||||
match = githubUrl.exec(release.home);
|
match = githubUrl.exec(release.home);
|
||||||
if (chartRepo.test(match?.groups.repo)) {
|
if (chartRepo.test(match?.groups.repo)) {
|
||||||
return match.groups.url;
|
return { sourceUrl: match.groups.url, sourceDirectory: match.groups.path };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!release.sources?.length) {
|
if (!release.sources?.length) {
|
||||||
|
@ -28,10 +28,13 @@ export function findSourceUrl(release: HelmRelease): string {
|
||||||
for (const url of release.sources) {
|
for (const url of release.sources) {
|
||||||
match = githubUrl.exec(url);
|
match = githubUrl.exec(url);
|
||||||
if (chartRepo.test(match?.groups.repo)) {
|
if (chartRepo.test(match?.groups.repo)) {
|
||||||
return match.groups.url;
|
return {
|
||||||
|
sourceUrl: match.groups.url,
|
||||||
|
sourceDirectory: match.groups.path,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback
|
// fallback
|
||||||
return release.sources[0];
|
return { sourceUrl: release.sources[0] };
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,11 @@ export class HelmDatasource extends Datasource {
|
||||||
}
|
}
|
||||||
const result: RepositoryData = {};
|
const result: RepositoryData = {};
|
||||||
for (const [name, releases] of Object.entries(doc.entries)) {
|
for (const [name, releases] of Object.entries(doc.entries)) {
|
||||||
|
const { sourceUrl, sourceDirectory } = findSourceUrl(releases[0]);
|
||||||
result[name] = {
|
result[name] = {
|
||||||
homepage: releases[0].home,
|
homepage: releases[0].home,
|
||||||
sourceUrl: findSourceUrl(releases[0]),
|
sourceUrl,
|
||||||
|
sourceDirectory,
|
||||||
releases: releases.map((release) => ({
|
releases: releases.map((release) => ({
|
||||||
version: release.version,
|
version: release.version,
|
||||||
releaseTimestamp: release.created ?? null,
|
releaseTimestamp: release.created ?? null,
|
||||||
|
|
|
@ -13,3 +13,8 @@ export interface HelmRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RepositoryData = Record<string, ReleaseResult>;
|
export type RepositoryData = Record<string, ReleaseResult>;
|
||||||
|
|
||||||
|
export interface RepoSource {
|
||||||
|
sourceUrl?: string;
|
||||||
|
sourceDirectory?: string;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue