diff --git a/src/github/utils/plugins.ts b/src/github/utils/plugins.ts index 2464287..164e74c 100644 --- a/src/github/utils/plugins.ts +++ b/src/github/utils/plugins.ts @@ -5,6 +5,8 @@ import { Manifest, manifestSchema } from "@ubiquity-os/plugin-sdk/manifest"; import { Buffer } from "node:buffer"; import { Value } from "@sinclair/typebox/value"; +const _manifestCache: Record = {}; + export function getPluginsForEvent(plugins: PluginConfiguration["plugins"], event: EmitterWebhookEventName) { return plugins.filter((plugin) => { return plugin.uses?.[0].runsOn?.includes(event); @@ -16,6 +18,10 @@ export function getManifest(context: GitHubContext, plugin: string | GithubPlugi } async function fetchActionManifest(context: GitHubContext<"issue_comment.created">, { owner, repo, ref }: GithubPlugin): Promise { + const manifestKey = ref ? `${owner}:${repo}:${ref}` : `${owner}:${repo}`; + if (_manifestCache[manifestKey]) { + return _manifestCache[manifestKey]; + } try { const { data } = await context.octokit.rest.repos.getContent({ owner, @@ -26,7 +32,9 @@ async function fetchActionManifest(context: GitHubContext<"issue_comment.created if ("content" in data) { const content = Buffer.from(data.content, "base64").toString(); const contentParsed = JSON.parse(content); - return decodeManifest(contentParsed); + const manifest = decodeManifest(contentParsed); + _manifestCache[manifestKey] = manifest; + return manifest; } } catch (e) { console.warn(`Could not find a manifest for Action ${owner}/${repo}: ${e}`); @@ -35,11 +43,16 @@ async function fetchActionManifest(context: GitHubContext<"issue_comment.created } async function fetchWorkerManifest(url: string): Promise { + if (_manifestCache[url]) { + return _manifestCache[url]; + } const manifestUrl = `${url}/manifest.json`; try { const result = await fetch(manifestUrl); const jsonData = await result.json(); - return decodeManifest(jsonData); + const manifest = decodeManifest(jsonData); + _manifestCache[url] = manifest; + return manifest; } catch (e) { console.warn(`Could not find a manifest for Worker ${manifestUrl}: ${e}`); }