From b81e380c62caccc82868eebe200cd785806de20b Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Tue, 14 Dec 2021 06:45:26 +0100 Subject: [PATCH] feat(datasource/helm): handle github source directoy (#13058) --- lib/datasource/helm/common.spec.ts | 6 +++--- lib/datasource/helm/common.ts | 17 ++++++++++------- lib/datasource/helm/index.ts | 4 +++- lib/datasource/helm/types.ts | 5 +++++ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/datasource/helm/common.spec.ts b/lib/datasource/helm/common.spec.ts index a9b3058a08..e2f1f32dbf 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 e6aef34e93..26cb20d308 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( - /^(?https:\/\/github\.com\/[^/]+\/(?[^/]+))(?:\/|$)/ + /^(?https:\/\/github\.com\/[^/]+\/(?[^/]+))(:?\/|\/tree\/[^/]+\/(?.+))?$/ ); 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 4b18435817..83dd7667df 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 fe482f27db..ccfc418c13 100644 --- a/lib/datasource/helm/types.ts +++ b/lib/datasource/helm/types.ts @@ -13,3 +13,8 @@ export interface HelmRepository { } export type RepositoryData = Record; + +export interface RepoSource { + sourceUrl?: string; + sourceDirectory?: string; +}