Skip to content

Commit

Permalink
Merge pull request #110 from ubiquity/development
Browse files Browse the repository at this point in the history
Merge development into main
  • Loading branch information
gentlementlegen authored Sep 9, 2024
2 parents 9df4bdf + ab82b31 commit 7f1a0a1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/worker-delete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
- name: Enable corepack
run: corepack enable

- uses: oven-sh/setup-bun@v1

- uses: actions/checkout@v4

- name: Get Deleted Branch Name
Expand Down
2 changes: 1 addition & 1 deletion src/github/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function shouldSkipPlugin(event: EmitterWebhookEvent, context: GitHubConte
manifest?.commands &&
Object.keys(manifest.commands).length &&
!Object.keys(manifest.commands).some(
(command) => "comment" in context.payload && typeof context.payload.comment !== "string" && context.payload.comment?.body.startsWith(`/${command}`)
(command) => "comment" in context.payload && typeof context.payload.comment !== "string" && context.payload.comment?.body.trim().startsWith(`/${command}`)
)
) {
console.log(`Skipping plugin chain ${manifest.name} because command does not match.`, manifest.commands);
Expand Down
5 changes: 3 additions & 2 deletions src/github/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export function getManifest(context: GitHubContext, plugin: string | GithubPlugi
return isGithubPlugin(plugin) ? fetchActionManifest(context, plugin) : fetchWorkerManifest(plugin);
}

async function fetchActionManifest(context: GitHubContext<"issue_comment.created">, { owner, repo }: GithubPlugin): Promise<Manifest | null> {
const manifestKey = `${owner}:${repo}`;
async function fetchActionManifest(context: GitHubContext<"issue_comment.created">, { owner, repo, ref }: GithubPlugin): Promise<Manifest | null> {
const manifestKey = ref ? `${owner}:${repo}:${ref}` : `${owner}:${repo}`;
if (_manifestCache[manifestKey]) {
return _manifestCache[manifestKey];
}
Expand All @@ -27,6 +27,7 @@ async function fetchActionManifest(context: GitHubContext<"issue_comment.created
owner,
repo,
path: "manifest.json",
ref,
});
if ("content" in data) {
const content = Buffer.from(data.content, "base64").toString();
Expand Down
66 changes: 66 additions & 0 deletions tests/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "./__mocks__/webhooks";
import { getConfig } from "../src/github/utils/config";
import { GitHubContext } from "../src/github/github-context";
import { GitHubEventHandler } from "../src/github/github-event-handler";
import { getManifest } from "../src/github/utils/plugins";

config({ path: ".dev.vars" });

Expand Down Expand Up @@ -88,4 +89,69 @@ plugins:
skipBotEvents: true,
});
});
it("Should retrieve the configuration manifest from the proper branch if specified", async () => {
let repo = "ubiquibot-kernel";
let ref: string | undefined = "fork/pull/1";
const owner = "ubiquity";
const workflowId = "compute.yml";
const content: Record<string, object> = {
withRef: {
name: "plugin",
commands: {
command: {
description: "description",
"ubiquity:example": "example",
},
},
description: "",
"ubiquity:listeners": [],
},
withoutRef: {
name: "plugin-no-ref",
commands: {
command: {
description: "description",
"ubiquity:example": "example",
},
},
description: "",
"ubiquity:listeners": [],
},
};
function getContent({ ref }: Record<string, string>) {
return {
data: {
content: Buffer.from(JSON.stringify(ref ? content["withRef"] : content["withoutRef"])).toString("base64"),
},
};
}
let manifest = await getManifest(
{
octokit: {
rest: {
repos: {
getContent,
},
},
},
} as unknown as GitHubContext,
{ owner, repo, ref, workflowId }
);
expect(manifest).toEqual(content["withRef"]);
ref = undefined;
repo = "repo-2";
manifest = await getManifest(
{
octokit: {
rest: {
repos: {
getContent,
},
},
},
} as unknown as GitHubContext,
{ owner, repo, ref, workflowId }
);
expect(manifest).toEqual(content["withoutRef"]);
});
});

0 comments on commit 7f1a0a1

Please sign in to comment.