MCPcopy Create free account
hub / github.com/github/awesome-copilot / upsertExternalPlugin

Function upsertExternalPlugin

eng/external-plugin-approval.mjs:104–146  ·  view source on GitHub ↗
(plugin, { filePath = EXTERNAL_PLUGINS_FILE } = {})

Source from the content-addressed store, hash-verified

102}
103
104export function upsertExternalPlugin(plugin, { filePath = EXTERNAL_PLUGINS_FILE } = {}) {
105 const { plugins, errors } = readExternalPlugins({
106 filePath,
107 localPluginNames: readLocalPluginNames(),
108 policy: "marketplace",
109 });
110
111 if (errors.length > 0) {
112 throw new Error(errors.join("\n"));
113 }
114
115 const updatedPlugins = [...plugins];
116 const existingIndex = updatedPlugins.findIndex((existingPlugin) => pluginsMatch(existingPlugin, plugin));
117 const action = existingIndex === -1 ? "inserted" : "updated";
118
119 if (existingIndex === -1) {
120 updatedPlugins.push(plugin);
121 } else {
122 updatedPlugins[existingIndex] = plugin;
123 }
124
125 updatedPlugins.sort((left, right) => left.name.localeCompare(right.name, undefined, { sensitivity: "base" }));
126
127 const { errors: validationErrors } = validateExternalPlugins(updatedPlugins, {
128 localPluginNames: readLocalPluginNames(),
129 policy: "marketplace",
130 });
131
132 if (validationErrors.length > 0) {
133 throw new Error(validationErrors.join("\n"));
134 }
135
136 const changed = JSON.stringify(updatedPlugins) !== JSON.stringify(plugins);
137 if (changed) {
138 fs.writeFileSync(filePath, `${JSON.stringify(updatedPlugins, null, 2)}\n`);
139 }
140
141 return {
142 action,
143 changed,
144 plugin,
145 };
146}
147
148function readCliArgs(argv) {
149 const args = {};

Callers 1

Calls 4

readExternalPluginsFunction · 0.90
validateExternalPluginsFunction · 0.90
pluginsMatchFunction · 0.85
readLocalPluginNamesFunction · 0.70

Tested by

no test coverage detected