diff --git a/lib/datasource/helm/common.spec.ts b/lib/datasource/helm/common.spec.ts index a9b3058a08b4cbb8fcb2d03714c8fe8bedb29faa..e2f1f32dbfd3910212c54e129ed555c68186dcc8 100644 --- a/lib/datasource/helm/common.spec.ts +++ b/lib/datasource/helm/common.spec.ts @@ -12,9 +12,9 @@ describe('datasource/helm/common', () => { describe('findSourceUrl', () => { test.each` input | output - ${'airflow'} | ${'https://github.com/bitnami/charts'} - ${'coredns'} | ${'https://github.com/coredns/helm'} - ${'pgadmin4'} | ${'https://github.com/rowanruseler/helm-charts'} + ${'airflow'} | ${{ sourceUrl: 'https://github.com/bitnami/charts', sourceDirectory: 'bitnami/airflow' }} + ${'coredns'} | ${{ sourceUrl: 'https://github.com/coredns/helm', sourceDirectory: undefined }} + ${'pgadmin4'} | ${{ sourceUrl: 'https://github.com/rowanruseler/helm-charts', sourceDirectory: undefined }} ${'dummy'} | ${undefined} `( '$input -> $output', diff --git a/lib/datasource/helm/common.ts b/lib/datasource/helm/common.ts index e6aef34e931e430cef433b71a0964efab80eac5c..26cb20d308aefbc39c6f6212e0efa8f3448b78f8 100644 --- a/lib/datasource/helm/common.ts +++ b/lib/datasource/helm/common.ts @@ -1,24 +1,24 @@ 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 githubUrl = regEx( - /^(?<url>https:\/\/github\.com\/[^/]+\/(?<repo>[^/]+))(?:\/|$)/ + /^(?<url>https:\/\/github\.com\/[^/]+\/(?<repo>[^/]+))(:?\/|\/tree\/[^/]+\/(?<path>.+))?$/ ); const githubRelease = regEx( /^(https:\/\/github\.com\/[^/]+\/[^/]+)\/releases\// ); -export function findSourceUrl(release: HelmRelease): string { +export function findSourceUrl(release: HelmRelease): RepoSource { // it's a github release :) let match = githubRelease.exec(release.urls[0]); if (match) { - return match[1]; + return { sourceUrl: match[1] }; } match = githubUrl.exec(release.home); if (chartRepo.test(match?.groups.repo)) { - return match.groups.url; + return { sourceUrl: match.groups.url, sourceDirectory: match.groups.path }; } if (!release.sources?.length) { @@ -28,10 +28,13 @@ export function findSourceUrl(release: HelmRelease): string { for (const url of release.sources) { match = githubUrl.exec(url); if (chartRepo.test(match?.groups.repo)) { - return match.groups.url; + return { + sourceUrl: match.groups.url, + sourceDirectory: match.groups.path, + }; } } // fallback - return release.sources[0]; + return { sourceUrl: release.sources[0] }; } diff --git a/lib/datasource/helm/index.ts b/lib/datasource/helm/index.ts index 4b18435817fa3499fde63b7f4a6f2764a88d5633..83dd7667df0e3e70c47b944aba24d07af29a04ef 100644 --- a/lib/datasource/helm/index.ts +++ b/lib/datasource/helm/index.ts @@ -54,9 +54,11 @@ export class HelmDatasource extends Datasource { } const result: RepositoryData = {}; for (const [name, releases] of Object.entries(doc.entries)) { + const { sourceUrl, sourceDirectory } = findSourceUrl(releases[0]); result[name] = { homepage: releases[0].home, - sourceUrl: findSourceUrl(releases[0]), + sourceUrl, + sourceDirectory, releases: releases.map((release) => ({ version: release.version, releaseTimestamp: release.created ?? null, diff --git a/lib/datasource/helm/types.ts b/lib/datasource/helm/types.ts index fe482f27dbf185ca50d16669a5b67016332e93d1..ccfc418c139dde7e24b43bd8c85e2b237c3a14e7 100644 --- a/lib/datasource/helm/types.ts +++ b/lib/datasource/helm/types.ts @@ -13,3 +13,8 @@ export interface HelmRepository { } export type RepositoryData = Record<string, ReleaseResult>; + +export interface RepoSource { + sourceUrl?: string; + sourceDirectory?: string; +}