-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
index.ts
51 lines (48 loc) · 1.63 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
import { parse } from 'node-html-parser';
import got from '../../util/got';
import { isVersion } from '../../versioning/ruby';
import { DatasourceError, PkgReleaseConfig, ReleaseResult } from '../common';
const rubyVersionsUrl = 'https://www.ruby-lang.org/en/downloads/releases/';
export async function getPkgReleases(
_config?: PkgReleaseConfig
): Promise<ReleaseResult> {
// First check the persistent cache
const cacheNamespace = 'datasource-ruby-version';
const cachedResult = await renovateCache.get<ReleaseResult>(
cacheNamespace,
'all'
);
// istanbul ignore if
if (cachedResult) {
return cachedResult;
}
try {
const res: ReleaseResult = {
homepage: 'https://www.ruby-lang.org',
sourceUrl: 'https://github.com/ruby/ruby',
releases: [],
};
const response = await got(rubyVersionsUrl);
const root: any = parse(response.body);
const rows = root.querySelector('.release-list').querySelectorAll('tr');
for (const row of rows) {
const columns: string[] = Array.from(
row.querySelectorAll('td').map(td => td.innerHTML)
);
if (columns.length) {
const version = columns[0].replace('Ruby ', '');
if (isVersion(version)) {
const releaseTimestamp = columns[1];
const changelogUrl = columns[2]
.replace('<a href="', 'https://www.ruby-lang.org')
.replace('">more...</a>', '');
res.releases.push({ version, releaseTimestamp, changelogUrl });
}
}
}
await renovateCache.set(cacheNamespace, 'all', res, 15);
return res;
} catch (err) {
throw new DatasourceError(err);
}
}