mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
Accept multiline input for allowed_tools and disallowed_tools (#168)
This commit is contained in:
11
README.md
11
README.md
@@ -347,8 +347,15 @@ Claude does **not** have access to execute arbitrary Bash commands by default. I
|
|||||||
```yaml
|
```yaml
|
||||||
- uses: anthropics/claude-code-action@beta
|
- uses: anthropics/claude-code-action@beta
|
||||||
with:
|
with:
|
||||||
allowed_tools: "Bash(npm install),Bash(npm run test),Edit,Replace,NotebookEditCell"
|
allowed_tools: |
|
||||||
disallowed_tools: "TaskOutput,KillTask"
|
Bash(npm install)
|
||||||
|
Bash(npm run test)
|
||||||
|
Edit
|
||||||
|
Replace
|
||||||
|
NotebookEditCell
|
||||||
|
disallowed_tools: |
|
||||||
|
TaskOutput
|
||||||
|
KillTask
|
||||||
# ... other inputs
|
# ... other inputs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -52,14 +52,8 @@ export function parseGitHubContext(): ParsedGitHubContext {
|
|||||||
inputs: {
|
inputs: {
|
||||||
triggerPhrase: process.env.TRIGGER_PHRASE ?? "@claude",
|
triggerPhrase: process.env.TRIGGER_PHRASE ?? "@claude",
|
||||||
assigneeTrigger: process.env.ASSIGNEE_TRIGGER ?? "",
|
assigneeTrigger: process.env.ASSIGNEE_TRIGGER ?? "",
|
||||||
allowedTools: (process.env.ALLOWED_TOOLS ?? "")
|
allowedTools: parseMultilineInput(process.env.ALLOWED_TOOLS ?? ""),
|
||||||
.split(",")
|
disallowedTools: parseMultilineInput(process.env.DISALLOWED_TOOLS ?? ""),
|
||||||
.map((tool) => tool.trim())
|
|
||||||
.filter((tool) => tool.length > 0),
|
|
||||||
disallowedTools: (process.env.DISALLOWED_TOOLS ?? "")
|
|
||||||
.split(",")
|
|
||||||
.map((tool) => tool.trim())
|
|
||||||
.filter((tool) => tool.length > 0),
|
|
||||||
customInstructions: process.env.CUSTOM_INSTRUCTIONS ?? "",
|
customInstructions: process.env.CUSTOM_INSTRUCTIONS ?? "",
|
||||||
directPrompt: process.env.DIRECT_PROMPT ?? "",
|
directPrompt: process.env.DIRECT_PROMPT ?? "",
|
||||||
baseBranch: process.env.BASE_BRANCH,
|
baseBranch: process.env.BASE_BRANCH,
|
||||||
@@ -116,6 +110,14 @@ export function parseGitHubContext(): ParsedGitHubContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function parseMultilineInput(s: string): string[] {
|
||||||
|
return s
|
||||||
|
.split(/,|[\n\r]+/)
|
||||||
|
.map((tool) => tool.replace(/#.+$/, ""))
|
||||||
|
.map((tool) => tool.trim())
|
||||||
|
.filter((tool) => tool.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
export function isIssuesEvent(
|
export function isIssuesEvent(
|
||||||
context: ParsedGitHubContext,
|
context: ParsedGitHubContext,
|
||||||
): context is ParsedGitHubContext & { payload: IssuesEvent } {
|
): context is ParsedGitHubContext & { payload: IssuesEvent } {
|
||||||
|
|||||||
57
test/github/context.test.ts
Normal file
57
test/github/context.test.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import { describe, it, expect } from "bun:test";
|
||||||
|
import { parseMultilineInput } from "../../src/github/context";
|
||||||
|
|
||||||
|
describe("parseMultilineInput", () => {
|
||||||
|
it("should parse a comma-separated string", () => {
|
||||||
|
const input = `Bash(bun install),Bash(bun test:*),Bash(bun typecheck)`;
|
||||||
|
const result = parseMultilineInput(input);
|
||||||
|
expect(result).toEqual([
|
||||||
|
"Bash(bun install)",
|
||||||
|
"Bash(bun test:*)",
|
||||||
|
"Bash(bun typecheck)",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should parse multiline string", () => {
|
||||||
|
const input = `Bash(bun install)
|
||||||
|
Bash(bun test:*)
|
||||||
|
Bash(bun typecheck)`;
|
||||||
|
const result = parseMultilineInput(input);
|
||||||
|
expect(result).toEqual([
|
||||||
|
"Bash(bun install)",
|
||||||
|
"Bash(bun test:*)",
|
||||||
|
"Bash(bun typecheck)",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should parse comma-separated multiline line", () => {
|
||||||
|
const input = `Bash(bun install),Bash(bun test:*)
|
||||||
|
Bash(bun typecheck)`;
|
||||||
|
const result = parseMultilineInput(input);
|
||||||
|
expect(result).toEqual([
|
||||||
|
"Bash(bun install)",
|
||||||
|
"Bash(bun test:*)",
|
||||||
|
"Bash(bun typecheck)",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should ignore comments", () => {
|
||||||
|
const input = `Bash(bun install),
|
||||||
|
Bash(bun test:*) # For testing
|
||||||
|
# For type checking
|
||||||
|
Bash(bun typecheck)
|
||||||
|
`;
|
||||||
|
const result = parseMultilineInput(input);
|
||||||
|
expect(result).toEqual([
|
||||||
|
"Bash(bun install)",
|
||||||
|
"Bash(bun test:*)",
|
||||||
|
"Bash(bun typecheck)",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should parse an empty string", () => {
|
||||||
|
const input = "";
|
||||||
|
const result = parseMultilineInput(input);
|
||||||
|
expect(result).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user