Skip to content

Commit

Permalink
Merge branch 'refs/heads/fix/multiple-commands-per-plugin' into feat/…
Browse files Browse the repository at this point in the history
…runs-on
  • Loading branch information
gentlementlegen committed Jul 21, 2024
2 parents 92b8bf2 + 7b3e111 commit 7b21ae4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/github/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { repositoryDispatch } from "./repository-dispatch";
import { dispatchWorker, dispatchWorkflow, getDefaultBranch } from "../utils/workflow-dispatch";
import { PluginInput } from "../types/plugin";
import { isGithubPlugin, PluginConfiguration } from "../types/plugin-configuration";
import { getPluginsForEvent } from "../utils/plugins";
import { getManifest, getPluginsForEvent } from "../utils/plugins";

function tryCatchWrapper(fn: (event: EmitterWebhookEvent) => unknown) {
return async (event: EmitterWebhookEvent) => {
Expand All @@ -25,19 +25,21 @@ export function bindHandlers(eventHandler: GitHubEventHandler) {
eventHandler.onAny(tryCatchWrapper((event) => handleEvent(event, eventHandler))); // onAny should also receive GithubContext but the types in octokit/webhooks are weird
}

function shouldSkipPlugin(event: EmitterWebhookEvent, context: GitHubContext, pluginChain: PluginConfiguration["plugins"][0]) {
async function shouldSkipPlugin(event: EmitterWebhookEvent, context: GitHubContext, pluginChain: PluginConfiguration["plugins"][0]) {
if (pluginChain.skipBotEvents && "sender" in event.payload && event.payload.sender?.type === "Bot") {
console.log("Skipping plugin chain because sender is a bot");
return true;
}
const manifest = await getManifest(context, pluginChain.uses[0].plugin);
if (
context.key === "issue_comment.created" &&
pluginChain.command &&
"comment" in context.payload &&
typeof context.payload.comment !== "string" &&
!context.payload.comment?.body.startsWith(pluginChain.command)
manifest &&
!Object.keys(manifest.commands).some(
(command) => "comment" in context.payload && typeof context.payload.comment !== "string" && context.payload.comment?.body.startsWith(command)
)
) {
console.log("Skipping plugin chain because command does not match");
console.log(`Skipping plugin chain ${pluginChain.command} because command does not match`);
return true;
}
return false;
Expand Down Expand Up @@ -66,7 +68,7 @@ async function handleEvent(event: EmitterWebhookEvent, eventHandler: InstanceTyp
}

for (const pluginChain of pluginChains) {
if (shouldSkipPlugin(event, context, pluginChain)) {
if (await shouldSkipPlugin(event, context, pluginChain)) {
continue;
}

Expand All @@ -87,7 +89,7 @@ async function handleEvent(event: EmitterWebhookEvent, eventHandler: InstanceTyp
inputs: new Array(pluginChain.uses.length),
};

const ref = isGithubPluginObject ? plugin.ref ?? (await getDefaultBranch(context, plugin.owner, plugin.repo)) : plugin;
const ref = isGithubPluginObject ? (plugin.ref ?? (await getDefaultBranch(context, plugin.owner, plugin.repo))) : plugin;
const token = await eventHandler.getToken(event.payload.installation.id);
const inputs = new PluginInput(context.eventHandler, stateId, context.key, event.payload, settings, token, ref);

Expand Down

0 comments on commit 7b21ae4

Please sign in to comment.