aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/installation/fetch_artifact_release_info.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/installation/fetch_artifact_release_info.ts')
-rw-r--r--editors/code/src/installation/fetch_artifact_release_info.ts77
1 files changed, 0 insertions, 77 deletions
diff --git a/editors/code/src/installation/fetch_artifact_release_info.ts b/editors/code/src/installation/fetch_artifact_release_info.ts
deleted file mode 100644
index 1ad3b8338..000000000
--- a/editors/code/src/installation/fetch_artifact_release_info.ts
+++ /dev/null
@@ -1,77 +0,0 @@
1import fetch from "node-fetch";
2import { GithubRepo, ArtifactReleaseInfo } from "./interfaces";
3import { log } from "../util";
4
5const GITHUB_API_ENDPOINT_URL = "https://api.github.com";
6
7/**
8 * Fetches the release with `releaseTag` from GitHub `repo` and
9 * returns metadata about `artifactFileName` shipped with
10 * this release.
11 *
12 * @throws Error upon network failure or if no such repository, release, or artifact exists.
13 */
14export async function fetchArtifactReleaseInfo(
15 repo: GithubRepo,
16 artifactFileName: string,
17 releaseTag: string
18): Promise<ArtifactReleaseInfo> {
19
20 const repoOwner = encodeURIComponent(repo.owner);
21 const repoName = encodeURIComponent(repo.name);
22
23 const apiEndpointPath = `/repos/${repoOwner}/${repoName}/releases/tags/${releaseTag}`;
24
25 const requestUrl = GITHUB_API_ENDPOINT_URL + apiEndpointPath;
26
27 log.debug("Issuing request for released artifacts metadata to", requestUrl);
28
29 const response = await fetch(requestUrl, { headers: { Accept: "application/vnd.github.v3+json" } });
30
31 if (!response.ok) {
32 log.error("Error fetching artifact release info", {
33 requestUrl,
34 releaseTag,
35 artifactFileName,
36 response: {
37 headers: response.headers,
38 status: response.status,
39 body: await response.text(),
40 }
41 });
42
43 throw new Error(
44 `Got response ${response.status} when trying to fetch ` +
45 `"${artifactFileName}" artifact release info for ${releaseTag} release`
46 );
47 }
48
49 // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`)
50 const release: GithubRelease = await response.json();
51
52 const artifact = release.assets.find(artifact => artifact.name === artifactFileName);
53
54 if (!artifact) {
55 throw new Error(
56 `Artifact ${artifactFileName} was not found in ${release.name} release!`
57 );
58 }
59
60 return {
61 releaseName: release.name,
62 releaseDate: new Date(release.published_at),
63 downloadUrl: artifact.browser_download_url
64 };
65
66 // We omit declaration of tremendous amount of fields that we are not using here
67 interface GithubRelease {
68 name: string;
69 // eslint-disable-next-line camelcase
70 published_at: string;
71 assets: Array<{
72 name: string;
73 // eslint-disable-next-line camelcase
74 browser_download_url: string;
75 }>;
76 }
77}