feat(datasource/helm): handle github source directoy (#13058)

This commit is contained in:
Michael Kriese 2021-12-14 06:45:26 +01:00 committed by GitHub
parent 579059cc52
commit b81e380c62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 11 deletions

View file

@ -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',

View file

@ -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] };
}

View file

@ -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,

View file

@ -13,3 +13,8 @@ export interface HelmRepository {
}
export type RepositoryData = Record<string, ReleaseResult>;
export interface RepoSource {
sourceUrl?: string;
sourceDirectory?: string;
}