aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/installation/fetch_latest_artifact_metadata.ts20
1 files changed, 10 insertions, 10 deletions
diff --git a/editors/code/src/installation/fetch_latest_artifact_metadata.ts b/editors/code/src/installation/fetch_latest_artifact_metadata.ts
index f07431aac..cda955af2 100644
--- a/editors/code/src/installation/fetch_latest_artifact_metadata.ts
+++ b/editors/code/src/installation/fetch_latest_artifact_metadata.ts
@@ -3,29 +3,28 @@ import { GithubRepo, ArtifactMetadata } from "./interfaces";
3 3
4const GITHUB_API_ENDPOINT_URL = "https://api.github.com"; 4const GITHUB_API_ENDPOINT_URL = "https://api.github.com";
5 5
6export interface FetchLatestArtifactMetadataOpts { 6/**
7 repo: GithubRepo; 7 * Fetches the latest release from GitHub `repo` and returns metadata about
8 artifactFileName: string; 8 * `artifactFileName` shipped with this release or `null` if no such artifact was published.
9} 9 */
10
11export async function fetchLatestArtifactMetadata( 10export async function fetchLatestArtifactMetadata(
12 opts: FetchLatestArtifactMetadataOpts 11 repo: GithubRepo, artifactFileName: string
13): Promise<null | ArtifactMetadata> { 12): Promise<null | ArtifactMetadata> {
14 13
15 const repoOwner = encodeURIComponent(opts.repo.owner); 14 const repoOwner = encodeURIComponent(repo.owner);
16 const repoName = encodeURIComponent(opts.repo.name); 15 const repoName = encodeURIComponent(repo.name);
17 16
18 const apiEndpointPath = `/repos/${repoOwner}/${repoName}/releases/latest`; 17 const apiEndpointPath = `/repos/${repoOwner}/${repoName}/releases/latest`;
19 const requestUrl = GITHUB_API_ENDPOINT_URL + apiEndpointPath; 18 const requestUrl = GITHUB_API_ENDPOINT_URL + apiEndpointPath;
20 19
21 // We skip runtime type checks for simplicity (here we cast from `any` to `Release`) 20 // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`)
22 21
23 const response: GithubRelease = await fetch(requestUrl, { 22 const response: GithubRelease = await fetch(requestUrl, {
24 headers: { Accept: "application/vnd.github.v3+json" } 23 headers: { Accept: "application/vnd.github.v3+json" }
25 }) 24 })
26 .then(res => res.json()); 25 .then(res => res.json());
27 26
28 const artifact = response.assets.find(artifact => artifact.name === opts.artifactFileName); 27 const artifact = response.assets.find(artifact => artifact.name === artifactFileName);
29 28
30 return !artifact ? null : { 29 return !artifact ? null : {
31 releaseName: response.name, 30 releaseName: response.name,
@@ -36,6 +35,7 @@ export async function fetchLatestArtifactMetadata(
36 interface GithubRelease { 35 interface GithubRelease {
37 name: string; 36 name: string;
38 assets: Array<{ 37 assets: Array<{
38 name: string;
39 browser_download_url: string; 39 browser_download_url: string;
40 40
41 [noise: string]: unknown; 41 [noise: string]: unknown;