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', () => {
|
||||
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',
|
||||
|
|
|
@ -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] };
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -13,3 +13,8 @@ export interface HelmRepository {
|
|||
}
|
||||
|
||||
export type RepositoryData = Record<string, ReleaseResult>;
|
||||
|
||||
export interface RepoSource {
|
||||
sourceUrl?: string;
|
||||
sourceDirectory?: string;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue