diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-16 11:54:38 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-16 11:54:38 +0000 |
commit | a15c8739b9a6da223e1f3a6ff6aa868913c0dbf4 (patch) | |
tree | 5694d395b08c416bf60d7206e0380a3859cfe1e2 /editors/code/src/installation/fetch_artifact_release_info.ts | |
parent | 617b5b3b31cf0b461829810640e28a9090a5b957 (diff) | |
parent | 325eba58a286c147f19dada5f205aa9e2ec6f391 (diff) |
Merge #3162
3162: Feature: vscode always downloads only the matching ra_lsp_server version r=matklad a=Veetaha
I tried to separate logically connected changes into separate commits, so enjoy!
Now TypeScript extension saves installed binary version in global state and always checks that the installed binary version equals the version of the TypeScript extension itself (to prevent version drifts).
Also, changed `fetchLatestArtifactReleaseInfo()` to `fetchArtifactReleaseInfo()` that takes an optional release tag (when not specified fetches the latest release). The version without a release tag will be useful in the future when adding auto-checking for updates.
I decided not to do `Download latest language server` command (I have stated the rationale for this in #3073) and let the extension itself decide which version of the binary it wants. This way the users will be able to get the latest `ra_lsp_server` binary after the approaching 2020-02-17 release, without having to manually delete the outdated one from `~/.config/Code/User/globalStorage/matklad.rust-analyzer`!
Closes #3073
Co-authored-by: Veetaha <[email protected]>
Diffstat (limited to 'editors/code/src/installation/fetch_artifact_release_info.ts')
-rw-r--r-- | editors/code/src/installation/fetch_artifact_release_info.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/editors/code/src/installation/fetch_artifact_release_info.ts b/editors/code/src/installation/fetch_artifact_release_info.ts new file mode 100644 index 000000000..7d497057a --- /dev/null +++ b/editors/code/src/installation/fetch_artifact_release_info.ts | |||
@@ -0,0 +1,52 @@ | |||
1 | import fetch from "node-fetch"; | ||
2 | import { GithubRepo, ArtifactReleaseInfo } from "./interfaces"; | ||
3 | |||
4 | const GITHUB_API_ENDPOINT_URL = "https://api.github.com"; | ||
5 | |||
6 | |||
7 | /** | ||
8 | * Fetches the release with `releaseTag` (or just latest release when not specified) | ||
9 | * from GitHub `repo` and returns metadata about `artifactFileName` shipped with | ||
10 | * this release or `null` if no such artifact was published. | ||
11 | */ | ||
12 | export async function fetchArtifactReleaseInfo( | ||
13 | repo: GithubRepo, artifactFileName: string, releaseTag?: string | ||
14 | ): Promise<null | ArtifactReleaseInfo> { | ||
15 | |||
16 | const repoOwner = encodeURIComponent(repo.owner); | ||
17 | const repoName = encodeURIComponent(repo.name); | ||
18 | |||
19 | const apiEndpointPath = releaseTag | ||
20 | ? `/repos/${repoOwner}/${repoName}/releases/tags/${releaseTag}` | ||
21 | : `/repos/${repoOwner}/${repoName}/releases/latest`; | ||
22 | |||
23 | const requestUrl = GITHUB_API_ENDPOINT_URL + apiEndpointPath; | ||
24 | |||
25 | // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`) | ||
26 | |||
27 | console.log("Issuing request for released artifacts metadata to", requestUrl); | ||
28 | |||
29 | // FIXME: handle non-ok response | ||
30 | const response: GithubRelease = await fetch(requestUrl, { | ||
31 | headers: { Accept: "application/vnd.github.v3+json" } | ||
32 | }) | ||
33 | .then(res => res.json()); | ||
34 | |||
35 | const artifact = response.assets.find(artifact => artifact.name === artifactFileName); | ||
36 | |||
37 | if (!artifact) return null; | ||
38 | |||
39 | return { | ||
40 | releaseName: response.name, | ||
41 | downloadUrl: artifact.browser_download_url | ||
42 | }; | ||
43 | |||
44 | // We omit declaration of tremendous amount of fields that we are not using here | ||
45 | interface GithubRelease { | ||
46 | name: string; | ||
47 | assets: Array<{ | ||
48 | name: string; | ||
49 | browser_download_url: string; | ||
50 | }>; | ||
51 | } | ||
52 | } | ||