blob: 6edf3e4571dadd963dfb0f1911992154d63c3be4 (
plain)
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
73
74
|
/* eslint-disable no-console */
import { compareVersions } from 'compare-versions';
const BASE_URL = `${window.location.protocol}//${window.location.host}`;
const DOCS_VERSIONS_ENDPOINT = `${BASE_URL}/versions.json`;
const GITLAB_RELEASE_DATES_ENDPOINT = `${BASE_URL}/release_dates.json`;
const DOCS_IMAGES_ENDPOINT =
'https://gitlab.com/api/v4/projects/1794617/registry/repositories/631635/tags?per_page=100';
/**
* Fetch a list of versions available on docs.gitlab.com.
*
* @returns Array
*/
export function getVersions() {
return fetch(DOCS_VERSIONS_ENDPOINT)
.then((response) => response.json())
.then((data) => {
return Object.assign(...data);
})
.catch((error) => console.error(error));
}
/**
* Fetch a list of archived versions available as container images.
*
* @returns Array
*/
export function getArchiveImages() {
return fetch(DOCS_IMAGES_ENDPOINT)
.then((response) => response.json())
.then((data) => {
// We only want tags for versioned releases, so drop any that aren't integers.
return data.filter((object) => !Number.isNaN(Number(object.name))).reverse();
})
.catch((error) => console.error(error));
}
/**
* Fetch a list of versions available on the archives site.
*
* @returns Array
*/
export async function getArchivesVersions() {
const onlineVersions = await getVersions();
const archiveImages = await getArchiveImages();
const oldestSupportedMinor = onlineVersions.last_major[1].split('.')[0];
const oldestCurrentMinor = onlineVersions.last_minor[1];
return archiveImages
.map((object) => object.name)
.filter(
(v) =>
compareVersions(v, oldestSupportedMinor) >= 0 &&
compareVersions(v, oldestCurrentMinor) < 0 &&
!Object.values(onlineVersions).flat().includes(v),
);
}
/**
* Fetch a list of versions with their associated release dates.
*
* @returns Array
*/
export function getReleaseDates() {
return fetch(GITLAB_RELEASE_DATES_ENDPOINT)
.then((response) => response.json())
.then((data) => {
return Object.assign(...data);
})
.catch((error) => console.error(error));
}
|