├── .gitignore ├── import_map.json ├── .vscode └── settings.json ├── deno.jsonc ├── github.plug.yaml ├── README.md ├── api.ts ├── github.ts ├── github.plug.js └── github.plug.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /import_map.json: -------------------------------------------------------------------------------- 1 | { 2 | "imports": { 3 | "$sb/": "../silverbullet/plug-api/", 4 | "yaml": "https://deno.land/std@0.184.0/yaml/mod.ts" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "deno.enable": true, 3 | "editor.formatOnSave": true, 4 | "deno.config": "deno.jsonc", 5 | "[markdown]": { 6 | "editor.formatOnSave": false 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /deno.jsonc: -------------------------------------------------------------------------------- 1 | { 2 | "importMap": "import_map.json", 3 | "tasks": { 4 | "build": "silverbullet plug:compile --importmap import_map.json github.plug.yaml", 5 | "watch": "silverbullet plug:compile -w --importmap import_map.json github.plug.yaml" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /github.plug.yaml: -------------------------------------------------------------------------------- 1 | name: github 2 | requiredPermissions: 3 | - fetch 4 | functions: 5 | queryEvents: 6 | path: ./github.ts:queryEvents 7 | events: 8 | - query:gh-event 9 | queryPulls: 10 | path: ./github.ts:queryPulls 11 | events: 12 | - query:gh-pull 13 | queryNotifications: 14 | path: ./github.ts:queryNotifications 15 | events: 16 | - query:gh-notification 17 | querySearchIssues: 18 | path: ./github.ts:querySearchIssues 19 | events: 20 | - query:gh-search-issue 21 | 22 | # Gist publishing 23 | shareGistCommand: 24 | path: ./github.ts:shareGistCommand 25 | command: 26 | name: "Share: Gist: Public Gist" 27 | loadGistCommand: 28 | path: ./github.ts:loadGistCommand 29 | command: 30 | name: "Share: Gist: Load" 31 | openGistCommand: 32 | path: ./github.ts:openGistCommand 33 | command: 34 | name: "Share: Gist: Open In Browser" 35 | 36 | ## Server side calls invoked from commands 37 | createGist: 38 | path: ./github.ts:createGist 39 | env: server 40 | updateGist: 41 | path: ./github.ts:updateGist 42 | env: server 43 | events: 44 | # For `Share: Publish` command 45 | - share:gh-gist 46 | getGist: 47 | path: ./github.ts:getGist 48 | env: server 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SilverBullet plug for Github 2 | 3 | **IMPORTANT NOTE** This plug is 0.xx only and no longer maintained. 4 | 5 | Provides various integrations with Github: 6 | 7 | * Query sources for events, notifications and pull requests 8 | * Ability to load and share pages as Gists 9 | 10 | ## Installation 11 | Open your `PLUGS` note in SilverBullet and add this plug to the list: 12 | 13 | ``` 14 | - github:silverbulletmd/silverbullet-github/github.plug.js 15 | ``` 16 | 17 | Then run the `Plugs: Update` command and off you go! 18 | 19 | ## Configuration 20 | To configure, add a `githubToken` key to your `SECRETS` page, this should be a [personal access token](https://github.com/settings/tokens): 21 | 22 | ```yaml 23 | githubToken: your-github-token 24 | ``` 25 | 26 | ## Query sources 27 | 28 | * `gh-event` List events of a user 29 | * `username`: the user whose events to query 30 | * `gh-pull`: List pull requests in a repository 31 | * `repo`: the repo to query PRs for 32 | * `gh-search-issue`: Search for issues and pull requests 33 | * `query`: [the search query](https://docs.github.com/en/rest/search#search-issues-and-pull-requests) 34 | * `gh-notification` requires a `githubToken` to be configured in `SECRETS`. 35 | 36 | ## Share as Gist support 37 | 38 | To use: navigate to a page, and run the {[Share: Gist: Public Gist]} command, this will perform an initial publish, and add a `$share` attribute to your page's front matter. Subsequent updates can be performed via {[Share: Publish]}. 39 | 40 | To pull an *existing* gist into your space, use the {[Share: Gist: Load]} command and paste the URL to the gist. 41 | ## Example 42 | 43 | Example uses of the query providers: 44 | 45 | ## Recent pushes 46 | ```query 47 | gh-event where username = "zefhemel" and type = "PushEvent" select type, actor_login, created_at, payload_ref limit 3 48 | ``` 49 | 50 | ## Recent PRs 51 | ```query 52 | gh-pull where repo = "silverbulletmd/silverbullet" and user_login = "zefhemel" limit 3 render [[template/gh-pull]] 53 | ``` 54 | 55 | Where the `template/gh-pull` looks as follows: 56 | 57 | * ({{state}}) [{{title}}]({{html_url}}) 58 | -------------------------------------------------------------------------------- /api.ts: -------------------------------------------------------------------------------- 1 | import { readSecrets } from "$sb/lib/secrets_page.ts"; 2 | 3 | export async function getToken(): Promise { 4 | try { 5 | const [token] = await readSecrets(["githubToken"]); 6 | return token; 7 | } catch { 8 | console.error("No github-config page found, using default config"); 9 | return undefined; 10 | } 11 | } 12 | export class GithubApi { 13 | constructor(private token?: string) {} 14 | 15 | async apiCall(url: string, options: any = {}): Promise { 16 | const res = await fetch(url, { 17 | ...options, 18 | headers: { 19 | Authorization: this.token ? `token ${this.token}` : undefined, 20 | }, 21 | }); 22 | if (res.status < 200 || res.status >= 300) { 23 | throw new Error(await res.text()); 24 | } 25 | return res.json(); 26 | } 27 | 28 | listEvents(username: string): Promise { 29 | return this.apiCall( 30 | `https://api.github.com/users/${username}/events?per_page=100`, 31 | ); 32 | } 33 | 34 | listPulls( 35 | repo: string, 36 | state = "all", 37 | sort = "updated", 38 | ): Promise { 39 | return this.apiCall( 40 | `https://api.github.com/repos/${repo}/pulls?state=${state}&sort=${sort}&direction=desc&per_page=100`, 41 | ); 42 | } 43 | 44 | searchIssues( 45 | query: string, 46 | sort = "", 47 | ): Promise<{ items: any[] }> { 48 | query = encodeURIComponent(query); 49 | 50 | return this.apiCall( 51 | `https://api.github.com/search/issues?q=${query}&sort=${sort}&direction=desc&per_page=100`, 52 | ); 53 | } 54 | 55 | listNotifications(): Promise { 56 | return this.apiCall(`https://api.github.com/notifications?per_page=100`); 57 | } 58 | 59 | async createGist( 60 | description: string, 61 | isPublic: boolean, 62 | files: Record, 63 | ): Promise { 64 | const result = await this.apiCall(`https://api.github.com/gists`, { 65 | method: "POST", 66 | body: JSON.stringify({ 67 | description, 68 | public: isPublic, 69 | files, 70 | }), 71 | }); 72 | return result.id; 73 | } 74 | 75 | updateGist( 76 | id: string, 77 | description: string, 78 | isPublic: boolean, 79 | files: Record, 80 | ) { 81 | return this.apiCall(`https://api.github.com/gists/${id}`, { 82 | method: "PATCH", 83 | body: JSON.stringify({ 84 | description, 85 | public: isPublic, 86 | files, 87 | }), 88 | }); 89 | } 90 | 91 | async getGist(id: string): Promise> { 92 | const resp = await this.apiCall(`https://api.github.com/gists/${id}`); 93 | return resp.files; 94 | } 95 | 96 | static async fromConfig(): Promise { 97 | return new GithubApi(await getToken()); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /github.ts: -------------------------------------------------------------------------------- 1 | import type { PublishEvent, QueryProviderEvent } from "$sb/app_event.ts"; 2 | import { 3 | applyQuery, 4 | evalQueryExpression, 5 | liftAttributeFilter, 6 | } from "$sb/lib/query.ts"; 7 | import { renderToText } from "$sb/lib/tree.ts"; 8 | import { 9 | editor, 10 | markdown, 11 | space, 12 | system, 13 | } from "$sb/silverbullet-syscall/mod.ts"; 14 | import { GithubApi } from "./api.ts"; 15 | import { 16 | extractFrontmatter, 17 | prepareFrontmatterDispatch, 18 | } from "$sb/lib/frontmatter.ts"; 19 | 20 | export async function queryEvents({ 21 | query, 22 | }: QueryProviderEvent): Promise { 23 | const api = await GithubApi.fromConfig(); 24 | const usernameFilter = liftAttributeFilter(query.filter, "username"); 25 | if (!usernameFilter) { 26 | throw Error("No 'username' filter specified, this is mandatory"); 27 | } 28 | 29 | const username: string = evalQueryExpression(usernameFilter, {}); 30 | const allEvents: any[] = await api.listEvents(username); 31 | 32 | return applyQuery( 33 | query, 34 | allEvents.map((e) => flattenObject(e)), 35 | ); 36 | } 37 | 38 | export async function queryPulls({ 39 | query, 40 | }: QueryProviderEvent): Promise { 41 | const api = await GithubApi.fromConfig(); 42 | const repoFilter = liftAttributeFilter(query.filter, "repo"); 43 | if (!repoFilter) { 44 | throw Error("No 'repo' specified, this is mandatory"); 45 | } 46 | const repo: string = evalQueryExpression(repoFilter, {}); 47 | let allPulls: any[] = await api.listPulls(repo, "all", "updated"); 48 | allPulls = applyQuery( 49 | query, 50 | allPulls.map((p) => flattenObject(p)), 51 | ); 52 | return allPulls; 53 | } 54 | 55 | export async function queryNotifications({ 56 | query, 57 | }: QueryProviderEvent): Promise { 58 | const api = await GithubApi.fromConfig(); 59 | let allNotifications = await api.listNotifications(); 60 | allNotifications = applyQuery( 61 | query, 62 | allNotifications.map((n) => flattenObject(n)), 63 | ); 64 | return allNotifications; 65 | } 66 | 67 | export async function querySearchIssues({ 68 | query, 69 | }: QueryProviderEvent): Promise { 70 | const api = await GithubApi.fromConfig(); 71 | 72 | const queryFilter = liftAttributeFilter(query.filter, "query"); 73 | if (!queryFilter) { 74 | throw Error("No 'query' specified, this is mandatory"); 75 | } 76 | 77 | const q = evalQueryExpression(queryFilter, {}); 78 | 79 | const searchResult = await api.searchIssues(q); 80 | const result = applyQuery( 81 | query, 82 | searchResult.items.map((n) => flattenObject(n)), 83 | ); 84 | return result; 85 | } 86 | 87 | function flattenObject(obj: any, prefix = ""): any { 88 | let result: any = {}; 89 | for (let [key, value] of Object.entries(obj)) { 90 | if (prefix) { 91 | key = prefix + "_" + key; 92 | } 93 | if (value && typeof value === "object") { 94 | result = { ...result, ...flattenObject(value, key) }; 95 | } else { 96 | result[key] = value; 97 | } 98 | } 99 | return result; 100 | } 101 | 102 | export async function shareGistCommand() { 103 | const pageName = await editor.getCurrentPage(); 104 | const text = await editor.getText(); 105 | const tree = await markdown.parseMarkdown(text); 106 | let { $share } = await extractFrontmatter(tree, ["$share"]); 107 | const cleanText = renderToText(tree); 108 | 109 | if (!$share) { 110 | $share = []; 111 | } 112 | 113 | // Check if already published 114 | for (const uri of $share) { 115 | if (uri.startsWith("gh-gist:")) { 116 | // Already published, let's just update it 117 | await system.invokeFunction("server", "updateGist", { 118 | name: pageName, 119 | uri: uri, 120 | }); 121 | await editor.flashNotification("Updated!"); 122 | await editor.openUrl(`https://gist.github.com/${uri.split(":")[1]}`); 123 | return; // Done 124 | } 125 | } 126 | 127 | const gistId = await system.invokeFunction( 128 | "server", 129 | "createGist", 130 | pageName, 131 | cleanText, 132 | ); 133 | 134 | const dispatchData = prepareFrontmatterDispatch(tree, { 135 | $share: [...$share, `gh-gist:${gistId}`], 136 | }); 137 | 138 | await editor.flashNotification("Done!"); 139 | 140 | await editor.dispatch(dispatchData); 141 | 142 | await editor.openUrl(`https://gist.github.com/${gistId}`); 143 | } 144 | 145 | export async function createGist(pageName: string, text: string) { 146 | const api = await GithubApi.fromConfig(); 147 | return api.createGist("", true, { 148 | [`${pageName}.md`]: { 149 | content: text, 150 | }, 151 | }); 152 | } 153 | 154 | export async function getGist(id: string): Promise> { 155 | const api = await GithubApi.fromConfig(); 156 | return api.getGist(id); 157 | } 158 | 159 | export async function loadGistCommand() { 160 | const gistUrl = await editor.prompt("Gist URL:"); 161 | if (!gistUrl) { 162 | return; 163 | } 164 | const pieces = gistUrl.split("/"); 165 | const gistId = pieces[pieces.length - 1]; 166 | const gist = await system.invokeFunction("server", "getGist", gistId); 167 | if (Object.keys(gist).length !== 1) { 168 | await editor.flashNotification( 169 | "Only gists with a single file are supported", 170 | "error", 171 | ); 172 | return; 173 | } 174 | const pageName = Object.keys(gist)[0].replace(/\.md$/, ""); 175 | const text = (Object.values(gist)[0] as any).content; 176 | const finalPageName = await editor.prompt("Page name:", pageName); 177 | if (!finalPageName) { 178 | return; 179 | } 180 | await space.writePage( 181 | finalPageName, 182 | `---\n$share:\n- 'gh-gist:${gistId}'\n---\n${text}`, 183 | ); 184 | await editor.navigate(finalPageName); 185 | } 186 | 187 | export async function openGistCommand() { 188 | const text = await editor.getText(); 189 | const tree = await markdown.parseMarkdown(text); 190 | const { $share } = await extractFrontmatter(tree); 191 | if (!$share) { 192 | await editor.flashNotification("Not currently shared as gist", "error"); 193 | return; 194 | } 195 | for (const uri of $share) { 196 | if (uri.startsWith("gh-gist:")) { 197 | const gistId = uri.split(":")[1]; 198 | const url = `https://gist.github.com/${gistId}`; 199 | await editor.openUrl(url); 200 | return; 201 | } 202 | } 203 | await editor.flashNotification("Not currently shared as gist", "error"); 204 | } 205 | 206 | export async function updateGist(event: PublishEvent) { 207 | const gistId = event.uri.split(":")[1]; 208 | const api = await GithubApi.fromConfig(); 209 | const text = await space.readPage(event.name); 210 | const tree = await markdown.parseMarkdown(text); 211 | // Only for side effect 212 | extractFrontmatter(tree, ["$share"]); 213 | const cleanText = renderToText(tree); 214 | 215 | await api.updateGist(gistId, "", true, { 216 | [`${event.name}.md`]: { 217 | content: cleanText, 218 | }, 219 | }); 220 | return true; 221 | } 222 | -------------------------------------------------------------------------------- /github.plug.js: -------------------------------------------------------------------------------- 1 | var mod=(()=>{var G=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var w=(e,t)=>{for(var r in t)G(e,r,{get:t[r],enumerable:!0})},oe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of re(t))!ne.call(e,o)&&o!==r&&G(e,o,{get:()=>t[o],enumerable:!(n=te(t,o))||n.enumerable});return e};var se=e=>oe(G({},"__esModule",{value:!0}),e);var At={};w(At,{functionMapping:()=>ee});typeof Deno>"u"&&(self.Deno={args:[],build:{arch:"x86_64"},env:{get(){}}});var k=new Map,F=0;function C(e){self.postMessage(e)}self.syscall=async(e,...t)=>await new Promise((r,n)=>{F++,k.set(F,{resolve:r,reject:n}),C({type:"sys",id:F,name:e,args:t})});function U(e,t){self.addEventListener("message",r=>{(async()=>{let n=r.data;switch(n.type){case"inv":{let o=e[n.name];if(!o)throw new Error(`Function not loaded: ${n.name}`);try{let s=await Promise.resolve(o(...n.args||[]));C({type:"invr",id:n.id,result:s})}catch(s){console.error("An exception was thrown as a result of invoking function",n.name,"error:",s),C({type:"invr",id:n.id,error:s.message})}}break;case"sysr":{let o=n.id,s=k.get(o);if(!s)throw Error("Invalid request id");k.delete(o),n.error?s.reject(new Error(n.error)):s.resolve(n.result)}break}})().catch(console.error)}),C({type:"manifest",manifest:t})}function ie(e){let t=atob(e),r=t.length,n=new Uint8Array(r);for(let o=0;o0?R(r):void 0;t={method:e.method,headers:Object.fromEntries(e.headers.entries()),base64Body:n},e=e.url}return syscall("sandboxFetch.fetch",e,t)}function ce(){globalThis.nativeFetch=globalThis.fetch,globalThis.fetch=async function(e,t){let r=t&&t.body?R(new Uint8Array(await new Response(t.body).arrayBuffer())):void 0,n=await ae(e,t&&{method:t.method,headers:t.headers,base64Body:r});return new Response(n.base64Body?ie(n.base64Body):null,{status:n.status,headers:n.headers})}}ce();function N(e){if(e.children)for(let t of e.children){if(t.parent)return;t.parent=e,N(t)}}function O(e,t){return E(e,r=>r.type===t)}function E(e,t){if(t(e))return[e];let r=[];if(e.children)for(let n of e.children)r=[...r,...E(n,t)];return r}async function D(e,t){if(await t(e))return[e];let r=[];if(e.children)for(let n of e.children)r=[...r,...await D(n,t)];return r}async function M(e,t){if(e.children){let r=e.children.slice();for(let n of r){let o=await t(n);if(o!==void 0){let s=e.children.indexOf(n);o?e.children.splice(s,1,o):e.children.splice(s,1)}else await M(n,t)}}}function $(e,t){return E(e,r=>r.type===t)[0]}function Q(e,t){E(e,t)}async function K(e,t){await D(e,t)}function g(e){let t=[];if(e.text!==void 0)return e.text;for(let r of e.children)t.push(g(r));return t.join("")}function u(e,t,r={}){let[n,o]=e;switch(n){case"and":return u(o,t,r)&&u(e[2],t,r);case"or":return u(o,t,r)||u(e[2],t,r);case"null":return null;case"number":case"string":case"boolean":return o;case"regexp":return[o,e[2]];case"attr":{let c=t;return e.length===3?(c=u(e[1],t,r),c?c[e[2]]:null):e[1]?c[e[1]]:t}case"array":return o.map(c=>u(c,t,r));case"object":return t;case"call":{let c=r[o];if(!c)throw new Error(`Unknown function: ${o}`);return c(...e[2].map(p=>u(p,t,r)))}}let s=u(o,t,r),a=u(e[2],t,r);switch(n){case"+":return s+a;case"-":return s-a;case"*":return s*a;case"/":return s/a;case"%":return s%a;case"=":{if(Array.isArray(s)&&!Array.isArray(a)){if(s.includes(a))return!0}else if(Array.isArray(s)&&Array.isArray(a)&&s.some(c=>a.includes(c)))return!0;return s==a}case"!=":return s!=a;case"=~":{if(!Array.isArray(a))throw new Error(`Invalid regexp: ${a}`);return new RegExp(a[0],a[1]).test(s)}case"!=~":{if(!Array.isArray(a))throw new Error(`Invalid regexp: ${a}`);return!new RegExp(a[0],a[1]).test(s)}case"<":return s":return s>a;case">=":return s>=a;case"in":return a.includes(s);default:throw new Error(`Unupported operator: ${n}`)}}function v(e,t){if(!e)throw new Error(`Cannot find attribute assignment for ${t}`);switch(e[0]){case"=":{if(e[1][0]==="attr"&&e[1][1]===t){let r=e[2];return e[1]=["boolean",!0],e[2]=["boolean",!0],r}break}case"and":case"or":{let r=v(e[1],t);if(r)return r;let n=v(e[2],t);if(n)return n;throw new Error(`Cannot find attribute assignment for ${t}`)}}throw new Error(`Cannot find attribute assignment for ${t}`)}function T(e,t){return e.filter&&(t=t.filter(r=>u(e.filter,r))),ue(e,t.map(r=>({key:[],value:r}))).map(r=>r.value)}function ue(e,t,r={}){if(e.orderBy&&t.sort((n,o)=>{let s=n.value,a=o.value;for(let{expr:c,desc:p}of e.orderBy){let m=u(c,s,r),x=u(c,a,r);if(mx||x===void 0)return p?-1:1}return 0}),e.select)for(let n=0;nn&&(t=t.slice(0,n))}return t}var l={};w(l,{confirm:()=>Me,dispatch:()=>ke,downloadFile:()=>ve,filterBox:()=>Te,flashNotification:()=>be,fold:()=>Re,foldAll:()=>Qe,getCurrentPage:()=>le,getCursor:()=>pe,getSelection:()=>me,getText:()=>fe,getUiOption:()=>$e,hidePanel:()=>Ce,insertAtCursor:()=>Fe,insertAtPos:()=>Ee,moveCursor:()=>Ge,navigate:()=>he,openUrl:()=>we,prompt:()=>Ne,reloadPage:()=>Pe,reloadUI:()=>xe,replaceRange:()=>Se,save:()=>ye,setPage:()=>de,setSelection:()=>ge,setUiOption:()=>qe,showPanel:()=>Ae,toggleFold:()=>De,unfold:()=>Oe,unfoldAll:()=>Ke,vimEx:()=>Ue});typeof self>"u"&&(self={syscall:()=>{throw new Error("Not implemented here")}});var i=self.syscall;function le(){return i("editor.getCurrentPage")}function de(e){return i("editor.setPage",e)}function fe(){return i("editor.getText")}function pe(){return i("editor.getCursor")}function me(){return i("editor.getSelection")}function ge(e,t){return i("editor.setSelection",e,t)}function ye(){return i("editor.save")}function he(e,t,r=!1,n=!1){return i("editor.navigate",e,t,r,n)}function Pe(){return i("editor.reloadPage")}function xe(){return i("editor.reloadUI")}function we(e,t=!1){return i("editor.openUrl",e,t)}function ve(e,t){return i("editor.downloadFile",e,t)}function be(e,t="info"){return i("editor.flashNotification",e,t)}function Te(e,t,r="",n=""){return i("editor.filterBox",e,t,r,n)}function Ae(e,t,r,n=""){return i("editor.showPanel",e,t,r,n)}function Ce(e){return i("editor.hidePanel",e)}function Ee(e,t){return i("editor.insertAtPos",e,t)}function Se(e,t,r){return i("editor.replaceRange",e,t,r)}function Ge(e,t=!1){return i("editor.moveCursor",e,t)}function Fe(e){return i("editor.insertAtCursor",e)}function ke(e){return i("editor.dispatch",e)}function Ne(e,t=""){return i("editor.prompt",e,t)}function Me(e){return i("editor.confirm",e)}function $e(e){return i("editor.getUiOption",e)}function qe(e,t){return i("editor.setUiOption",e,t)}function Ue(e){return i("editor.vimEx",e)}function Re(){return i("editor.fold")}function Oe(){return i("editor.unfold")}function De(){return i("editor.toggleFold")}function Qe(){return i("editor.foldAll")}function Ke(){return i("editor.unfoldAll")}var y={};w(y,{parseMarkdown:()=>Be});function Be(e){return i("markdown.parseMarkdown",e)}var P={};w(P,{deleteAttachment:()=>Xe,deleteFile:()=>nt,deletePage:()=>_e,getAttachmentMeta:()=>je,getFileMeta:()=>tt,getPageMeta:()=>Le,listAttachments:()=>Je,listFiles:()=>Ze,listPages:()=>Ie,listPlugs:()=>We,readAttachment:()=>He,readFile:()=>et,readPage:()=>Ve,writeAttachment:()=>ze,writeFile:()=>rt,writePage:()=>Ye});function Ie(e=!1){return i("space.listPages",e)}function Le(e){return i("space.getPageMeta",e)}function Ve(e){return i("space.readPage",e)}function Ye(e,t){return i("space.writePage",e,t)}function _e(e){return i("space.deletePage",e)}function We(){return i("space.listPlugs")}function Je(){return i("space.listAttachments")}function je(e){return i("space.getAttachmentMeta",e)}function He(e){return i("space.readAttachment",e)}function ze(e,t){return i("space.writeAttachment",e,t)}function Xe(e){return i("space.deleteAttachment",e)}function Ze(){return i("space.listFiles")}function et(e){return i("space.readFile",e)}function tt(e){return i("space.getFileMeta",e)}function rt(e,t){return i("space.writeFile",e,t)}function nt(e){return i("space.deleteFile",e)}var b={};w(b,{getEnv:()=>ct,invokeCommand:()=>st,invokeFunction:()=>ot,listCommands:()=>it,reloadPlugs:()=>at});function ot(e,...t){return i("system.invokeFunction",e,...t)}function st(e){return i("system.invokeCommand",e)}function it(){return i("system.listCommands")}function at(){i("system.reloadPlugs")}function ct(){return i("system.getEnv")}var h=globalThis.syscall;var f={};w(f,{parse:()=>ht,stringify:()=>Pt});function ht(e){return h("yaml.parse",e)}function Pt(e){return h("yaml.stringify",e)}async function vt(e,t){let r=await P.readPage(e),n=await y.parseMarkdown(r),o;return Q(n,s=>{if(s.type!=="FencedCode")return!1;let a=$(s,"CodeInfo");if(t&&!a||t&&!t.includes(a.children[0].text))return!1;let c=$(s,"CodeText");return c?(o=c.children[0].text,!0):!1}),o}async function B(e,t=["yaml"]){let r=await vt(e,t);if(r!==void 0)try{return f.parse(r)}catch(n){throw console.error("YAML Page parser error",n),new Error(`YAML Error: ${n.message}`)}}async function I(e){try{let t=await B("SECRETS",["yaml","secrets"]),r=[];for(let n of e){let o=t[n];if(o)r.push(o);else throw new Error(`No such secret: ${n}`)}return r}catch(t){throw t.message==="Not found"?new Error(`No such secret: ${e[0]}`):t}}async function bt(){try{let[e]=await I(["githubToken"]);return e}catch{console.error("No github-config page found, using default config");return}}var d=class{constructor(t){this.token=t}async apiCall(t,r={}){let n=await fetch(t,{...r,headers:{Authorization:this.token?`token ${this.token}`:void 0}});if(n.status<200||n.status>=300)throw new Error(await n.text());return n.json()}listEvents(t){return this.apiCall(`https://api.github.com/users/${t}/events?per_page=100`)}listPulls(t,r="all",n="updated"){return this.apiCall(`https://api.github.com/repos/${t}/pulls?state=${r}&sort=${n}&direction=desc&per_page=100`)}searchIssues(t,r=""){return t=encodeURIComponent(t),this.apiCall(`https://api.github.com/search/issues?q=${t}&sort=${r}&direction=desc&per_page=100`)}listNotifications(){return this.apiCall("https://api.github.com/notifications?per_page=100")}async createGist(t,r,n){return(await this.apiCall("https://api.github.com/gists",{method:"POST",body:JSON.stringify({description:t,public:r,files:n})})).id}updateGist(t,r,n,o){return this.apiCall(`https://api.github.com/gists/${t}`,{method:"PATCH",body:JSON.stringify({description:r,public:n,files:o})})}async getGist(t){return(await this.apiCall(`https://api.github.com/gists/${t}`)).files}static async fromConfig(){return new d(await bt())}};async function S(e,t=[],r=!1){let n={};N(e);let o=0;return await M(e,async s=>{if(s.type==="Paragraph"){if(o++,o!==1)return;O(s,"Hashtag").forEach(a=>{n.tags||(n.tags=[]);let c=a.children[0].text.substring(1);Array.isArray(n.tags)&&!n.tags.includes(c)&&n.tags.push(c)})}if(s.type==="FrontMatter"){let a=s.children[1].children[0],c=g(a);try{let p=await f.parse(c),m={...p};if(n={...n,...p},t.length>0){let x=!1;for(let q of t)q in m&&(delete m[q],x=!0);x&&(a.text=await f.stringify(m))}if(Object.keys(m).length===0||r)return null}catch(p){console.warn("Could not parse frontmatter",p.message)}}}),n.name&&(n.displayName=n.name,delete n.name),n}async function L(e,t){let r=null;return await K(e,async n=>{if(n.type==="FrontMatter"){let o=n.children[1].children[0],s=g(o);try{let c={...await f.parse(s),...t};r={changes:{from:o.from,to:o.to,insert:await f.stringify(c)}}}catch(a){console.error("Error parsing YAML",a)}return!0}return!1}),r||(r={changes:{from:0,to:0,insert:`--- 2 | `+await f.stringify(t)+`--- 3 | `}}),r}async function V({query:e}){let t=await d.fromConfig(),r=v(e.filter,"username");if(!r)throw Error("No 'username' filter specified, this is mandatory");let n=u(r,{}),o=await t.listEvents(n);return T(e,o.map(s=>A(s)))}async function Y({query:e}){let t=await d.fromConfig(),r=v(e.filter,"repo");if(!r)throw Error("No 'repo' specified, this is mandatory");let n=u(r,{}),o=await t.listPulls(n,"all","updated");return o=T(e,o.map(s=>A(s))),o}async function _({query:e}){let r=await(await d.fromConfig()).listNotifications();return r=T(e,r.map(n=>A(n))),r}async function W({query:e}){let t=await d.fromConfig(),r=v(e.filter,"query");if(!r)throw Error("No 'query' specified, this is mandatory");let n=u(r,{}),o=await t.searchIssues(n);return T(e,o.items.map(a=>A(a)))}function A(e,t=""){let r={};for(let[n,o]of Object.entries(e))t&&(n=t+"_"+n),o&&typeof o=="object"?r={...r,...A(o,n)}:r[n]=o;return r}async function J(){let e=await l.getCurrentPage(),t=await l.getText(),r=await y.parseMarkdown(t),{$share:n}=await S(r,["$share"]),o=g(r);n||(n=[]);for(let c of n)if(c.startsWith("gh-gist:")){await b.invokeFunction("server","updateGist",{name:e,uri:c}),await l.flashNotification("Updated!"),await l.openUrl(`https://gist.github.com/${c.split(":")[1]}`);return}let s=await b.invokeFunction("server","createGist",e,o),a=L(r,{$share:[...n,`gh-gist:${s}`]});await l.flashNotification("Done!"),await l.dispatch(a),await l.openUrl(`https://gist.github.com/${s}`)}async function j(e,t){return(await d.fromConfig()).createGist("",!0,{[`${e}.md`]:{content:t}})}async function H(e){return(await d.fromConfig()).getGist(e)}async function z(){let e=await l.prompt("Gist URL:");if(!e)return;let t=e.split("/"),r=t[t.length-1],n=await b.invokeFunction("server","getGist",r);if(Object.keys(n).length!==1){await l.flashNotification("Only gists with a single file are supported","error");return}let o=Object.keys(n)[0].replace(/\.md$/,""),s=Object.values(n)[0].content,a=await l.prompt("Page name:",o);a&&(await P.writePage(a,`--- 4 | $share: 5 | - 'gh-gist:${r}' 6 | --- 7 | ${s}`),await l.navigate(a))}async function X(){let e=await l.getText(),t=await y.parseMarkdown(e),{$share:r}=await S(t);if(!r){await l.flashNotification("Not currently shared as gist","error");return}for(let n of r)if(n.startsWith("gh-gist:")){let s=`https://gist.github.com/${n.split(":")[1]}`;await l.openUrl(s);return}await l.flashNotification("Not currently shared as gist","error")}async function Z(e){let t=e.uri.split(":")[1],r=await d.fromConfig(),n=await P.readPage(e.name),o=await y.parseMarkdown(n);S(o,["$share"]);let s=g(o);return await r.updateGist(t,"",!0,{[`${e.name}.md`]:{content:s}}),!0}var ee={queryEvents:V,queryPulls:Y,queryNotifications:_,querySearchIssues:W,shareGistCommand:J,loadGistCommand:z,openGistCommand:X,createGist:j,updateGist:Z,getGist:H},Tt={name:"github",requiredPermissions:["fetch"],functions:{queryEvents:{path:"./github.ts:queryEvents",events:["query:gh-event"]},queryPulls:{path:"./github.ts:queryPulls",events:["query:gh-pull"]},queryNotifications:{path:"./github.ts:queryNotifications",events:["query:gh-notification"]},querySearchIssues:{path:"./github.ts:querySearchIssues",events:["query:gh-search-issue"]},shareGistCommand:{path:"./github.ts:shareGistCommand",command:{name:"Share: Gist: Public Gist"}},loadGistCommand:{path:"./github.ts:loadGistCommand",command:{name:"Share: Gist: Load"}},openGistCommand:{path:"./github.ts:openGistCommand",command:{name:"Share: Gist: Open In Browser"}},createGist:{path:"./github.ts:createGist",env:"server"},updateGist:{path:"./github.ts:updateGist",env:"server",events:["share:gh-gist"]},getGist:{path:"./github.ts:getGist",env:"server"}},assets:{}};U(ee,Tt);return se(At);})(); 8 | -------------------------------------------------------------------------------- /github.plug.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github", 3 | "imports": [ 4 | "https://get.silverbullet.md/global.plug.json" 5 | ], 6 | "functions": { 7 | "queryEvents": { 8 | "events": [ 9 | "query:gh-event" 10 | ], 11 | "code": "(() => { var mod=(()=>{var S=Object.create;var p=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var x=(r=>typeof require!=\"undefined\"?require:typeof Proxy!=\"undefined\"?new Proxy(r,{get:(e,t)=>(typeof require!=\"undefined\"?require:e)[t]}):r)(function(r){if(typeof require!=\"undefined\")return require.apply(this,arguments);throw new Error('Dynamic require of \"'+r+'\" is not supported')});var w=(r,e)=>{for(var t in e)p(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,n)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of L(e))!Y.call(r,i)&&i!==t&&p(r,i,{get:()=>e[i],enumerable:!(n=I(e,i))||n.enumerable});return r};var T=(r,e,t)=>(t=r!=null?S(R(r)):{},v(e||!r||!r.__esModule?p(t,\"default\",{value:r,enumerable:!0}):t,r)),D=r=>v(p({},\"__esModule\",{value:!0}),r);var J={};w(J,{default:()=>H});function g(r,e){if(e(r))return[r];let t=[];if(r.children)for(let n of r.children)t=[...t,...g(n,e)];return t}function d(r,e){return g(r,t=>t.type===e)[0]}function P(r,e){g(r,e)}function A(r,e){let t=[];if(r.filter.length===0)t=e.slice();else{e:for(let n of e){let i=n;for(let{op:s,prop:a,value:c}of r.filter)switch(s){case\"=\":{let u=i[a];if(Array.isArray(u)&&!Array.isArray(c)){if(!u.includes(c))continue e}else if(Array.isArray(u)&&Array.isArray(c)){if(!u.some(O=>c.includes(O)))continue e}else if(u!=c)continue e;break}case\"!=\":if(i[a]==c)continue e;break;case\"<\":if(!(i[a]\":if(!(i[a]>c))continue e;break;case\">=\":if(!(i[a]>=c))continue e;break;case\"=~\":if(!new RegExp(c).exec(i[a]))continue e;break;case\"!=~\":if(new RegExp(c).exec(i[a]))continue e;break;case\"in\":if(!c.includes(i[a]))continue e;break}t.push(i)}}return r.ordering.length>0&&(t=t.sort((n,i)=>{for(let{orderBy:s,orderDesc:a}of r.ordering){if(n[s]i[s]||i[s]===void 0)return a?-1:1}return 0})),r.limit&&(t=t.slice(0,r.limit)),r.select&&(t=t.map(n=>{let i={};for(let s of r.select)i[s]=n[s];return i})),t}typeof self>\"u\"&&(self={syscall:()=>{throw new Error(\"Not implemented here\")}});var o=self.syscall;var f={};w(f,{parseMarkdown:()=>Q});function Q(r){return o(\"markdown.parseMarkdown\",r)}var y=class{listPages(e=!1){return o(\"space.listPages\",e)}getPageMeta(e){return o(\"space.getPageMeta\",e)}readPage(e){return o(\"space.readPage\",e)}writePage(e,t){return o(\"space.writePage\",e,t)}deletePage(e){return o(\"space.deletePage\",e)}listPlugs(){return o(\"space.listPlugs\")}listAttachments(){return o(\"space.listAttachments\")}getAttachmentMeta(e){return o(\"space.getAttachmentMeta\",e)}readAttachment(e){return o(\"space.readAttachment\",e)}writeAttachment(e,t,n){return o(\"space.writeAttachment\",e,t,n)}deleteAttachment(e){return o(\"space.deleteAttachment\",e)}readFile(e,t){return o(\"space.readFile\",e,t)}getFileMeta(e){return o(\"space.getFileMeta\",e)}writeFile(e,t,n){return o(\"space.writeFile\",e,t,n)}deleteFile(e){return o(\"space.deleteFile\",e)}listFiles(e){return o(\"space.listFiles\",e)}},m=new y;var h=T(x(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function _(r,e){let t=await m.readPage(r),n=await f.parseMarkdown(t),i;return P(n,s=>{if(s.type!==\"FencedCode\")return!1;let a=d(s,\"CodeInfo\");if(e&&!a||e&&!e.includes(a.children[0].text))return!1;let c=d(s,\"CodeText\");return c?(i=c.children[0].text,!0):!1}),i}async function k(r,e=[\"yaml\"]){let t=await _(r,e);if(t!==void 0)try{return h.parse(t)}catch(n){throw console.error(\"YAML Page parser error\",n),new Error(`YAML Error: ${n.message}`)}}async function N(r){try{let e=await k(\"SECRETS\",[\"yaml\",\"secrets\"]),t=[];for(let n of r){let i=e[n];if(i)t.push(i);else throw new Error(`No such secret: ${n}`)}return t}catch(e){throw e.message===\"Page not found\"?new Error(`No such secret: ${r[0]}`):e}}async function V(){try{let[r]=await N([\"githubToken\"]);return r}catch{console.error(\"No github-config page found, using default config\");return}}var l=class{constructor(e){this.token=e}async apiCall(e,t={}){let n=await fetch(e,{...t,headers:{Authorization:this.token?`token ${this.token}`:void 0}});if(n.status<200||n.status>=300)throw new Error(await n.text());return n.json()}listEvents(e){return this.apiCall(`https://api.github.com/users/${e}/events?per_page=100`)}listPulls(e,t=\"all\",n=\"updated\"){return this.apiCall(`https://api.github.com/repos/${e}/pulls?state=${t}&sort=${n}&direction=desc&per_page=100`)}searchIssues(e,t=\"\"){return e=encodeURIComponent(e),this.apiCall(`https://api.github.com/search/issues?q=${e}&sort=${t}&direction=desc&per_page=100`)}listNotifications(){return this.apiCall(\"https://api.github.com/notifications?per_page=100\")}async createGist(e,t,n){return(await this.apiCall(\"https://api.github.com/gists\",{method:\"POST\",body:JSON.stringify({description:e,public:t,files:n})})).id}updateGist(e,t,n,i){return this.apiCall(`https://api.github.com/gists/${e}`,{method:\"PATCH\",body:JSON.stringify({description:t,public:n,files:i})})}async getGist(e){return(await this.apiCall(`https://api.github.com/gists/${e}`)).files}static async fromConfig(){return new l(await V())}};var E=T(x(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function F({query:r}){let e=await l.fromConfig(),t=r.filter.find(s=>s.prop===\"username\");if(!t)throw Error(\"No 'username' filter specified, this is mandatory\");let n=[];if(t.op===\"=\")n=[t.value];else if(t.op===\"in\")n=t.value;else throw new Error(`Unsupported operator ${t.op}`);let i=[];for(let s of await Promise.all(n.map(a=>e.listEvents(a))))i.push(...s);return r.filter.splice(r.filter.indexOf(t),1),A(r,i.map(s=>$(s)))}function $(r,e=\"\"){let t={};for(let[n,i]of Object.entries(r))e&&(n=e+\"_\"+n),i&&typeof i==\"object\"?t={...t,...$(i,n)}:t[n]=i;return t}var H=F;return D(J);})();\n return mod;})()" 12 | }, 13 | "queryPulls": { 14 | "events": [ 15 | "query:gh-pull" 16 | ], 17 | "code": "(() => { var mod=(()=>{var S=Object.create;var p=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var x=(r=>typeof require!=\"undefined\"?require:typeof Proxy!=\"undefined\"?new Proxy(r,{get:(e,t)=>(typeof require!=\"undefined\"?require:e)[t]}):r)(function(r){if(typeof require!=\"undefined\")return require.apply(this,arguments);throw new Error('Dynamic require of \"'+r+'\" is not supported')});var w=(r,e)=>{for(var t in e)p(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,n)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of L(e))!Y.call(r,i)&&i!==t&&p(r,i,{get:()=>e[i],enumerable:!(n=I(e,i))||n.enumerable});return r};var T=(r,e,t)=>(t=r!=null?S(R(r)):{},v(e||!r||!r.__esModule?p(t,\"default\",{value:r,enumerable:!0}):t,r)),D=r=>v(p({},\"__esModule\",{value:!0}),r);var J={};w(J,{default:()=>H});function g(r,e){if(e(r))return[r];let t=[];if(r.children)for(let n of r.children)t=[...t,...g(n,e)];return t}function d(r,e){return g(r,t=>t.type===e)[0]}function P(r,e){g(r,e)}function A(r,e){let t=[];if(r.filter.length===0)t=e.slice();else{e:for(let n of e){let i=n;for(let{op:s,prop:a,value:c}of r.filter)switch(s){case\"=\":{let u=i[a];if(Array.isArray(u)&&!Array.isArray(c)){if(!u.includes(c))continue e}else if(Array.isArray(u)&&Array.isArray(c)){if(!u.some(O=>c.includes(O)))continue e}else if(u!=c)continue e;break}case\"!=\":if(i[a]==c)continue e;break;case\"<\":if(!(i[a]\":if(!(i[a]>c))continue e;break;case\">=\":if(!(i[a]>=c))continue e;break;case\"=~\":if(!new RegExp(c).exec(i[a]))continue e;break;case\"!=~\":if(new RegExp(c).exec(i[a]))continue e;break;case\"in\":if(!c.includes(i[a]))continue e;break}t.push(i)}}return r.ordering.length>0&&(t=t.sort((n,i)=>{for(let{orderBy:s,orderDesc:a}of r.ordering){if(n[s]i[s]||i[s]===void 0)return a?-1:1}return 0})),r.limit&&(t=t.slice(0,r.limit)),r.select&&(t=t.map(n=>{let i={};for(let s of r.select)i[s]=n[s];return i})),t}typeof self>\"u\"&&(self={syscall:()=>{throw new Error(\"Not implemented here\")}});var o=self.syscall;var f={};w(f,{parseMarkdown:()=>Q});function Q(r){return o(\"markdown.parseMarkdown\",r)}var y=class{listPages(e=!1){return o(\"space.listPages\",e)}getPageMeta(e){return o(\"space.getPageMeta\",e)}readPage(e){return o(\"space.readPage\",e)}writePage(e,t){return o(\"space.writePage\",e,t)}deletePage(e){return o(\"space.deletePage\",e)}listPlugs(){return o(\"space.listPlugs\")}listAttachments(){return o(\"space.listAttachments\")}getAttachmentMeta(e){return o(\"space.getAttachmentMeta\",e)}readAttachment(e){return o(\"space.readAttachment\",e)}writeAttachment(e,t,n){return o(\"space.writeAttachment\",e,t,n)}deleteAttachment(e){return o(\"space.deleteAttachment\",e)}readFile(e,t){return o(\"space.readFile\",e,t)}getFileMeta(e){return o(\"space.getFileMeta\",e)}writeFile(e,t,n){return o(\"space.writeFile\",e,t,n)}deleteFile(e){return o(\"space.deleteFile\",e)}listFiles(e){return o(\"space.listFiles\",e)}},m=new y;var h=T(x(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function _(r,e){let t=await m.readPage(r),n=await f.parseMarkdown(t),i;return P(n,s=>{if(s.type!==\"FencedCode\")return!1;let a=d(s,\"CodeInfo\");if(e&&!a||e&&!e.includes(a.children[0].text))return!1;let c=d(s,\"CodeText\");return c?(i=c.children[0].text,!0):!1}),i}async function k(r,e=[\"yaml\"]){let t=await _(r,e);if(t!==void 0)try{return h.parse(t)}catch(n){throw console.error(\"YAML Page parser error\",n),new Error(`YAML Error: ${n.message}`)}}async function N(r){try{let e=await k(\"SECRETS\",[\"yaml\",\"secrets\"]),t=[];for(let n of r){let i=e[n];if(i)t.push(i);else throw new Error(`No such secret: ${n}`)}return t}catch(e){throw e.message===\"Page not found\"?new Error(`No such secret: ${r[0]}`):e}}async function V(){try{let[r]=await N([\"githubToken\"]);return r}catch{console.error(\"No github-config page found, using default config\");return}}var l=class{constructor(e){this.token=e}async apiCall(e,t={}){let n=await fetch(e,{...t,headers:{Authorization:this.token?`token ${this.token}`:void 0}});if(n.status<200||n.status>=300)throw new Error(await n.text());return n.json()}listEvents(e){return this.apiCall(`https://api.github.com/users/${e}/events?per_page=100`)}listPulls(e,t=\"all\",n=\"updated\"){return this.apiCall(`https://api.github.com/repos/${e}/pulls?state=${t}&sort=${n}&direction=desc&per_page=100`)}searchIssues(e,t=\"\"){return e=encodeURIComponent(e),this.apiCall(`https://api.github.com/search/issues?q=${e}&sort=${t}&direction=desc&per_page=100`)}listNotifications(){return this.apiCall(\"https://api.github.com/notifications?per_page=100\")}async createGist(e,t,n){return(await this.apiCall(\"https://api.github.com/gists\",{method:\"POST\",body:JSON.stringify({description:e,public:t,files:n})})).id}updateGist(e,t,n,i){return this.apiCall(`https://api.github.com/gists/${e}`,{method:\"PATCH\",body:JSON.stringify({description:t,public:n,files:i})})}async getGist(e){return(await this.apiCall(`https://api.github.com/gists/${e}`)).files}static async fromConfig(){return new l(await V())}};var E=T(x(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function F({query:r}){let e=await l.fromConfig(),t=r.filter.find(s=>s.prop===\"repo\");if(!t)throw Error(\"No 'repo' specified, this is mandatory\");r.filter.splice(r.filter.indexOf(t),1);let n=[];if(t.op===\"=\")n=[t.value];else if(t.op===\"in\")n=t.value;else throw new Error(`Unsupported operator ${t.op}`);let i=[];for(let s of await Promise.all(n.map(a=>e.listPulls(a,\"all\",\"updated\"))))i.push(...s);return i=A(r,i.map(s=>$(s))),i}function $(r,e=\"\"){let t={};for(let[n,i]of Object.entries(r))e&&(n=e+\"_\"+n),i&&typeof i==\"object\"?t={...t,...$(i,n)}:t[n]=i;return t}var H=F;return D(J);})();\n return mod;})()" 18 | }, 19 | "queryNotifications": { 20 | "events": [ 21 | "query:gh-notification" 22 | ], 23 | "code": "(() => { var mod=(()=>{var S=Object.create;var p=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var x=(r=>typeof require!=\"undefined\"?require:typeof Proxy!=\"undefined\"?new Proxy(r,{get:(e,t)=>(typeof require!=\"undefined\"?require:e)[t]}):r)(function(r){if(typeof require!=\"undefined\")return require.apply(this,arguments);throw new Error('Dynamic require of \"'+r+'\" is not supported')});var w=(r,e)=>{for(var t in e)p(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,n)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of L(e))!Y.call(r,i)&&i!==t&&p(r,i,{get:()=>e[i],enumerable:!(n=I(e,i))||n.enumerable});return r};var T=(r,e,t)=>(t=r!=null?S(R(r)):{},v(e||!r||!r.__esModule?p(t,\"default\",{value:r,enumerable:!0}):t,r)),D=r=>v(p({},\"__esModule\",{value:!0}),r);var J={};w(J,{default:()=>H});function g(r,e){if(e(r))return[r];let t=[];if(r.children)for(let n of r.children)t=[...t,...g(n,e)];return t}function d(r,e){return g(r,t=>t.type===e)[0]}function P(r,e){g(r,e)}function A(r,e){let t=[];if(r.filter.length===0)t=e.slice();else{e:for(let n of e){let i=n;for(let{op:a,prop:c,value:s}of r.filter)switch(a){case\"=\":{let u=i[c];if(Array.isArray(u)&&!Array.isArray(s)){if(!u.includes(s))continue e}else if(Array.isArray(u)&&Array.isArray(s)){if(!u.some(O=>s.includes(O)))continue e}else if(u!=s)continue e;break}case\"!=\":if(i[c]==s)continue e;break;case\"<\":if(!(i[c]\":if(!(i[c]>s))continue e;break;case\">=\":if(!(i[c]>=s))continue e;break;case\"=~\":if(!new RegExp(s).exec(i[c]))continue e;break;case\"!=~\":if(new RegExp(s).exec(i[c]))continue e;break;case\"in\":if(!s.includes(i[c]))continue e;break}t.push(i)}}return r.ordering.length>0&&(t=t.sort((n,i)=>{for(let{orderBy:a,orderDesc:c}of r.ordering){if(n[a]i[a]||i[a]===void 0)return c?-1:1}return 0})),r.limit&&(t=t.slice(0,r.limit)),r.select&&(t=t.map(n=>{let i={};for(let a of r.select)i[a]=n[a];return i})),t}typeof self>\"u\"&&(self={syscall:()=>{throw new Error(\"Not implemented here\")}});var o=self.syscall;var f={};w(f,{parseMarkdown:()=>Q});function Q(r){return o(\"markdown.parseMarkdown\",r)}var y=class{listPages(e=!1){return o(\"space.listPages\",e)}getPageMeta(e){return o(\"space.getPageMeta\",e)}readPage(e){return o(\"space.readPage\",e)}writePage(e,t){return o(\"space.writePage\",e,t)}deletePage(e){return o(\"space.deletePage\",e)}listPlugs(){return o(\"space.listPlugs\")}listAttachments(){return o(\"space.listAttachments\")}getAttachmentMeta(e){return o(\"space.getAttachmentMeta\",e)}readAttachment(e){return o(\"space.readAttachment\",e)}writeAttachment(e,t,n){return o(\"space.writeAttachment\",e,t,n)}deleteAttachment(e){return o(\"space.deleteAttachment\",e)}readFile(e,t){return o(\"space.readFile\",e,t)}getFileMeta(e){return o(\"space.getFileMeta\",e)}writeFile(e,t,n){return o(\"space.writeFile\",e,t,n)}deleteFile(e){return o(\"space.deleteFile\",e)}listFiles(e){return o(\"space.listFiles\",e)}},m=new y;var h=T(x(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function _(r,e){let t=await m.readPage(r),n=await f.parseMarkdown(t),i;return P(n,a=>{if(a.type!==\"FencedCode\")return!1;let c=d(a,\"CodeInfo\");if(e&&!c||e&&!e.includes(c.children[0].text))return!1;let s=d(a,\"CodeText\");return s?(i=s.children[0].text,!0):!1}),i}async function k(r,e=[\"yaml\"]){let t=await _(r,e);if(t!==void 0)try{return h.parse(t)}catch(n){throw console.error(\"YAML Page parser error\",n),new Error(`YAML Error: ${n.message}`)}}async function N(r){try{let e=await k(\"SECRETS\",[\"yaml\",\"secrets\"]),t=[];for(let n of r){let i=e[n];if(i)t.push(i);else throw new Error(`No such secret: ${n}`)}return t}catch(e){throw e.message===\"Page not found\"?new Error(`No such secret: ${r[0]}`):e}}async function V(){try{let[r]=await N([\"githubToken\"]);return r}catch{console.error(\"No github-config page found, using default config\");return}}var l=class{constructor(e){this.token=e}async apiCall(e,t={}){let n=await fetch(e,{...t,headers:{Authorization:this.token?`token ${this.token}`:void 0}});if(n.status<200||n.status>=300)throw new Error(await n.text());return n.json()}listEvents(e){return this.apiCall(`https://api.github.com/users/${e}/events?per_page=100`)}listPulls(e,t=\"all\",n=\"updated\"){return this.apiCall(`https://api.github.com/repos/${e}/pulls?state=${t}&sort=${n}&direction=desc&per_page=100`)}searchIssues(e,t=\"\"){return e=encodeURIComponent(e),this.apiCall(`https://api.github.com/search/issues?q=${e}&sort=${t}&direction=desc&per_page=100`)}listNotifications(){return this.apiCall(\"https://api.github.com/notifications?per_page=100\")}async createGist(e,t,n){return(await this.apiCall(\"https://api.github.com/gists\",{method:\"POST\",body:JSON.stringify({description:e,public:t,files:n})})).id}updateGist(e,t,n,i){return this.apiCall(`https://api.github.com/gists/${e}`,{method:\"PATCH\",body:JSON.stringify({description:t,public:n,files:i})})}async getGist(e){return(await this.apiCall(`https://api.github.com/gists/${e}`)).files}static async fromConfig(){return new l(await V())}};var E=T(x(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function F({query:r}){let t=await(await l.fromConfig()).listNotifications();return t=A(r,t.map(n=>$(n))),t}function $(r,e=\"\"){let t={};for(let[n,i]of Object.entries(r))e&&(n=e+\"_\"+n),i&&typeof i==\"object\"?t={...t,...$(i,n)}:t[n]=i;return t}var H=F;return D(J);})();\n return mod;})()" 24 | }, 25 | "querySearchIssues": { 26 | "events": [ 27 | "query:gh-search-issue" 28 | ], 29 | "code": "(() => { var mod=(()=>{var S=Object.create;var p=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var x=(r=>typeof require!=\"undefined\"?require:typeof Proxy!=\"undefined\"?new Proxy(r,{get:(e,t)=>(typeof require!=\"undefined\"?require:e)[t]}):r)(function(r){if(typeof require!=\"undefined\")return require.apply(this,arguments);throw new Error('Dynamic require of \"'+r+'\" is not supported')});var w=(r,e)=>{for(var t in e)p(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,n)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of L(e))!Y.call(r,i)&&i!==t&&p(r,i,{get:()=>e[i],enumerable:!(n=I(e,i))||n.enumerable});return r};var T=(r,e,t)=>(t=r!=null?S(R(r)):{},v(e||!r||!r.__esModule?p(t,\"default\",{value:r,enumerable:!0}):t,r)),D=r=>v(p({},\"__esModule\",{value:!0}),r);var J={};w(J,{default:()=>H});function g(r,e){if(e(r))return[r];let t=[];if(r.children)for(let n of r.children)t=[...t,...g(n,e)];return t}function d(r,e){return g(r,t=>t.type===e)[0]}function P(r,e){g(r,e)}function A(r,e){let t=[];if(r.filter.length===0)t=e.slice();else{e:for(let n of e){let i=n;for(let{op:a,prop:s,value:c}of r.filter)switch(a){case\"=\":{let u=i[s];if(Array.isArray(u)&&!Array.isArray(c)){if(!u.includes(c))continue e}else if(Array.isArray(u)&&Array.isArray(c)){if(!u.some(O=>c.includes(O)))continue e}else if(u!=c)continue e;break}case\"!=\":if(i[s]==c)continue e;break;case\"<\":if(!(i[s]\":if(!(i[s]>c))continue e;break;case\">=\":if(!(i[s]>=c))continue e;break;case\"=~\":if(!new RegExp(c).exec(i[s]))continue e;break;case\"!=~\":if(new RegExp(c).exec(i[s]))continue e;break;case\"in\":if(!c.includes(i[s]))continue e;break}t.push(i)}}return r.ordering.length>0&&(t=t.sort((n,i)=>{for(let{orderBy:a,orderDesc:s}of r.ordering){if(n[a]i[a]||i[a]===void 0)return s?-1:1}return 0})),r.limit&&(t=t.slice(0,r.limit)),r.select&&(t=t.map(n=>{let i={};for(let a of r.select)i[a]=n[a];return i})),t}typeof self>\"u\"&&(self={syscall:()=>{throw new Error(\"Not implemented here\")}});var o=self.syscall;var f={};w(f,{parseMarkdown:()=>Q});function Q(r){return o(\"markdown.parseMarkdown\",r)}var y=class{listPages(e=!1){return o(\"space.listPages\",e)}getPageMeta(e){return o(\"space.getPageMeta\",e)}readPage(e){return o(\"space.readPage\",e)}writePage(e,t){return o(\"space.writePage\",e,t)}deletePage(e){return o(\"space.deletePage\",e)}listPlugs(){return o(\"space.listPlugs\")}listAttachments(){return o(\"space.listAttachments\")}getAttachmentMeta(e){return o(\"space.getAttachmentMeta\",e)}readAttachment(e){return o(\"space.readAttachment\",e)}writeAttachment(e,t,n){return o(\"space.writeAttachment\",e,t,n)}deleteAttachment(e){return o(\"space.deleteAttachment\",e)}readFile(e,t){return o(\"space.readFile\",e,t)}getFileMeta(e){return o(\"space.getFileMeta\",e)}writeFile(e,t,n){return o(\"space.writeFile\",e,t,n)}deleteFile(e){return o(\"space.deleteFile\",e)}listFiles(e){return o(\"space.listFiles\",e)}},m=new y;var h=T(x(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function _(r,e){let t=await m.readPage(r),n=await f.parseMarkdown(t),i;return P(n,a=>{if(a.type!==\"FencedCode\")return!1;let s=d(a,\"CodeInfo\");if(e&&!s||e&&!e.includes(s.children[0].text))return!1;let c=d(a,\"CodeText\");return c?(i=c.children[0].text,!0):!1}),i}async function k(r,e=[\"yaml\"]){let t=await _(r,e);if(t!==void 0)try{return h.parse(t)}catch(n){throw console.error(\"YAML Page parser error\",n),new Error(`YAML Error: ${n.message}`)}}async function N(r){try{let e=await k(\"SECRETS\",[\"yaml\",\"secrets\"]),t=[];for(let n of r){let i=e[n];if(i)t.push(i);else throw new Error(`No such secret: ${n}`)}return t}catch(e){throw e.message===\"Page not found\"?new Error(`No such secret: ${r[0]}`):e}}async function V(){try{let[r]=await N([\"githubToken\"]);return r}catch{console.error(\"No github-config page found, using default config\");return}}var l=class{constructor(e){this.token=e}async apiCall(e,t={}){let n=await fetch(e,{...t,headers:{Authorization:this.token?`token ${this.token}`:void 0}});if(n.status<200||n.status>=300)throw new Error(await n.text());return n.json()}listEvents(e){return this.apiCall(`https://api.github.com/users/${e}/events?per_page=100`)}listPulls(e,t=\"all\",n=\"updated\"){return this.apiCall(`https://api.github.com/repos/${e}/pulls?state=${t}&sort=${n}&direction=desc&per_page=100`)}searchIssues(e,t=\"\"){return e=encodeURIComponent(e),this.apiCall(`https://api.github.com/search/issues?q=${e}&sort=${t}&direction=desc&per_page=100`)}listNotifications(){return this.apiCall(\"https://api.github.com/notifications?per_page=100\")}async createGist(e,t,n){return(await this.apiCall(\"https://api.github.com/gists\",{method:\"POST\",body:JSON.stringify({description:e,public:t,files:n})})).id}updateGist(e,t,n,i){return this.apiCall(`https://api.github.com/gists/${e}`,{method:\"PATCH\",body:JSON.stringify({description:t,public:n,files:i})})}async getGist(e){return(await this.apiCall(`https://api.github.com/gists/${e}`)).files}static async fromConfig(){return new l(await V())}};var E=T(x(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function F({query:r}){let e=await l.fromConfig(),t=r.filter.find(s=>s.prop===\"query\");if(!t)throw Error(\"No 'query' specified, this is mandatory\");r.filter=r.filter.filter(s=>s.prop!==\"query\");let n=\"\";if(t.op===\"=\")n=t.value;else throw new Error(`Unsupported operator ${t.op}`);let i=await e.searchIssues(n);return A(r,i.items.map(s=>$(s)))}function $(r,e=\"\"){let t={};for(let[n,i]of Object.entries(r))e&&(n=e+\"_\"+n),i&&typeof i==\"object\"?t={...t,...$(i,n)}:t[n]=i;return t}var H=F;return D(J);})();\n return mod;})()" 30 | }, 31 | "shareGistCommand": { 32 | "command": { 33 | "name": "Share: Gist: Public Gist" 34 | }, 35 | "code": "(() => { var mod=(()=>{var Y=Object.create;var x=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var F=(e=>typeof require!=\"undefined\"?require:typeof Proxy!=\"undefined\"?new Proxy(e,{get:(t,r)=>(typeof require!=\"undefined\"?require:t)[r]}):e)(function(e){if(typeof require!=\"undefined\")return require.apply(this,arguments);throw new Error('Dynamic require of \"'+e+'\" is not supported')});var w=(e,t)=>{for(var r in t)x(e,r,{get:t[r],enumerable:!0})},$=(e,t,r,i)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let o of D(t))!j.call(e,o)&&o!==r&&x(e,o,{get:()=>t[o],enumerable:!(i=G(t,o))||i.enumerable});return e};var O=(e,t,r)=>(r=e!=null?Y(U(e)):{},$(t||!e||!e.__esModule?x(r,\"default\",{value:e,enumerable:!0}):r,e)),Q=e=>$(x({},\"__esModule\",{value:!0}),e);var Ce={};w(Ce,{default:()=>Ae});function b(e){if(!!e.children)for(let t of e.children){if(t.parent)return;t.parent=e,b(t)}}function A(e,t){if(t(e))return[e];let r=[];if(e.children)for(let i of e.children)r=[...r,...A(i,t)];return r}function v(e,t){if(e.children){let r=e.children.slice();for(let i of r){let o=t(i);if(o!==void 0){let s=e.children.indexOf(i);o?e.children.splice(s,1,o):e.children.splice(s,1)}else v(i,t)}}}function T(e,t){return A(e,r=>r.type===t)[0]}function C(e,t){A(e,t)}function f(e){let t=[];if(e.text!==void 0)return e.text;for(let r of e.children)t.push(f(r));return t.join(\"\")}typeof self>\"u\"&&(self={syscall:()=>{throw new Error(\"Not implemented here\")}});var n=self.syscall;var a={};w(a,{confirm:()=>fe,dispatch:()=>le,downloadFile:()=>ee,filterBox:()=>re,flashNotification:()=>te,getCurrentPage:()=>B,getCursor:()=>H,getSelection:()=>J,getText:()=>V,getUiOption:()=>pe,hidePanel:()=>ie,insertAtCursor:()=>ce,insertAtPos:()=>oe,moveCursor:()=>ae,navigate:()=>X,openUrl:()=>K,prompt:()=>ue,reloadPage:()=>Z,replaceRange:()=>se,save:()=>z,setPage:()=>_,setSelection:()=>W,setUiOption:()=>de,showPanel:()=>ne,vimEx:()=>me});function B(){return n(\"editor.getCurrentPage\")}function _(e){return n(\"editor.setPage\",e)}function V(){return n(\"editor.getText\")}function H(){return n(\"editor.getCursor\")}function J(){return n(\"editor.getSelection\")}function W(e,t){return n(\"editor.setSelection\",e,t)}function z(){return n(\"editor.save\")}function X(e,t,r=!1,i=!1){return n(\"editor.navigate\",e,t,r,i)}function Z(){return n(\"editor.reloadPage\")}function K(e){return n(\"editor.openUrl\",e)}function ee(e,t){return n(\"editor.downloadFile\",e,t)}function te(e,t=\"info\"){return n(\"editor.flashNotification\",e,t)}function re(e,t,r=\"\",i=\"\"){return n(\"editor.filterBox\",e,t,r,i)}function ne(e,t,r,i=\"\"){return n(\"editor.showPanel\",e,t,r,i)}function ie(e){return n(\"editor.hidePanel\",e)}function oe(e,t){return n(\"editor.insertAtPos\",e,t)}function se(e,t,r){return n(\"editor.replaceRange\",e,t,r)}function ae(e,t=!1){return n(\"editor.moveCursor\",e,t)}function ce(e){return n(\"editor.insertAtCursor\",e)}function le(e){return n(\"editor.dispatch\",e)}function ue(e,t=\"\"){return n(\"editor.prompt\",e,t)}function fe(e){return n(\"editor.confirm\",e)}function pe(e){return n(\"editor.getUiOption\",e)}function de(e,t){return n(\"editor.setUiOption\",e,t)}function me(e){return n(\"editor.vimEx\",e)}var d={};w(d,{parseMarkdown:()=>Pe});function Pe(e){return n(\"markdown.parseMarkdown\",e)}var M=class{listPages(t=!1){return n(\"space.listPages\",t)}getPageMeta(t){return n(\"space.getPageMeta\",t)}readPage(t){return n(\"space.readPage\",t)}writePage(t,r){return n(\"space.writePage\",t,r)}deletePage(t){return n(\"space.deletePage\",t)}listPlugs(){return n(\"space.listPlugs\")}listAttachments(){return n(\"space.listAttachments\")}getAttachmentMeta(t){return n(\"space.getAttachmentMeta\",t)}readAttachment(t){return n(\"space.readAttachment\",t)}writeAttachment(t,r,i){return n(\"space.writeAttachment\",t,r,i)}deleteAttachment(t){return n(\"space.deleteAttachment\",t)}readFile(t,r){return n(\"space.readFile\",t,r)}getFileMeta(t){return n(\"space.getFileMeta\",t)}writeFile(t,r,i){return n(\"space.writeFile\",t,r,i)}deleteFile(t){return n(\"space.deleteFile\",t)}listFiles(t){return n(\"space.listFiles\",t)}},k=new M;var m={};w(m,{getEnv:()=>Te,invokeCommand:()=>xe,invokeFunction:()=>he,listCommands:()=>we,reloadPlugs:()=>ve});function he(e,t,...r){return n(\"system.invokeFunction\",e,t,...r)}function xe(e){return n(\"system.invokeCommand\",e)}function we(){return n(\"system.listCommands\")}function ve(){n(\"system.reloadPlugs\")}function Te(){return n(\"system.getEnv\")}var S=O(F(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));var c=O(F(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));function I(e,t=[]){let r={};return b(e),v(e,i=>{if(i.type===\"Hashtag\"){if(i.parent&&i.parent.type===\"Paragraph\"){let u=i.children[0].text.substring(1);r.tags||(r.tags=[]),Array.isArray(r.tags)&&!r.tags.includes(u)&&r.tags.push(u)}return}if(i.type===\"FrontMatter\"){let u=i.children[1].children[0],P=f(u);try{let y=c.parse(P),h={...y};if(r={...r,...y},t.length>0){let N=!1;for(let E of t)E in h&&(delete h[E],N=!0);N&&(u.text=c.stringify(h))}if(Object.keys(h).length===0)return null}catch(y){console.error(\"Could not parse frontmatter\",y)}}if(i.type!==\"FencedCode\")return;let o=T(i,\"CodeInfo\");if(!o||o.children[0].text!==\"meta\")return;let s=T(i,\"CodeText\");if(!s)return;let p=s.children[0].text,l=c.parse(p),g={...l};if(r={...r,...l},t.length>0){let u=!1;for(let P of t)P in g&&(delete g[P],u=!0);u&&(s.children[0].text=c.stringify(g).trim())}if(Object.keys(g).length===0)return null}),r.name&&(r.displayName=r.name,delete r.name),r}function L(e,t){let r=null;return C(e,i=>{if(i.type===\"FrontMatter\"){let o=i.children[1].children[0],s=f(o);try{let l={...c.parse(s),...t};r={changes:{from:o.from,to:o.to,insert:c.stringify(l,{noArrayIndent:!0})}}}catch(p){console.error(\"Error parsing YAML\",p)}return!0}return!1}),r||(r={changes:{from:0,to:0,insert:`---\n`+c.stringify(t,{noArrayIndent:!0})+`---\n`}}),r}async function R(){let e=await a.getCurrentPage(),t=await a.getText(),r=await d.parseMarkdown(t),{$share:i}=I(r,[\"$share\"]),o=f(r);i||(i=[]);for(let l of i)if(l.startsWith(\"gh-gist:\")){await m.invokeFunction(\"server\",\"updateGist\",{name:e,uri:l}),await a.flashNotification(\"Updated!\"),await a.openUrl(`https://gist.github.com/${l.split(\":\")[1]}`);return}let s=await m.invokeFunction(\"server\",\"createGist\",e,o),p=L(r,{$share:[...i,`gh-gist:${s}`]});await a.flashNotification(\"Done!\"),await a.dispatch(p),await a.openUrl(`https://gist.github.com/${s}`)}var Ae=R;return Q(Ce);})();\n return mod;})()" 36 | }, 37 | "loadGistCommand": { 38 | "command": { 39 | "name": "Share: Gist: Load" 40 | }, 41 | "code": "(() => { var mod=(()=>{var T=Object.create;var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var m=(t=>typeof require!=\"undefined\"?require:typeof Proxy!=\"undefined\"?new Proxy(t,{get:(e,n)=>(typeof require!=\"undefined\"?require:e)[n]}):t)(function(t){if(typeof require!=\"undefined\")return require.apply(this,arguments);throw new Error('Dynamic require of \"'+t+'\" is not supported')});var f=(t,e)=>{for(var n in e)a(t,n,{get:e[n],enumerable:!0})},g=(t,e,n,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of A(e))!M.call(t,o)&&o!==n&&a(t,o,{get:()=>e[o],enumerable:!(i=b(e,o))||i.enumerable});return t};var P=(t,e,n)=>(n=t!=null?T(C(t)):{},g(e||!t||!t.__esModule?a(n,\"default\",{value:t,enumerable:!0}):n,t)),k=t=>g(a({},\"__esModule\",{value:!0}),t);var pe={};f(pe,{default:()=>fe});typeof self>\"u\"&&(self={syscall:()=>{throw new Error(\"Not implemented here\")}});var r=self.syscall;var s={};f(s,{confirm:()=>X,dispatch:()=>W,downloadFile:()=>U,filterBox:()=>Q,flashNotification:()=>j,getCurrentPage:()=>F,getCursor:()=>S,getSelection:()=>I,getText:()=>O,getUiOption:()=>Z,hidePanel:()=>B,insertAtCursor:()=>J,insertAtPos:()=>_,moveCursor:()=>H,navigate:()=>Y,openUrl:()=>D,prompt:()=>z,reloadPage:()=>G,replaceRange:()=>V,save:()=>R,setPage:()=>$,setSelection:()=>L,setUiOption:()=>K,showPanel:()=>q,vimEx:()=>ee});function F(){return r(\"editor.getCurrentPage\")}function $(t){return r(\"editor.setPage\",t)}function O(){return r(\"editor.getText\")}function S(){return r(\"editor.getCursor\")}function I(){return r(\"editor.getSelection\")}function L(t,e){return r(\"editor.setSelection\",t,e)}function R(){return r(\"editor.save\")}function Y(t,e,n=!1,i=!1){return r(\"editor.navigate\",t,e,n,i)}function G(){return r(\"editor.reloadPage\")}function D(t){return r(\"editor.openUrl\",t)}function U(t,e){return r(\"editor.downloadFile\",t,e)}function j(t,e=\"info\"){return r(\"editor.flashNotification\",t,e)}function Q(t,e,n=\"\",i=\"\"){return r(\"editor.filterBox\",t,e,n,i)}function q(t,e,n,i=\"\"){return r(\"editor.showPanel\",t,e,n,i)}function B(t){return r(\"editor.hidePanel\",t)}function _(t,e){return r(\"editor.insertAtPos\",t,e)}function V(t,e,n){return r(\"editor.replaceRange\",t,e,n)}function H(t,e=!1){return r(\"editor.moveCursor\",t,e)}function J(t){return r(\"editor.insertAtCursor\",t)}function W(t){return r(\"editor.dispatch\",t)}function z(t,e=\"\"){return r(\"editor.prompt\",t,e)}function X(t){return r(\"editor.confirm\",t)}function Z(t){return r(\"editor.getUiOption\",t)}function K(t,e){return r(\"editor.setUiOption\",t,e)}function ee(t){return r(\"editor.vimEx\",t)}var d=class{listPages(e=!1){return r(\"space.listPages\",e)}getPageMeta(e){return r(\"space.getPageMeta\",e)}readPage(e){return r(\"space.readPage\",e)}writePage(e,n){return r(\"space.writePage\",e,n)}deletePage(e){return r(\"space.deletePage\",e)}listPlugs(){return r(\"space.listPlugs\")}listAttachments(){return r(\"space.listAttachments\")}getAttachmentMeta(e){return r(\"space.getAttachmentMeta\",e)}readAttachment(e){return r(\"space.readAttachment\",e)}writeAttachment(e,n,i){return r(\"space.writeAttachment\",e,n,i)}deleteAttachment(e){return r(\"space.deleteAttachment\",e)}readFile(e,n){return r(\"space.readFile\",e,n)}getFileMeta(e){return r(\"space.getFileMeta\",e)}writeFile(e,n,i){return r(\"space.writeFile\",e,n,i)}deleteFile(e){return r(\"space.deleteFile\",e)}listFiles(e){return r(\"space.listFiles\",e)}},c=new d;var l={};f(l,{getEnv:()=>ae,invokeCommand:()=>ie,invokeFunction:()=>ne,listCommands:()=>oe,reloadPlugs:()=>se});function ne(t,e,...n){return r(\"system.invokeFunction\",t,e,...n)}function ie(t){return r(\"system.invokeCommand\",t)}function oe(){return r(\"system.listCommands\")}function se(){r(\"system.reloadPlugs\")}function ae(){return r(\"system.getEnv\")}var h=P(m(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));var x=P(m(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function w(){let t=await s.prompt(\"Gist URL:\");if(!t)return;let e=t.split(\"/\"),n=e[e.length-1],i=await l.invokeFunction(\"server\",\"getGist\",n);if(Object.keys(i).length!==1){await s.flashNotification(\"Only gists with a single file are supported\",\"error\");return}let o=Object.keys(i)[0].replace(/\\.md$/,\"\"),v=Object.values(i)[0].content,u=await s.prompt(\"Page name:\",o);!u||(await c.writePage(u,`---\n$share:\n- 'gh-gist:${n}'\n---\n${v}`),await s.navigate(u))}var fe=w;return k(pe);})();\n return mod;})()" 42 | }, 43 | "openGistCommand": { 44 | "command": { 45 | "name": "Share: Gist: Open In Browser" 46 | }, 47 | "code": "(() => { var mod=(()=>{var L=Object.create;var P=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var M=(e=>typeof require!=\"undefined\"?require:typeof Proxy!=\"undefined\"?new Proxy(e,{get:(t,r)=>(typeof require!=\"undefined\"?require:t)[r]}):e)(function(e){if(typeof require!=\"undefined\")return require.apply(this,arguments);throw new Error('Dynamic require of \"'+e+'\" is not supported')});var x=(e,t)=>{for(var r in t)P(e,r,{get:t[r],enumerable:!0})},k=(e,t,r,i)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let o of Y(t))!D.call(e,o)&&o!==r&&P(e,o,{get:()=>t[o],enumerable:!(i=R(t,o))||i.enumerable});return e};var N=(e,t,r)=>(r=e!=null?L(G(e)):{},k(t||!e||!e.__esModule?P(r,\"default\",{value:e,enumerable:!0}):r,e)),U=e=>k(P({},\"__esModule\",{value:!0}),e);var xe={};x(xe,{default:()=>he});function w(e){if(!!e.children)for(let t of e.children){if(t.parent)return;t.parent=e,w(t)}}function E(e,t){if(t(e))return[e];let r=[];if(e.children)for(let i of e.children)r=[...r,...E(i,t)];return r}function y(e,t){if(e.children){let r=e.children.slice();for(let i of r){let o=t(i);if(o!==void 0){let s=e.children.indexOf(i);o?e.children.splice(s,1,o):e.children.splice(s,1)}else y(i,t)}}}function h(e,t){return E(e,r=>r.type===t)[0]}function u(e){let t=[];if(e.text!==void 0)return e.text;for(let r of e.children)t.push(u(r));return t.join(\"\")}typeof self>\"u\"&&(self={syscall:()=>{throw new Error(\"Not implemented here\")}});var n=self.syscall;var c={};x(c,{confirm:()=>le,dispatch:()=>ae,downloadFile:()=>Z,filterBox:()=>ee,flashNotification:()=>K,getCurrentPage:()=>Q,getCursor:()=>_,getSelection:()=>V,getText:()=>B,getUiOption:()=>ue,hidePanel:()=>re,insertAtCursor:()=>se,insertAtPos:()=>ne,moveCursor:()=>oe,navigate:()=>W,openUrl:()=>X,prompt:()=>ce,reloadPage:()=>z,replaceRange:()=>ie,save:()=>J,setPage:()=>q,setSelection:()=>H,setUiOption:()=>fe,showPanel:()=>te,vimEx:()=>pe});function Q(){return n(\"editor.getCurrentPage\")}function q(e){return n(\"editor.setPage\",e)}function B(){return n(\"editor.getText\")}function _(){return n(\"editor.getCursor\")}function V(){return n(\"editor.getSelection\")}function H(e,t){return n(\"editor.setSelection\",e,t)}function J(){return n(\"editor.save\")}function W(e,t,r=!1,i=!1){return n(\"editor.navigate\",e,t,r,i)}function z(){return n(\"editor.reloadPage\")}function X(e){return n(\"editor.openUrl\",e)}function Z(e,t){return n(\"editor.downloadFile\",e,t)}function K(e,t=\"info\"){return n(\"editor.flashNotification\",e,t)}function ee(e,t,r=\"\",i=\"\"){return n(\"editor.filterBox\",e,t,r,i)}function te(e,t,r,i=\"\"){return n(\"editor.showPanel\",e,t,r,i)}function re(e){return n(\"editor.hidePanel\",e)}function ne(e,t){return n(\"editor.insertAtPos\",e,t)}function ie(e,t,r){return n(\"editor.replaceRange\",e,t,r)}function oe(e,t=!1){return n(\"editor.moveCursor\",e,t)}function se(e){return n(\"editor.insertAtCursor\",e)}function ae(e){return n(\"editor.dispatch\",e)}function ce(e,t=\"\"){return n(\"editor.prompt\",e,t)}function le(e){return n(\"editor.confirm\",e)}function ue(e){return n(\"editor.getUiOption\",e)}function fe(e,t){return n(\"editor.setUiOption\",e,t)}function pe(e){return n(\"editor.vimEx\",e)}var f={};x(f,{parseMarkdown:()=>me});function me(e){return n(\"markdown.parseMarkdown\",e)}var v=class{listPages(t=!1){return n(\"space.listPages\",t)}getPageMeta(t){return n(\"space.getPageMeta\",t)}readPage(t){return n(\"space.readPage\",t)}writePage(t,r){return n(\"space.writePage\",t,r)}deletePage(t){return n(\"space.deletePage\",t)}listPlugs(){return n(\"space.listPlugs\")}listAttachments(){return n(\"space.listAttachments\")}getAttachmentMeta(t){return n(\"space.getAttachmentMeta\",t)}readAttachment(t){return n(\"space.readAttachment\",t)}writeAttachment(t,r,i){return n(\"space.writeAttachment\",t,r,i)}deleteAttachment(t){return n(\"space.deleteAttachment\",t)}readFile(t,r){return n(\"space.readFile\",t,r)}getFileMeta(t){return n(\"space.getFileMeta\",t)}writeFile(t,r,i){return n(\"space.writeFile\",t,r,i)}deleteFile(t){return n(\"space.deleteFile\",t)}listFiles(t){return n(\"space.listFiles\",t)}},T=new v;var $=N(M(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));var l=N(M(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));function O(e,t=[]){let r={};return w(e),y(e,i=>{if(i.type===\"Hashtag\"){if(i.parent&&i.parent.type===\"Paragraph\"){let a=i.children[0].text.substring(1);r.tags||(r.tags=[]),Array.isArray(r.tags)&&!r.tags.includes(a)&&r.tags.push(a)}return}if(i.type===\"FrontMatter\"){let a=i.children[1].children[0],d=u(a);try{let m=l.parse(d),g={...m};if(r={...r,...m},t.length>0){let A=!1;for(let C of t)C in g&&(delete g[C],A=!0);A&&(a.text=l.stringify(g))}if(Object.keys(g).length===0)return null}catch(m){console.error(\"Could not parse frontmatter\",m)}}if(i.type!==\"FencedCode\")return;let o=h(i,\"CodeInfo\");if(!o||o.children[0].text!==\"meta\")return;let s=h(i,\"CodeText\");if(!s)return;let I=s.children[0].text,b=l.parse(I),p={...b};if(r={...r,...b},t.length>0){let a=!1;for(let d of t)d in p&&(delete p[d],a=!0);a&&(s.children[0].text=l.stringify(p).trim())}if(Object.keys(p).length===0)return null}),r.name&&(r.displayName=r.name,delete r.name),r}async function S(){let e=await c.getText(),t=await f.parseMarkdown(e),{$share:r}=O(t);if(!r){await c.flashNotification(\"Not currently shared as gist\",\"error\");return}for(let i of r)if(i.startsWith(\"gh-gist:\")){let s=`https://gist.github.com/${i.split(\":\")[1]}`;await c.openUrl(s);return}await c.flashNotification(\"Not currently shared as gist\",\"error\")}var he=S;return U(xe);})();\n return mod;})()" 48 | }, 49 | "createGist": { 50 | "env": "server", 51 | "code": "(() => { var mod=(()=>{var E=Object.create;var c=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var h=(r=>typeof require!=\"undefined\"?require:typeof Proxy!=\"undefined\"?new Proxy(r,{get:(e,t)=>(typeof require!=\"undefined\"?require:e)[t]}):r)(function(r){if(typeof require!=\"undefined\")return require.apply(this,arguments);throw new Error('Dynamic require of \"'+r+'\" is not supported')});var x=(r,e)=>{for(var t in e)c(r,t,{get:e[t],enumerable:!0})},w=(r,e,t,n)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of $(e))!S.call(r,o)&&o!==t&&c(r,o,{get:()=>e[o],enumerable:!(n=F(e,o))||n.enumerable});return r};var v=(r,e,t)=>(t=r!=null?E(O(r)):{},w(e||!r||!r.__esModule?c(t,\"default\",{value:r,enumerable:!0}):t,r)),I=r=>w(c({},\"__esModule\",{value:!0}),r);var B={};x(B,{default:()=>q});function p(r,e){if(e(r))return[r];let t=[];if(r.children)for(let n of r.children)t=[...t,...p(n,e)];return t}function l(r,e){return p(r,t=>t.type===e)[0]}function d(r,e){p(r,e)}typeof self>\"u\"&&(self={syscall:()=>{throw new Error(\"Not implemented here\")}});var i=self.syscall;var a={};x(a,{parseMarkdown:()=>G});function G(r){return i(\"markdown.parseMarkdown\",r)}var m=class{listPages(e=!1){return i(\"space.listPages\",e)}getPageMeta(e){return i(\"space.getPageMeta\",e)}readPage(e){return i(\"space.readPage\",e)}writePage(e,t){return i(\"space.writePage\",e,t)}deletePage(e){return i(\"space.deletePage\",e)}listPlugs(){return i(\"space.listPlugs\")}listAttachments(){return i(\"space.listAttachments\")}getAttachmentMeta(e){return i(\"space.getAttachmentMeta\",e)}readAttachment(e){return i(\"space.readAttachment\",e)}writeAttachment(e,t,n){return i(\"space.writeAttachment\",e,t,n)}deleteAttachment(e){return i(\"space.deleteAttachment\",e)}readFile(e,t){return i(\"space.readFile\",e,t)}getFileMeta(e){return i(\"space.getFileMeta\",e)}writeFile(e,t,n){return i(\"space.writeFile\",e,t,n)}deleteFile(e){return i(\"space.deleteFile\",e)}listFiles(e){return i(\"space.listFiles\",e)}},u=new m;var g=v(h(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function j(r,e){let t=await u.readPage(r),n=await a.parseMarkdown(t),o;return d(n,f=>{if(f.type!==\"FencedCode\")return!1;let P=l(f,\"CodeInfo\");if(e&&!P||e&&!e.includes(P.children[0].text))return!1;let y=l(f,\"CodeText\");return y?(o=y.children[0].text,!0):!1}),o}async function C(r,e=[\"yaml\"]){let t=await j(r,e);if(t!==void 0)try{return g.parse(t)}catch(n){throw console.error(\"YAML Page parser error\",n),new Error(`YAML Error: ${n.message}`)}}async function M(r){try{let e=await C(\"SECRETS\",[\"yaml\",\"secrets\"]),t=[];for(let n of r){let o=e[n];if(o)t.push(o);else throw new Error(`No such secret: ${n}`)}return t}catch(e){throw e.message===\"Page not found\"?new Error(`No such secret: ${r[0]}`):e}}async function Q(){try{let[r]=await M([\"githubToken\"]);return r}catch{console.error(\"No github-config page found, using default config\");return}}var s=class{constructor(e){this.token=e}async apiCall(e,t={}){let n=await fetch(e,{...t,headers:{Authorization:this.token?`token ${this.token}`:void 0}});if(n.status<200||n.status>=300)throw new Error(await n.text());return n.json()}listEvents(e){return this.apiCall(`https://api.github.com/users/${e}/events?per_page=100`)}listPulls(e,t=\"all\",n=\"updated\"){return this.apiCall(`https://api.github.com/repos/${e}/pulls?state=${t}&sort=${n}&direction=desc&per_page=100`)}searchIssues(e,t=\"\"){return e=encodeURIComponent(e),this.apiCall(`https://api.github.com/search/issues?q=${e}&sort=${t}&direction=desc&per_page=100`)}listNotifications(){return this.apiCall(\"https://api.github.com/notifications?per_page=100\")}async createGist(e,t,n){return(await this.apiCall(\"https://api.github.com/gists\",{method:\"POST\",body:JSON.stringify({description:e,public:t,files:n})})).id}updateGist(e,t,n,o){return this.apiCall(`https://api.github.com/gists/${e}`,{method:\"PATCH\",body:JSON.stringify({description:t,public:n,files:o})})}async getGist(e){return(await this.apiCall(`https://api.github.com/gists/${e}`)).files}static async fromConfig(){return new s(await Q())}};var k=v(h(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function N(r,e){return(await s.fromConfig()).createGist(\"\",!0,{[`${r}.md`]:{content:e}})}var q=N;return I(B);})();\n return mod;})()" 52 | }, 53 | "updateGist": { 54 | "env": "server", 55 | "events": [ 56 | "share:gh-gist" 57 | ], 58 | "code": "(() => { var mod=(()=>{var D=Object.create;var w=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var E=(r=>typeof require!=\"undefined\"?require:typeof Proxy!=\"undefined\"?new Proxy(r,{get:(e,t)=>(typeof require!=\"undefined\"?require:e)[t]}):r)(function(r){if(typeof require!=\"undefined\")return require.apply(this,arguments);throw new Error('Dynamic require of \"'+r+'\" is not supported')});var F=(r,e)=>{for(var t in e)w(r,t,{get:e[t],enumerable:!0})},$=(r,e,t,n)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of j(e))!q.call(r,i)&&i!==t&&w(r,i,{get:()=>e[i],enumerable:!(n=U(e,i))||n.enumerable});return r};var O=(r,e,t)=>(t=r!=null?D(Q(r)):{},$(e||!r||!r.__esModule?w(t,\"default\",{value:r,enumerable:!0}):t,r)),B=r=>$(w({},\"__esModule\",{value:!0}),r);var K={};F(K,{default:()=>Z});function T(r){if(!!r.children)for(let e of r.children){if(e.parent)return;e.parent=r,T(e)}}function b(r,e){if(e(r))return[r];let t=[];if(r.children)for(let n of r.children)t=[...t,...b(n,e)];return t}function v(r,e){if(r.children){let t=r.children.slice();for(let n of t){let i=e(n);if(i!==void 0){let s=r.children.indexOf(n);i?r.children.splice(s,1,i):r.children.splice(s,1)}else v(n,e)}}}function c(r,e){return b(r,t=>t.type===e)[0]}function A(r,e){b(r,e)}function l(r){let e=[];if(r.text!==void 0)return r.text;for(let t of r.children)e.push(l(t));return e.join(\"\")}typeof self>\"u\"&&(self={syscall:()=>{throw new Error(\"Not implemented here\")}});var o=self.syscall;var u={};F(u,{parseMarkdown:()=>H});function H(r){return o(\"markdown.parseMarkdown\",r)}var C=class{listPages(e=!1){return o(\"space.listPages\",e)}getPageMeta(e){return o(\"space.getPageMeta\",e)}readPage(e){return o(\"space.readPage\",e)}writePage(e,t){return o(\"space.writePage\",e,t)}deletePage(e){return o(\"space.deletePage\",e)}listPlugs(){return o(\"space.listPlugs\")}listAttachments(){return o(\"space.listAttachments\")}getAttachmentMeta(e){return o(\"space.getAttachmentMeta\",e)}readAttachment(e){return o(\"space.readAttachment\",e)}writeAttachment(e,t,n){return o(\"space.writeAttachment\",e,t,n)}deleteAttachment(e){return o(\"space.deleteAttachment\",e)}readFile(e,t){return o(\"space.readFile\",e,t)}getFileMeta(e){return o(\"space.getFileMeta\",e)}writeFile(e,t,n){return o(\"space.writeFile\",e,t,n)}deleteFile(e){return o(\"space.deleteFile\",e)}listFiles(e){return o(\"space.listFiles\",e)}},m=new C;var M=O(E(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function z(r,e){let t=await m.readPage(r),n=await u.parseMarkdown(t),i;return A(n,s=>{if(s.type!==\"FencedCode\")return!1;let g=c(s,\"CodeInfo\");if(e&&!g||e&&!e.includes(g.children[0].text))return!1;let d=c(s,\"CodeText\");return d?(i=d.children[0].text,!0):!1}),i}async function L(r,e=[\"yaml\"]){let t=await z(r,e);if(t!==void 0)try{return M.parse(t)}catch(n){throw console.error(\"YAML Page parser error\",n),new Error(`YAML Error: ${n.message}`)}}async function R(r){try{let e=await L(\"SECRETS\",[\"yaml\",\"secrets\"]),t=[];for(let n of r){let i=e[n];if(i)t.push(i);else throw new Error(`No such secret: ${n}`)}return t}catch(e){throw e.message===\"Page not found\"?new Error(`No such secret: ${r[0]}`):e}}async function X(){try{let[r]=await R([\"githubToken\"]);return r}catch{console.error(\"No github-config page found, using default config\");return}}var f=class{constructor(e){this.token=e}async apiCall(e,t={}){let n=await fetch(e,{...t,headers:{Authorization:this.token?`token ${this.token}`:void 0}});if(n.status<200||n.status>=300)throw new Error(await n.text());return n.json()}listEvents(e){return this.apiCall(`https://api.github.com/users/${e}/events?per_page=100`)}listPulls(e,t=\"all\",n=\"updated\"){return this.apiCall(`https://api.github.com/repos/${e}/pulls?state=${t}&sort=${n}&direction=desc&per_page=100`)}searchIssues(e,t=\"\"){return e=encodeURIComponent(e),this.apiCall(`https://api.github.com/search/issues?q=${e}&sort=${t}&direction=desc&per_page=100`)}listNotifications(){return this.apiCall(\"https://api.github.com/notifications?per_page=100\")}async createGist(e,t,n){return(await this.apiCall(\"https://api.github.com/gists\",{method:\"POST\",body:JSON.stringify({description:e,public:t,files:n})})).id}updateGist(e,t,n,i){return this.apiCall(`https://api.github.com/gists/${e}`,{method:\"PATCH\",body:JSON.stringify({description:t,public:n,files:i})})}async getGist(e){return(await this.apiCall(`https://api.github.com/gists/${e}`)).files}static async fromConfig(){return new f(await X())}};var p=O(E(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));function Y(r,e=[]){let t={};return T(r),v(r,n=>{if(n.type===\"Hashtag\"){if(n.parent&&n.parent.type===\"Paragraph\"){let a=n.children[0].text.substring(1);t.tags||(t.tags=[]),Array.isArray(t.tags)&&!t.tags.includes(a)&&t.tags.push(a)}return}if(n.type===\"FrontMatter\"){let a=n.children[1].children[0],y=l(a);try{let h=p.parse(y),x={...h};if(t={...t,...h},e.length>0){let k=!1;for(let N of e)N in x&&(delete x[N],k=!0);k&&(a.text=p.stringify(x))}if(Object.keys(x).length===0)return null}catch(h){console.error(\"Could not parse frontmatter\",h)}}if(n.type!==\"FencedCode\")return;let i=c(n,\"CodeInfo\");if(!i||i.children[0].text!==\"meta\")return;let s=c(n,\"CodeText\");if(!s)return;let g=s.children[0].text,d=p.parse(g),P={...d};if(t={...t,...d},e.length>0){let a=!1;for(let y of e)y in P&&(delete P[y],a=!0);a&&(s.children[0].text=p.stringify(P).trim())}if(Object.keys(P).length===0)return null}),t.name&&(t.displayName=t.name,delete t.name),t}async function G(r){let e=r.uri.split(\":\")[1],t=await f.fromConfig(),n=await m.readPage(r.name),i=await u.parseMarkdown(n);Y(i,[\"$share\"]);let s=l(i);return await t.updateGist(e,\"\",!0,{[`${r.name}.md`]:{content:s}}),!0}var Z=G;return B(K);})();\n return mod;})()" 59 | }, 60 | "getGist": { 61 | "env": "server", 62 | "code": "(() => { var mod=(()=>{var E=Object.create;var c=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var h=(r=>typeof require!=\"undefined\"?require:typeof Proxy!=\"undefined\"?new Proxy(r,{get:(e,t)=>(typeof require!=\"undefined\"?require:e)[t]}):r)(function(r){if(typeof require!=\"undefined\")return require.apply(this,arguments);throw new Error('Dynamic require of \"'+r+'\" is not supported')});var x=(r,e)=>{for(var t in e)c(r,t,{get:e[t],enumerable:!0})},w=(r,e,t,n)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of $(e))!S.call(r,o)&&o!==t&&c(r,o,{get:()=>e[o],enumerable:!(n=F(e,o))||n.enumerable});return r};var v=(r,e,t)=>(t=r!=null?E(O(r)):{},w(e||!r||!r.__esModule?c(t,\"default\",{value:r,enumerable:!0}):t,r)),I=r=>w(c({},\"__esModule\",{value:!0}),r);var B={};x(B,{default:()=>q});function p(r,e){if(e(r))return[r];let t=[];if(r.children)for(let n of r.children)t=[...t,...p(n,e)];return t}function l(r,e){return p(r,t=>t.type===e)[0]}function d(r,e){p(r,e)}typeof self>\"u\"&&(self={syscall:()=>{throw new Error(\"Not implemented here\")}});var i=self.syscall;var a={};x(a,{parseMarkdown:()=>G});function G(r){return i(\"markdown.parseMarkdown\",r)}var m=class{listPages(e=!1){return i(\"space.listPages\",e)}getPageMeta(e){return i(\"space.getPageMeta\",e)}readPage(e){return i(\"space.readPage\",e)}writePage(e,t){return i(\"space.writePage\",e,t)}deletePage(e){return i(\"space.deletePage\",e)}listPlugs(){return i(\"space.listPlugs\")}listAttachments(){return i(\"space.listAttachments\")}getAttachmentMeta(e){return i(\"space.getAttachmentMeta\",e)}readAttachment(e){return i(\"space.readAttachment\",e)}writeAttachment(e,t,n){return i(\"space.writeAttachment\",e,t,n)}deleteAttachment(e){return i(\"space.deleteAttachment\",e)}readFile(e,t){return i(\"space.readFile\",e,t)}getFileMeta(e){return i(\"space.getFileMeta\",e)}writeFile(e,t,n){return i(\"space.writeFile\",e,t,n)}deleteFile(e){return i(\"space.deleteFile\",e)}listFiles(e){return i(\"space.listFiles\",e)}},u=new m;var g=v(h(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function j(r,e){let t=await u.readPage(r),n=await a.parseMarkdown(t),o;return d(n,f=>{if(f.type!==\"FencedCode\")return!1;let P=l(f,\"CodeInfo\");if(e&&!P||e&&!e.includes(P.children[0].text))return!1;let y=l(f,\"CodeText\");return y?(o=y.children[0].text,!0):!1}),o}async function C(r,e=[\"yaml\"]){let t=await j(r,e);if(t!==void 0)try{return g.parse(t)}catch(n){throw console.error(\"YAML Page parser error\",n),new Error(`YAML Error: ${n.message}`)}}async function M(r){try{let e=await C(\"SECRETS\",[\"yaml\",\"secrets\"]),t=[];for(let n of r){let o=e[n];if(o)t.push(o);else throw new Error(`No such secret: ${n}`)}return t}catch(e){throw e.message===\"Page not found\"?new Error(`No such secret: ${r[0]}`):e}}async function Q(){try{let[r]=await M([\"githubToken\"]);return r}catch{console.error(\"No github-config page found, using default config\");return}}var s=class{constructor(e){this.token=e}async apiCall(e,t={}){let n=await fetch(e,{...t,headers:{Authorization:this.token?`token ${this.token}`:void 0}});if(n.status<200||n.status>=300)throw new Error(await n.text());return n.json()}listEvents(e){return this.apiCall(`https://api.github.com/users/${e}/events?per_page=100`)}listPulls(e,t=\"all\",n=\"updated\"){return this.apiCall(`https://api.github.com/repos/${e}/pulls?state=${t}&sort=${n}&direction=desc&per_page=100`)}searchIssues(e,t=\"\"){return e=encodeURIComponent(e),this.apiCall(`https://api.github.com/search/issues?q=${e}&sort=${t}&direction=desc&per_page=100`)}listNotifications(){return this.apiCall(\"https://api.github.com/notifications?per_page=100\")}async createGist(e,t,n){return(await this.apiCall(\"https://api.github.com/gists\",{method:\"POST\",body:JSON.stringify({description:e,public:t,files:n})})).id}updateGist(e,t,n,o){return this.apiCall(`https://api.github.com/gists/${e}`,{method:\"PATCH\",body:JSON.stringify({description:t,public:n,files:o})})}async getGist(e){return(await this.apiCall(`https://api.github.com/gists/${e}`)).files}static async fromConfig(){return new s(await Q())}};var k=v(h(\"https://deno.land/std@0.184.0/yaml/mod.ts\"));async function N(r){return(await s.fromConfig()).getGist(r)}var q=N;return I(B);})();\n return mod;})()" 63 | } 64 | }, 65 | "assets": {} 66 | } --------------------------------------------------------------------------------