feat: allow organization members in webhook chat
This commit is contained in:
1 parent
3adf4a41a2
commit
625ba79dbb
5 files changed
+82
-5
No files matched your search
@@ -5,6 +5,7 @@ import { Readable } from "node:stream";
|
||||
import test from "node:test";
|
||||
import {
|
||||
buildWebhookChatPrompt,
|
||||
getCommenterPermission,
|
||||
parseWebhookMentionEvent,
|
||||
webhookPermissionAllows
|
||||
} from "../src/webhook/processor.js";
|
||||
@@ -138,6 +139,8 @@ test("Webhook event parsing only accepts supported mentions and preserves PR con
|
||||
|
||||
test("Webhook permission policy is explicit", () => {
|
||||
assert.equal(webhookPermissionAllows(null, "anyone"), true);
|
||||
assert.equal(webhookPermissionAllows("organization", "read"), true);
|
||||
assert.equal(webhookPermissionAllows("organization", "write"), false);
|
||||
assert.equal(webhookPermissionAllows("read", "read"), true);
|
||||
assert.equal(webhookPermissionAllows("triage", "read"), true);
|
||||
assert.equal(webhookPermissionAllows("read", "write"), false);
|
||||
@@ -145,6 +148,48 @@ test("Webhook permission policy is explicit", () => {
|
||||
assert.equal(webhookPermissionAllows(null, "read"), false);
|
||||
});
|
||||
|
||||
test("organization members can use webhook chat without repository collaborator access", async () => {
|
||||
const calls: string[] = [];
|
||||
const octokit = {
|
||||
rest: {
|
||||
repos: {
|
||||
get: async () => {
|
||||
calls.push("repo");
|
||||
return { data: { owner: { type: "Organization" } } };
|
||||
},
|
||||
getCollaboratorPermissionLevel: async () => {
|
||||
calls.push("collaborator");
|
||||
return { data: { permission: null } };
|
||||
}
|
||||
},
|
||||
orgs: {
|
||||
checkMembershipForUser: async () => {
|
||||
calls.push("membership");
|
||||
return { status: 204 };
|
||||
}
|
||||
}
|
||||
}
|
||||
} as any;
|
||||
|
||||
const permission = await getCommenterPermission(octokit, {
|
||||
eventName: "issue_comment",
|
||||
action: "created",
|
||||
deliveryId: "delivery-org-member",
|
||||
installationId: 12345,
|
||||
owner: "acme",
|
||||
repo: "demo",
|
||||
issueNumber: 7,
|
||||
targetKind: "issue",
|
||||
sourceCommentId: 88,
|
||||
commentBody: "@bot help",
|
||||
commenterLogin: "alice",
|
||||
replyMode: "conversation"
|
||||
});
|
||||
|
||||
assert.equal(permission, "organization");
|
||||
assert.deepEqual(calls, ["repo", "membership"]);
|
||||
});
|
||||
|
||||
test("Webhook server returns health, verifies signatures, queues asynchronously, and deduplicates deliveries", async () => {
|
||||
const handled: string[] = [];
|
||||
let resolveHandler: (() => void) | undefined;
|
||||
|
||||
Reference in new issue
Block a user