From 24df846988e022a117079432fba28042a3134840 Mon Sep 17 00:00:00 2001 From: Guillermo Vaya Date: Sat, 23 Jul 2022 20:57:59 +0200 Subject: [PATCH] Add GHR protocol to plug manager --- packages/plugs/core/core.plug.yaml | 5 ++++- packages/plugs/core/plugmanager.ts | 15 +++++++++++++++ website/πŸ”Œ Plugs.md | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/plugs/core/core.plug.yaml b/packages/plugs/core/core.plug.yaml index 2086753..dfc8a7b 100644 --- a/packages/plugs/core/core.plug.yaml +++ b/packages/plugs/core/core.plug.yaml @@ -280,7 +280,10 @@ functions: path: "./plugmanager.ts:getPlugGithub" events: - get-plug:github - + getPlugGithubRelease: + path: "./plugmanager.ts:getPlugGithubRelease" + events: + - get-plug:ghr # Debug commands parseCommand: path: ./debug.ts:parsePageCommand diff --git a/packages/plugs/core/plugmanager.ts b/packages/plugs/core/plugmanager.ts index f52581f..cf74b19 100644 --- a/packages/plugs/core/plugmanager.ts +++ b/packages/plugs/core/plugmanager.ts @@ -92,3 +92,18 @@ export async function getPlugGithub(identifier: string): Promise { `//raw.githubusercontent.com/${owner}/${repoClean}/${branch}/${path}` ); } + +export async function getPlugGithubRelease(identifier: string): Promise { + let [owner, repo, version] = identifier.split("/"); + if (!version || version === "latest") { + console.log('fetching the latest version'); + const req = await fetch(`https://api.github.com/repos/${owner}/${repo}/releases/latest`); + if (req.status !== 200) { + throw new Error(`Could not fetch latest relase manifest from ${identifier}}`); + } + const result = await req.json(); + version = result.name; + } + const finalUrl = `//github.com/${owner}/${repo}/releases/download/${version}/${repo}.plug.json`; + return getPlugHTTPS(finalUrl); +} \ No newline at end of file diff --git a/website/πŸ”Œ Plugs.md b/website/πŸ”Œ Plugs.md index b4f4412..6d632cf 100644 --- a/website/πŸ”Œ Plugs.md +++ b/website/πŸ”Œ Plugs.md @@ -52,6 +52,7 @@ Reload your list of plugs via the `Plugs: Update` command (`Cmd-Shift-p` on Mac, Once you’re happy with your plug, you can distribute it in various ways: * You can put it on github by simply committing the resulting `.plug.json` file there and instructing users to point to by adding `- github:yourgithubuser/yourrepo/yourplugname.plug.json` to their `PLUGS` file +* Add a release in your github repo and instruct users to add the release as `- ghr:yourgithubuser/yourrepo` or if they need a spcecific release `- ghr:yourgithubuser/yourrepo/release-name` * You can put it on any other web server, and tell people to load it via https, e.g. `- https://mydomain.com/mypugname.plug.json`. ### Recommended development workflow