-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathindex.ts
72 lines (61 loc) · 2.16 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { logger } from '../../../logger';
import { cache } from '../../../util/cache/package/decorator';
import { ensureTrailingSlash } from '../../../util/url';
import * as helmVersioning from '../../versioning/helm';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import type { HelmRepositoryData } from './schema';
import { HelmRepositorySchema } from './schema';
export class HelmDatasource extends Datasource {
static readonly id = 'helm';
constructor() {
super(HelmDatasource.id);
}
override readonly defaultRegistryUrls = ['https://charts.helm.sh/stable'];
override readonly defaultConfig = {
commitMessageTopic: 'Helm release {{depName}}',
};
override readonly defaultVersioning = helmVersioning.id;
override readonly releaseTimestampSupport = true;
override readonly releaseTimestampNote =
'The release timstamp is determined from the `created` field in the results.';
override readonly sourceUrlSupport = 'package';
override readonly sourceUrlNote =
'The source URL is determined from the `home` field or the `sources` field in the results.';
@cache({
namespace: `datasource-${HelmDatasource.id}`,
key: (helmRepository: string) => `repository-data:${helmRepository}`,
})
async getRepositoryData(helmRepository: string): Promise<HelmRepositoryData> {
const { val, err } = await this.http
.getYamlSafe(
'index.yaml',
{ baseUrl: ensureTrailingSlash(helmRepository) },
HelmRepositorySchema,
)
.unwrap();
if (err) {
this.handleGenericErrors(err);
}
return val;
}
async getReleases({
packageName,
registryUrl: helmRepository,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
// istanbul ignore if
if (!helmRepository) {
return null;
}
const repositoryData = await this.getRepositoryData(helmRepository);
const releases = repositoryData[packageName];
if (!releases) {
logger.debug(
{ dependency: packageName },
`Entry ${packageName} doesn't exist in index.yaml from ${helmRepository}`,
);
return null;
}
return releases;
}
}