From 5d88c1db38200896d2e4af7836fec95097adf509 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sat, 8 Feb 2020 04:22:44 +0200 Subject: vscode: amended config to use binary from globalStoragePath, added ui for downloading --- .../installation/fetch_latest_artifact_metadata.ts | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 editors/code/src/installation/fetch_latest_artifact_metadata.ts (limited to 'editors/code/src/installation/fetch_latest_artifact_metadata.ts') diff --git a/editors/code/src/installation/fetch_latest_artifact_metadata.ts b/editors/code/src/installation/fetch_latest_artifact_metadata.ts new file mode 100644 index 000000000..f07431aac --- /dev/null +++ b/editors/code/src/installation/fetch_latest_artifact_metadata.ts @@ -0,0 +1,47 @@ +import fetch from "node-fetch"; +import { GithubRepo, ArtifactMetadata } from "./interfaces"; + +const GITHUB_API_ENDPOINT_URL = "https://api.github.com"; + +export interface FetchLatestArtifactMetadataOpts { + repo: GithubRepo; + artifactFileName: string; +} + +export async function fetchLatestArtifactMetadata( + opts: FetchLatestArtifactMetadataOpts +): Promise { + + const repoOwner = encodeURIComponent(opts.repo.owner); + const repoName = encodeURIComponent(opts.repo.name); + + const apiEndpointPath = `/repos/${repoOwner}/${repoName}/releases/latest`; + const requestUrl = GITHUB_API_ENDPOINT_URL + apiEndpointPath; + + // We skip runtime type checks for simplicity (here we cast from `any` to `Release`) + + const response: GithubRelease = await fetch(requestUrl, { + headers: { Accept: "application/vnd.github.v3+json" } + }) + .then(res => res.json()); + + const artifact = response.assets.find(artifact => artifact.name === opts.artifactFileName); + + return !artifact ? null : { + releaseName: response.name, + downloadUrl: artifact.browser_download_url + }; + + // Noise denotes tremendous amount of data that we are not using here + interface GithubRelease { + name: string; + assets: Array<{ + browser_download_url: string; + + [noise: string]: unknown; + }>; + + [noise: string]: unknown; + } + +} -- cgit v1.2.3 From 6ef912f9259a78495fdba6a37bef7d78c4e0a4fd Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sat, 8 Feb 2020 20:18:33 +0200 Subject: vscode: converted fetchLatestArtifactMetadata params to positional, added docs --- .../installation/fetch_latest_artifact_metadata.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'editors/code/src/installation/fetch_latest_artifact_metadata.ts') 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"; const GITHUB_API_ENDPOINT_URL = "https://api.github.com"; -export interface FetchLatestArtifactMetadataOpts { - repo: GithubRepo; - artifactFileName: string; -} - +/** + * Fetches the latest release from GitHub `repo` and returns metadata about + * `artifactFileName` shipped with this release or `null` if no such artifact was published. + */ export async function fetchLatestArtifactMetadata( - opts: FetchLatestArtifactMetadataOpts + repo: GithubRepo, artifactFileName: string ): Promise { - const repoOwner = encodeURIComponent(opts.repo.owner); - const repoName = encodeURIComponent(opts.repo.name); + const repoOwner = encodeURIComponent(repo.owner); + const repoName = encodeURIComponent(repo.name); const apiEndpointPath = `/repos/${repoOwner}/${repoName}/releases/latest`; const requestUrl = GITHUB_API_ENDPOINT_URL + apiEndpointPath; - // We skip runtime type checks for simplicity (here we cast from `any` to `Release`) + // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`) const response: GithubRelease = await fetch(requestUrl, { headers: { Accept: "application/vnd.github.v3+json" } }) .then(res => res.json()); - const artifact = response.assets.find(artifact => artifact.name === opts.artifactFileName); + const artifact = response.assets.find(artifact => artifact.name === artifactFileName); return !artifact ? null : { releaseName: response.name, @@ -36,6 +35,7 @@ export async function fetchLatestArtifactMetadata( interface GithubRelease { name: string; assets: Array<{ + name: string; browser_download_url: string; [noise: string]: unknown; -- cgit v1.2.3 From 34241b9af966208d73f37f1cdf7f862f2590d846 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 9 Feb 2020 13:39:54 +0200 Subject: vscode: remove noise data fields declarations as per @matklad --- editors/code/src/installation/fetch_latest_artifact_metadata.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'editors/code/src/installation/fetch_latest_artifact_metadata.ts') diff --git a/editors/code/src/installation/fetch_latest_artifact_metadata.ts b/editors/code/src/installation/fetch_latest_artifact_metadata.ts index cda955af2..f1019e089 100644 --- a/editors/code/src/installation/fetch_latest_artifact_metadata.ts +++ b/editors/code/src/installation/fetch_latest_artifact_metadata.ts @@ -31,17 +31,12 @@ export async function fetchLatestArtifactMetadata( downloadUrl: artifact.browser_download_url }; - // Noise denotes tremendous amount of data that we are not using here + // We omit declaration of tremendous amount of fields that we are not using here interface GithubRelease { name: string; assets: Array<{ name: string; browser_download_url: string; - - [noise: string]: unknown; }>; - - [noise: string]: unknown; } - } -- cgit v1.2.3 From 7a09274e52dc00f7d4e3a040686aa1eb1e075671 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 9 Feb 2020 13:45:06 +0200 Subject: vscode: refactor inverted ternaries to if statements as per @matklad --- editors/code/src/installation/fetch_latest_artifact_metadata.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'editors/code/src/installation/fetch_latest_artifact_metadata.ts') diff --git a/editors/code/src/installation/fetch_latest_artifact_metadata.ts b/editors/code/src/installation/fetch_latest_artifact_metadata.ts index f1019e089..9141c92ef 100644 --- a/editors/code/src/installation/fetch_latest_artifact_metadata.ts +++ b/editors/code/src/installation/fetch_latest_artifact_metadata.ts @@ -26,7 +26,9 @@ export async function fetchLatestArtifactMetadata( const artifact = response.assets.find(artifact => artifact.name === artifactFileName); - return !artifact ? null : { + if (!artifact) return null; + + return { releaseName: response.name, downloadUrl: artifact.browser_download_url }; -- cgit v1.2.3 From 7cba77ed4e4207b2e24b8dd57723368c2717bb2a Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 9 Feb 2020 15:01:00 +0200 Subject: vscode: added logging when donloading binaries --- editors/code/src/installation/fetch_latest_artifact_metadata.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'editors/code/src/installation/fetch_latest_artifact_metadata.ts') diff --git a/editors/code/src/installation/fetch_latest_artifact_metadata.ts b/editors/code/src/installation/fetch_latest_artifact_metadata.ts index 9141c92ef..7e3700603 100644 --- a/editors/code/src/installation/fetch_latest_artifact_metadata.ts +++ b/editors/code/src/installation/fetch_latest_artifact_metadata.ts @@ -19,6 +19,8 @@ export async function fetchLatestArtifactMetadata( // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`) + console.log("Issuing request for released artifacts metadata to", requestUrl); + const response: GithubRelease = await fetch(requestUrl, { headers: { Accept: "application/vnd.github.v3+json" } }) -- cgit v1.2.3