mirror of
https://github.com/markwylde/claude-code-gitea-action.git
synced 2026-08-01 11:12:59 +08:00
chore: format gitea branch
This commit is contained in:
@@ -97,7 +97,9 @@ describe("checkAndDeleteEmptyBranch", () => {
|
||||
});
|
||||
|
||||
test("falls back to branch link when API call fails", async () => {
|
||||
const client = createMockClient({ error: Object.assign(new Error("boom"), { status: 500 }) });
|
||||
const client = createMockClient({
|
||||
error: Object.assign(new Error("boom"), { status: 500 }),
|
||||
});
|
||||
const result = await checkAndDeleteEmptyBranch(
|
||||
client,
|
||||
"owner",
|
||||
|
||||
@@ -140,8 +140,7 @@ describe("updateCommentBody", () => {
|
||||
it("removes old branch links from body", () => {
|
||||
const input = {
|
||||
...baseInput,
|
||||
currentBody:
|
||||
`Some comment with [View branch](${BRANCH_BASE_URL}/branch-name)` ,
|
||||
currentBody: `Some comment with [View branch](${BRANCH_BASE_URL}/branch-name)`,
|
||||
branchName: "new-branch-name",
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ describe("GITEA_SERVER_URL configuration", () => {
|
||||
process.env = { ...originalEnv };
|
||||
delete process.env.GITEA_SERVER_URL;
|
||||
delete process.env.GITHUB_SERVER_URL;
|
||||
|
||||
|
||||
// Clear module cache to force re-evaluation
|
||||
delete require.cache[require.resolve("../src/github/api/config")];
|
||||
});
|
||||
@@ -61,23 +61,35 @@ describe("GITEA_SERVER_URL configuration", () => {
|
||||
|
||||
it("should create correct job run links with custom GITEA_SERVER_URL", async () => {
|
||||
process.env.GITEA_SERVER_URL = "https://gitea.example.com";
|
||||
|
||||
|
||||
// Clear module cache and re-import
|
||||
delete require.cache[require.resolve("../src/github/operations/comments/common")];
|
||||
const { createJobRunLink } = await import("../src/github/operations/comments/common");
|
||||
|
||||
delete require.cache[
|
||||
require.resolve("../src/github/operations/comments/common")
|
||||
];
|
||||
const { createJobRunLink } = await import(
|
||||
"../src/github/operations/comments/common"
|
||||
);
|
||||
|
||||
const link = createJobRunLink("owner", "repo", "123");
|
||||
expect(link).toBe("[View job run](https://gitea.example.com/owner/repo/actions/runs/123)");
|
||||
expect(link).toBe(
|
||||
"[View job run](https://gitea.example.com/owner/repo/actions/runs/123)",
|
||||
);
|
||||
});
|
||||
|
||||
it("should create correct branch links with custom GITEA_SERVER_URL", async () => {
|
||||
process.env.GITEA_SERVER_URL = "https://gitea.example.com";
|
||||
|
||||
|
||||
// Clear module cache and re-import
|
||||
delete require.cache[require.resolve("../src/github/operations/comments/common")];
|
||||
const { createBranchLink } = await import("../src/github/operations/comments/common");
|
||||
|
||||
delete require.cache[
|
||||
require.resolve("../src/github/operations/comments/common")
|
||||
];
|
||||
const { createBranchLink } = await import(
|
||||
"../src/github/operations/comments/common"
|
||||
);
|
||||
|
||||
const link = createBranchLink("owner", "repo", "feature-branch");
|
||||
expect(link).toBe("\n[View branch](https://gitea.example.com/owner/repo/src/branch/feature-branch/)");
|
||||
expect(link).toBe(
|
||||
"\n[View branch](https://gitea.example.com/owner/repo/src/branch/feature-branch/)",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -40,7 +40,12 @@ describe("downloadCommentImages", () => {
|
||||
},
|
||||
];
|
||||
|
||||
const result = await downloadCommentImages(noopClient, "owner", "repo", comments);
|
||||
const result = await downloadCommentImages(
|
||||
noopClient,
|
||||
"owner",
|
||||
"repo",
|
||||
comments,
|
||||
);
|
||||
|
||||
expect(result.size).toBe(0);
|
||||
expect(consoleLogSpy).toHaveBeenCalled();
|
||||
|
||||
@@ -52,7 +52,9 @@ describe("checkWritePermissions", () => {
|
||||
});
|
||||
|
||||
test("returns true immediately in Gitea environments", async () => {
|
||||
const client = { api: { getBaseUrl: () => "https://gitea.example.com/api/v1" } } as any;
|
||||
const client = {
|
||||
api: { getBaseUrl: () => "https://gitea.example.com/api/v1" },
|
||||
} as any;
|
||||
const result = await checkWritePermissions(client, baseContext);
|
||||
|
||||
expect(result).toBe(true);
|
||||
|
||||
@@ -70,11 +70,7 @@ describe("parseEnvVarsWithContext", () => {
|
||||
});
|
||||
|
||||
test("should allow missing CLAUDE_BRANCH and omit it from event data", () => {
|
||||
const result = prepareContext(
|
||||
mockIssueCommentContext,
|
||||
"12345",
|
||||
"main",
|
||||
);
|
||||
const result = prepareContext(mockIssueCommentContext, "12345", "main");
|
||||
|
||||
if (
|
||||
result.eventData.eventName === "issue_comment" &&
|
||||
|
||||
@@ -417,9 +417,7 @@ describe("checkContainsTrigger", () => {
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [
|
||||
{ login: "claude", id: 1, type: "User" },
|
||||
],
|
||||
requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
|
||||
},
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
@@ -491,9 +489,7 @@ describe("checkContainsTrigger", () => {
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [
|
||||
{ login: "claude", id: 1, type: "User" },
|
||||
],
|
||||
requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
|
||||
},
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
@@ -516,426 +512,422 @@ describe("checkContainsTrigger", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should return true when PR has trigger user as requested reviewer for synchronized event", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "synchronized",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "synchronized",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [
|
||||
{ login: "claude", id: 1, type: "User" },
|
||||
],
|
||||
requested_teams: [],
|
||||
},
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
it("should return true when PR has trigger user as requested reviewer for synchronized event", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "synchronized",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "synchronized",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
|
||||
requested_teams: [],
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false when PR has no matching requested reviewers", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "opened",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "opened",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [
|
||||
{ login: "other-reviewer", id: 2, type: "User" },
|
||||
],
|
||||
requested_teams: [],
|
||||
},
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
});
|
||||
|
||||
it("should handle trigger phrase without @ symbol", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "opened",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "opened",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [
|
||||
{ login: "claude", id: 1, type: "User" },
|
||||
],
|
||||
requested_teams: [],
|
||||
},
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "claude", // No @ symbol
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle empty requested_reviewers and requested_teams arrays", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "opened",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "opened",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [],
|
||||
requested_teams: [],
|
||||
},
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
});
|
||||
|
||||
it("should handle missing requested_reviewers and requested_teams fields", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "opened",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "opened",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
// requested_reviewers and requested_teams are undefined
|
||||
},
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
describe("comment trigger", () => {
|
||||
it("should return true for issue_comment with trigger phrase", () => {
|
||||
const context = mockIssueCommentContext;
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for pull_request_review_comment with trigger phrase", () => {
|
||||
const context = mockPullRequestReviewCommentContext;
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for pull_request_review with submitted action and trigger phrase", () => {
|
||||
const context = mockPullRequestReviewContext;
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for pull_request_review with edited action and trigger phrase", () => {
|
||||
const context = {
|
||||
...mockPullRequestReviewContext,
|
||||
eventAction: "edited",
|
||||
payload: {
|
||||
...mockPullRequestReviewContext.payload,
|
||||
action: "edited",
|
||||
it("should return false when PR has no matching requested reviewers", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "opened",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "opened",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [
|
||||
{ login: "other-reviewer", id: 2, type: "User" },
|
||||
],
|
||||
requested_teams: [],
|
||||
},
|
||||
} as ParsedGitHubContext;
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false for pull_request_review with different action", () => {
|
||||
it("should handle trigger phrase without @ symbol", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "opened",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "opened",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
|
||||
requested_teams: [],
|
||||
},
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "claude", // No @ symbol
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle empty requested_reviewers and requested_teams arrays", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "opened",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "opened",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [],
|
||||
requested_teams: [],
|
||||
},
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
});
|
||||
|
||||
it("should handle missing requested_reviewers and requested_teams fields", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "opened",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "opened",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
// requested_reviewers and requested_teams are undefined
|
||||
},
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("comment trigger", () => {
|
||||
it("should return true for issue_comment with trigger phrase", () => {
|
||||
const context = mockIssueCommentContext;
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for pull_request_review_comment with trigger phrase", () => {
|
||||
const context = mockPullRequestReviewCommentContext;
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for pull_request_review with submitted action and trigger phrase", () => {
|
||||
const context = mockPullRequestReviewContext;
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for pull_request_review with edited action and trigger phrase", () => {
|
||||
const context = {
|
||||
...mockPullRequestReviewContext,
|
||||
eventAction: "edited",
|
||||
payload: {
|
||||
...mockPullRequestReviewContext.payload,
|
||||
action: "edited",
|
||||
},
|
||||
} as ParsedGitHubContext;
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false for pull_request_review with different action", () => {
|
||||
const context = {
|
||||
...mockPullRequestReviewContext,
|
||||
eventAction: "dismissed",
|
||||
payload: {
|
||||
...mockPullRequestReviewContext.payload,
|
||||
action: "dismissed",
|
||||
review: {
|
||||
...(mockPullRequestReviewContext.payload as PullRequestReviewEvent)
|
||||
.review,
|
||||
body: "/claude please review this PR",
|
||||
},
|
||||
},
|
||||
} as ParsedGitHubContext;
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
});
|
||||
|
||||
it("should handle pull_request_review with punctuation", () => {
|
||||
const baseContext = {
|
||||
...mockPullRequestReviewContext,
|
||||
inputs: {
|
||||
...mockPullRequestReviewContext.inputs,
|
||||
triggerPhrase: "@claude",
|
||||
},
|
||||
};
|
||||
|
||||
const testCases = [
|
||||
{ commentBody: "@claude, please review", expected: true },
|
||||
{ commentBody: "@claude. fix this", expected: true },
|
||||
{ commentBody: "@claude!", expected: true },
|
||||
{ commentBody: "claude@example.com", expected: false },
|
||||
{ commentBody: "claudette", expected: false },
|
||||
];
|
||||
|
||||
testCases.forEach(({ commentBody, expected }) => {
|
||||
const context = {
|
||||
...mockPullRequestReviewContext,
|
||||
eventAction: "dismissed",
|
||||
...baseContext,
|
||||
payload: {
|
||||
...mockPullRequestReviewContext.payload,
|
||||
action: "dismissed",
|
||||
...baseContext.payload,
|
||||
review: {
|
||||
...(mockPullRequestReviewContext.payload as PullRequestReviewEvent)
|
||||
.review,
|
||||
body: "/claude please review this PR",
|
||||
...(baseContext.payload as PullRequestReviewEvent).review,
|
||||
body: commentBody,
|
||||
},
|
||||
},
|
||||
} as ParsedGitHubContext;
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
});
|
||||
|
||||
it("should handle pull_request_review with punctuation", () => {
|
||||
const baseContext = {
|
||||
...mockPullRequestReviewContext,
|
||||
inputs: {
|
||||
...mockPullRequestReviewContext.inputs,
|
||||
triggerPhrase: "@claude",
|
||||
},
|
||||
};
|
||||
|
||||
const testCases = [
|
||||
{ commentBody: "@claude, please review", expected: true },
|
||||
{ commentBody: "@claude. fix this", expected: true },
|
||||
{ commentBody: "@claude!", expected: true },
|
||||
{ commentBody: "claude@example.com", expected: false },
|
||||
{ commentBody: "claudette", expected: false },
|
||||
];
|
||||
|
||||
testCases.forEach(({ commentBody, expected }) => {
|
||||
const context = {
|
||||
...baseContext,
|
||||
payload: {
|
||||
...baseContext.payload,
|
||||
review: {
|
||||
...(baseContext.payload as PullRequestReviewEvent).review,
|
||||
body: commentBody,
|
||||
},
|
||||
},
|
||||
} as ParsedGitHubContext;
|
||||
expect(checkContainsTrigger(context)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle comment trigger with punctuation", () => {
|
||||
const baseContext = {
|
||||
...mockIssueCommentContext,
|
||||
inputs: {
|
||||
...mockIssueCommentContext.inputs,
|
||||
triggerPhrase: "@claude",
|
||||
},
|
||||
};
|
||||
|
||||
const testCases = [
|
||||
{ commentBody: "@claude, please review", expected: true },
|
||||
{ commentBody: "@claude. fix this", expected: true },
|
||||
{ commentBody: "@claude!", expected: true },
|
||||
{ commentBody: "claude@example.com", expected: false },
|
||||
{ commentBody: "claudette", expected: false },
|
||||
];
|
||||
|
||||
testCases.forEach(({ commentBody, expected }) => {
|
||||
const context = {
|
||||
...baseContext,
|
||||
payload: {
|
||||
...baseContext.payload,
|
||||
comment: {
|
||||
...(baseContext.payload as IssueCommentEvent).comment,
|
||||
body: commentBody,
|
||||
},
|
||||
},
|
||||
} as ParsedGitHubContext;
|
||||
expect(checkContainsTrigger(context)).toBe(expected);
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("pull request review_requested action", () => {
|
||||
it("should return true when trigger user is requested as reviewer", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "review_requested",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "review_requested",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
|
||||
requested_teams: [],
|
||||
},
|
||||
requested_reviewer: { login: "claude", id: 1, type: "User" },
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
it("should handle comment trigger with punctuation", () => {
|
||||
const baseContext = {
|
||||
...mockIssueCommentContext,
|
||||
inputs: {
|
||||
...mockIssueCommentContext.inputs,
|
||||
triggerPhrase: "@claude",
|
||||
},
|
||||
};
|
||||
|
||||
it("should return false when different user is requested as reviewer", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "review_requested",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "review_requested",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [{ login: "john", id: 2, type: "User" }],
|
||||
requested_teams: [],
|
||||
},
|
||||
requested_reviewer: { login: "john", id: 2, type: "User" },
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
});
|
||||
const testCases = [
|
||||
{ commentBody: "@claude, please review", expected: true },
|
||||
{ commentBody: "@claude. fix this", expected: true },
|
||||
{ commentBody: "@claude!", expected: true },
|
||||
{ commentBody: "claude@example.com", expected: false },
|
||||
{ commentBody: "claudette", expected: false },
|
||||
];
|
||||
|
||||
it("should handle trigger phrase without @ symbol", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "review_requested",
|
||||
isPR: true,
|
||||
testCases.forEach(({ commentBody, expected }) => {
|
||||
const context = {
|
||||
...baseContext,
|
||||
payload: {
|
||||
action: "review_requested",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
|
||||
requested_teams: [],
|
||||
...baseContext.payload,
|
||||
comment: {
|
||||
...(baseContext.payload as IssueCommentEvent).comment,
|
||||
body: commentBody,
|
||||
},
|
||||
requested_reviewer: { login: "claude", id: 1, type: "User" },
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "claude", // no @ symbol
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
} as ParsedGitHubContext;
|
||||
expect(checkContainsTrigger(context)).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("non-matching events", () => {
|
||||
it("should return false for non-matching event type", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "push",
|
||||
eventAction: "created",
|
||||
payload: {} as any,
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
describe("pull request review_requested action", () => {
|
||||
it("should return true when trigger user is requested as reviewer", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "review_requested",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "review_requested",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
|
||||
requested_teams: [],
|
||||
},
|
||||
requested_reviewer: { login: "claude", id: 1, type: "User" },
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false when different user is requested as reviewer", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "review_requested",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "review_requested",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [{ login: "john", id: 2, type: "User" }],
|
||||
requested_teams: [],
|
||||
},
|
||||
requested_reviewer: { login: "john", id: 2, type: "User" },
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "@claude",
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
});
|
||||
|
||||
it("should handle trigger phrase without @ symbol", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "pull_request",
|
||||
eventAction: "review_requested",
|
||||
isPR: true,
|
||||
payload: {
|
||||
action: "review_requested",
|
||||
pull_request: {
|
||||
number: 123,
|
||||
title: "Test PR",
|
||||
body: "This PR fixes a bug",
|
||||
created_at: "2023-01-01T00:00:00Z",
|
||||
user: { login: "testuser" },
|
||||
requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
|
||||
requested_teams: [],
|
||||
},
|
||||
requested_reviewer: { login: "claude", id: 1, type: "User" },
|
||||
} as unknown as PullRequestEvent,
|
||||
inputs: {
|
||||
mode: "tag",
|
||||
triggerPhrase: "claude", // no @ symbol
|
||||
assigneeTrigger: "",
|
||||
labelTrigger: "",
|
||||
directPrompt: "",
|
||||
overridePrompt: "",
|
||||
allowedTools: [],
|
||||
disallowedTools: [],
|
||||
customInstructions: "",
|
||||
branchPrefix: "claude/",
|
||||
useStickyComment: false,
|
||||
additionalPermissions: new Map(),
|
||||
useCommitSigning: false,
|
||||
},
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("non-matching events", () => {
|
||||
it("should return false for non-matching event type", () => {
|
||||
const context = createMockContext({
|
||||
eventName: "push",
|
||||
eventAction: "created",
|
||||
payload: {} as any,
|
||||
});
|
||||
expect(checkContainsTrigger(context)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("escapeRegExp", () => {
|
||||
it("should escape special regex characters", () => {
|
||||
expect(escapeRegExp(".*+?^${}()|[]\\")).toBe(
|
||||
|
||||
Reference in New Issue
Block a user