/
index.ts
50 lines (43 loc) · 1.22 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
import { URL } from 'url';
import Git from 'simple-git/promise';
import * as packageCache from '../../util/cache/package';
import { DigestConfig, GetReleasesConfig, ReleaseResult } from '../common';
export const id = 'git-submodules';
export async function getReleases({
lookupName,
registryUrls,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
const cacheNamespace = 'datasource-git-submodules';
const cacheKey = `${registryUrls[0]}-${registryUrls[1]}`;
const cachedResult = await packageCache.get<ReleaseResult>(
cacheNamespace,
cacheKey
);
// istanbul ignore if
if (cachedResult) {
return cachedResult;
}
const git = Git();
const newHash = (
await git.listRemote(['--refs', registryUrls[0], registryUrls[1]])
)
.trim()
.split(/\t/)[0];
const sourceUrl = new URL(registryUrls[0]);
sourceUrl.username = '';
const result = {
sourceUrl: sourceUrl.href,
releases: [
{
version: newHash,
},
],
};
const cacheMinutes = 60;
await packageCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
return result;
}
export const getDigest = (
config: DigestConfig,
newValue?: string
): Promise<string> => new Promise((resolve) => resolve(newValue));