mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-11-19 21:03:06 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f431adaf77 | ||
|
|
5a85689334 | ||
|
|
23cd101ac6 | ||
|
|
6c3921da9b |
@@ -79,12 +79,12 @@ jobs:
|
||||
# --permission-mode auto: a tool call that needs permission and that the allowed tools
|
||||
# do not cover runs only if Claude Code's safety review passes it. This is also the
|
||||
# action's default, and it is set here so that the workflow hardening check can see it.
|
||||
# No --allowedTools, because a rule there skips the review: bun test runs whatever the workspace holds.
|
||||
# --disallowedTools: of the CI tools that actions: read enables, Claude needs only the run results. A pull
|
||||
# request controls the text of logs and of job and step names.
|
||||
# --append-system-prompt: how to use those results where the action denies commands.
|
||||
# --append-system-prompt: how to use those results where commands are denied.
|
||||
claude_args: |
|
||||
--allowedTools "Bash(bun install),Bash(bun test:*),Bash(bun run format),Bash(bun typecheck)"
|
||||
--disallowedTools "mcp__github_ci__download_job_log,mcp__github_ci__get_workflow_run_details"
|
||||
--append-system-prompt "The action denies commands such as bun on pull requests whose author is not confirmed to have write access. When that happens, do not ask for changes to allowedTools. Instead call mcp__github_ci__get_ci_status and report the newest run named CI, which is ci.yml. Only a success conclusion means it passed. action_required means a maintainer has not approved it yet, and a run without a conclusion has not finished. Say that the result is for the latest commit of the pull request and not for edits you made, and that the pull request can change its own workflows, so a maintainer should check the run."
|
||||
--append-system-prompt "A safety review decides whether a command such as bun test may run, and the action denies such commands on pull requests whose author is not confirmed to have write access. If one is denied, do not try the others or ask for changes to allowedTools. On an issue, say what you could not run. On a pull request, call mcp__github_ci__get_ci_status and report the newest run named CI, which is ci.yml. Only a success conclusion means it passed. action_required means a maintainer has not approved it yet, and a run without a conclusion has not finished. Say that the result is for the latest commit of the pull request and not for edits you made, and that the pull request can change its own workflows, so a maintainer should check the run."
|
||||
--model "claude-opus-4-7"
|
||||
--permission-mode auto
|
||||
|
||||
@@ -147,7 +147,7 @@ runs:
|
||||
PATH_TO_CLAUDE_CODE_EXECUTABLE: ${{ inputs.path_to_claude_code_executable }}
|
||||
run: |
|
||||
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
||||
CLAUDE_CODE_VERSION="2.1.327"
|
||||
CLAUDE_CODE_VERSION="2.1.328"
|
||||
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
||||
for attempt in 1 2 3; do
|
||||
echo "Installation attempt $attempt..."
|
||||
|
||||
+10
-10
@@ -6,7 +6,7 @@
|
||||
"name": "@anthropic-ai/claude-code-base-action",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.327",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.328",
|
||||
"shell-quote": "^1.8.4",
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -27,23 +27,23 @@
|
||||
|
||||
"@actions/io": ["@actions/[email protected]", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]7", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.327", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.327" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-zS5RIrYphnhftgafFUpNCGwNUwR6UzLUv3cEy6iD1+LDxmVKnwJAaYTgzgsdijqwuGvcpeiWmbkVrEk0Jc4M5A=="],
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]8", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.328", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.328", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.328", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.328", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.328", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.328", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.328", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.328" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-YcOWlpXVm7etPjPVrvSJEfynDksMiG11zvEybSBnk1EVWji6rSjU75HbbhJ8XPEB2ECEwRRP597Udu6IWMtsDw=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "darwin", "cpu": "arm64" }, "sha512-n+tQOPqz264l12BAKBcBPBbdB/bmZ2SfyONtEXQufTU6EeCoQMPS58RSt51Cxk5sDUme1hTF0vVAqRPdhq8tFg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]8", "", { "os": "darwin", "cpu": "arm64" }, "sha512-vjBASSSZFNs5M84XONCM4xAJMKPD0E9RtF0UDQ/a1Qqt5L+slNxhSADkH5n0tEM5HJMK7j9DCPi+0FVOBpZr3w=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]7", "", { "os": "darwin", "cpu": "x64" }, "sha512-u091X+eQIyqg8BIEYLWJ0o6U3BaivMcf8Im4hI3hti/NGJ6YC5sR+LLEa1RjSIKE+JoOfCxipdCNSKaEI+0d5Q=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]8", "", { "os": "darwin", "cpu": "x64" }, "sha512-pkZuDNi16H4yJFo6cS2sw8mFj7m7ESAxV74t2gQ9EFzZOpXbQoJqhPBHNEZJ2q/+kr/3vHUtRc2W6jURA6nS+A=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-/k6BfV+L2er67UoLUabcp0w3L1DMemJjoijdxvXDiU8w81fGfHaKWKhRuhUQFmIrMLyMyQcBKaoyUNSLWovPnw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]8", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-VvsUzOEf7r3ZtOPfliNGxqknsIvxEmnUOtQnq4+uw7MsfiALKR4s0bx2SP32UuXpqbmqxR1gn456D27XgsAmnA=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-oV8/+ZixiPzEW1BStoP9FOXsHcznONaom6S2PwwIfhi5Pxa5fGuloy8TiOB9wK+03zavqt7jmzLgVPF2a2NsTA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]8", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-4Vui26/OZwr8AU7FpAt+R5s/1AKmj5qDorUZIqF1MMfdjAQf8/ut/+HyEkuMom/MVF2JeQLdvnFFFmbfgmAq/g=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-oAdL7KM9UVAZlATeSjh2haeEjex1N7ZcHzWO1tY2hgyhkyLNVw/tWUhITOucxMwokBx++h2dMVjxiPJiZ5uVOQ=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]8", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-saP4fWgVZj1n7MYCqvTKADHXIc/hIAMRDpLVpXD5xB0IT68vhWgIMkzIrsg5P02P6zA49TDuoijbP1YBUEXT4A=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-O0nDZ1gpXi83qAdd8SM0gTdjlzrqpOlW0M4W7PfHVrMXWLh9I+1tvHat+s17ehIW6A9VQIWIq4oMwq7jb708Dg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]8", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-oJowzzjhWGbdBGyRjqV9CT0nfh4A4/fEI11LjX6b1SkhrNNgy9QT2HzSe8A2yNlliOWo1xJl6nAHT8pLwMNlVg=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "win32", "cpu": "arm64" }, "sha512-a5ju83mylDvUwvQyRt1E0TQ0ar2nzVMPeWZhjcmgpB1cNTjf+KT5jgUnLvxPOG2tyjhm8bYGysRMdgB+tVnhvw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]8", "", { "os": "win32", "cpu": "arm64" }, "sha512-FkqzA++c+giPH2k8svb0egWDiGDkvSLQJTp5bq7QFXOxPEael4ct1yjKit/Yu6Sd48uLEgNT1waBYbyApPzhOw=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]7", "", { "os": "win32", "cpu": "x64" }, "sha512-bf52nw4j5RCvkXI5Poj5Qf0jWvuLQ/UPFqdav86UwaGTZZ0txNV33MKBIUoCyxXV6IC1/p2BNfkwmCAZ+Uc9pw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]8", "", { "os": "win32", "cpu": "x64" }, "sha512-9Wd0XrZ0QWkgtcKxObcYDvUpQjUzN3Uq4Chbvu1SOWOoKPfQdD40dwRQMCeKx2KGxAfMrggJ7I3JYnvRWAFYjg=="],
|
||||
|
||||
"@anthropic-ai/sdk": ["@anthropic-ai/[email protected]", "", { "dependencies": { "json-schema-to-ts": "^3.1.1" }, "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" }, "optionalPeers": ["zod"], "bin": { "anthropic-ai-sdk": "bin/cli" } }, "sha512-q9vaSZQVFx6B/gPxetGYfLXSJD5v0sOmh0OpZDq7yCrTSA+Rscvrtyol7JJTW40wEpQB4U1B4JXzxQitbQ3CAA=="],
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.327",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.328",
|
||||
"shell-quote": "^1.8.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.327",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.328",
|
||||
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||
"@octokit/graphql": "^8.2.2",
|
||||
"@octokit/rest": "^21.1.1",
|
||||
@@ -37,23 +37,23 @@
|
||||
|
||||
"@actions/io": ["@actions/[email protected]", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]7", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.327", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.327" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-zS5RIrYphnhftgafFUpNCGwNUwR6UzLUv3cEy6iD1+LDxmVKnwJAaYTgzgsdijqwuGvcpeiWmbkVrEk0Jc4M5A=="],
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]8", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.328", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.328", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.328", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.328", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.328", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.328", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.328", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.328" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-YcOWlpXVm7etPjPVrvSJEfynDksMiG11zvEybSBnk1EVWji6rSjU75HbbhJ8XPEB2ECEwRRP597Udu6IWMtsDw=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "darwin", "cpu": "arm64" }, "sha512-n+tQOPqz264l12BAKBcBPBbdB/bmZ2SfyONtEXQufTU6EeCoQMPS58RSt51Cxk5sDUme1hTF0vVAqRPdhq8tFg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]8", "", { "os": "darwin", "cpu": "arm64" }, "sha512-vjBASSSZFNs5M84XONCM4xAJMKPD0E9RtF0UDQ/a1Qqt5L+slNxhSADkH5n0tEM5HJMK7j9DCPi+0FVOBpZr3w=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]7", "", { "os": "darwin", "cpu": "x64" }, "sha512-u091X+eQIyqg8BIEYLWJ0o6U3BaivMcf8Im4hI3hti/NGJ6YC5sR+LLEa1RjSIKE+JoOfCxipdCNSKaEI+0d5Q=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]8", "", { "os": "darwin", "cpu": "x64" }, "sha512-pkZuDNi16H4yJFo6cS2sw8mFj7m7ESAxV74t2gQ9EFzZOpXbQoJqhPBHNEZJ2q/+kr/3vHUtRc2W6jURA6nS+A=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-/k6BfV+L2er67UoLUabcp0w3L1DMemJjoijdxvXDiU8w81fGfHaKWKhRuhUQFmIrMLyMyQcBKaoyUNSLWovPnw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]8", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-VvsUzOEf7r3ZtOPfliNGxqknsIvxEmnUOtQnq4+uw7MsfiALKR4s0bx2SP32UuXpqbmqxR1gn456D27XgsAmnA=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-oV8/+ZixiPzEW1BStoP9FOXsHcznONaom6S2PwwIfhi5Pxa5fGuloy8TiOB9wK+03zavqt7jmzLgVPF2a2NsTA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]8", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-4Vui26/OZwr8AU7FpAt+R5s/1AKmj5qDorUZIqF1MMfdjAQf8/ut/+HyEkuMom/MVF2JeQLdvnFFFmbfgmAq/g=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-oAdL7KM9UVAZlATeSjh2haeEjex1N7ZcHzWO1tY2hgyhkyLNVw/tWUhITOucxMwokBx++h2dMVjxiPJiZ5uVOQ=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]8", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-saP4fWgVZj1n7MYCqvTKADHXIc/hIAMRDpLVpXD5xB0IT68vhWgIMkzIrsg5P02P6zA49TDuoijbP1YBUEXT4A=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-O0nDZ1gpXi83qAdd8SM0gTdjlzrqpOlW0M4W7PfHVrMXWLh9I+1tvHat+s17ehIW6A9VQIWIq4oMwq7jb708Dg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]8", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-oJowzzjhWGbdBGyRjqV9CT0nfh4A4/fEI11LjX6b1SkhrNNgy9QT2HzSe8A2yNlliOWo1xJl6nAHT8pLwMNlVg=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "win32", "cpu": "arm64" }, "sha512-a5ju83mylDvUwvQyRt1E0TQ0ar2nzVMPeWZhjcmgpB1cNTjf+KT5jgUnLvxPOG2tyjhm8bYGysRMdgB+tVnhvw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]8", "", { "os": "win32", "cpu": "arm64" }, "sha512-FkqzA++c+giPH2k8svb0egWDiGDkvSLQJTp5bq7QFXOxPEael4ct1yjKit/Yu6Sd48uLEgNT1waBYbyApPzhOw=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]7", "", { "os": "win32", "cpu": "x64" }, "sha512-bf52nw4j5RCvkXI5Poj5Qf0jWvuLQ/UPFqdav86UwaGTZZ0txNV33MKBIUoCyxXV6IC1/p2BNfkwmCAZ+Uc9pw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]8", "", { "os": "win32", "cpu": "x64" }, "sha512-9Wd0XrZ0QWkgtcKxObcYDvUpQjUzN3Uq4Chbvu1SOWOoKPfQdD40dwRQMCeKx2KGxAfMrggJ7I3JYnvRWAFYjg=="],
|
||||
|
||||
"@anthropic-ai/sdk": ["@anthropic-ai/[email protected]", "", { "dependencies": { "json-schema-to-ts": "^3.1.1" }, "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" }, "optionalPeers": ["zod"], "bin": { "anthropic-ai-sdk": "bin/cli" } }, "sha512-q9vaSZQVFx6B/gPxetGYfLXSJD5v0sOmh0OpZDq7yCrTSA+Rscvrtyol7JJTW40wEpQB4U1B4JXzxQitbQ3CAA=="],
|
||||
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
## Access Control
|
||||
|
||||
- **Text From Other People**: Triggering a run does not make someone else's text a request. When a maintainer labels or assigns another person's issue, slash commands in its body do not run, but Claude still reads the body to understand the task, so review it first. A pull request's body can also start a run when a maintainer pushes to, reopens or labels it, where `track_progress` is set. Editing or deleting another person's comment or review does not start a run, even with a `prompt`.
|
||||
- **Text From Other People**: Triggering a run does not make someone else's text a request. When a maintainer labels or assigns another person's issue, slash commands in its body do not run, but Claude still reads the body to understand the task, so review it first. A pull request's body can also start a run when a maintainer pushes to, reopens or labels it, where `track_progress` is set. Editing or dismissing another person's comment or review, or deleting any comment, does not start a run, even with a `prompt`.
|
||||
- **Repository Access**: The action can only be triggered by users with write access to the repository. This is checked for issue, pull request, comment, and review events, and for `workflow_run` events, where both the workflow actor and the actor that started the upstream run are checked. `workflow_dispatch`, `repository_dispatch`, and `schedule` events are not checked separately — GitHub itself requires write access to dispatch a workflow, and scheduled runs have no external actor.
|
||||
- **Bot User Control**: By default, GitHub Apps and bots cannot trigger this action for security reasons. Use the `allowed_bots` parameter to enable specific bots or all bots
|
||||
- **⚠️ Allowed bots are not checked for repository permissions.** A bot that matches an entry does **not** need to be installed on your repository or have write access. On a **public repository**, external parties — including GitHub Apps created by anyone — may be able to trigger workflow events such as opening issues, commenting, or reviewing pull requests. If your workflow listens on those events and `allowed_bots` is set to `'*'`, any such App can invoke this action with a prompt it controls.
|
||||
@@ -126,7 +126,7 @@ Bots often open pull requests from branches in your own repository. Runs there u
|
||||
|
||||
### What a session can leave behind
|
||||
|
||||
Steps that run after Claude, including post steps such as `actions/checkout`'s cleanup, trust `GITHUB_ENV`, `GITHUB_PATH` and git's config files. When the session ends, the action restores those files, including config pulled in through `include.path`, to how they were before it started, and logs a warning naming any it changed. A session therefore can't pass environment variables to later steps through `GITHUB_ENV`, and `git config` changes it made, such as the upstream that `git push -u` records, don't last. Use `GITHUB_OUTPUT` or `--json-schema` to pass results on.
|
||||
Steps that run after Claude, including post steps such as `actions/checkout`'s cleanup, trust `GITHUB_ENV`, `GITHUB_PATH` and git's config files. When the session ends, the action restores those files, including config pulled in through `include.path`, to how they were before it started, and logs a warning naming any it changed. A session therefore can't pass environment variables to later steps through `GITHUB_ENV`, and `git config` changes it made, such as the upstream that `git push -u` records, don't last. Use `GITHUB_OUTPUT` or `--json-schema` to pass results on. What a session writes to `GITHUB_OUTPUT` and `GITHUB_STEP_SUMMARY` is kept, unless it replaced the file with a link or something else that isn't a file.
|
||||
|
||||
While Claude runs, and for the action's own git commands afterwards, git ignores `core.fsmonitor`. Git hooks are off for the action's own commits after the session, and from before the checkout on pull requests that `restrict_untrusted_prs` applies to. During the session these are set in the repository's git config and by the wrapper scripts. Global git config also sets `safe.bareRepository=explicit` for the session, so git won't use a repository it finds in a folder that has no `.git`. A workflow that has Claude work in a bare repository needs to pass `--git-dir`. If a run is cancelled before it restores this, the setting stays in the global config of a self-hosted runner that keeps its home directory. Git LFS uploads through a hook, so the action uploads objects itself for its own commits, but a push Claude makes on such a pull request won't include them.
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.327",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.328",
|
||||
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||
"@octokit/graphql": "^8.2.2",
|
||||
"@octokit/rest": "^21.1.1",
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
/**
|
||||
* Prepare the Claude action by checking trigger conditions, verifying human actor,
|
||||
* and creating the initial tracking comment
|
||||
*/
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import { setupGitHubToken } from "../github/token";
|
||||
import { checkWritePermissions } from "../github/validation/permissions";
|
||||
import { createOctokit } from "../github/api/client";
|
||||
import {
|
||||
parseGitHubContext,
|
||||
isEntityContext,
|
||||
isWorkflowRunEvent,
|
||||
} from "../github/context";
|
||||
import { detectMode } from "../modes/detector";
|
||||
import { prepareTagMode } from "../modes/tag";
|
||||
import { prepareAgentMode } from "../modes/agent";
|
||||
import { checkContainsTrigger } from "../github/validation/trigger";
|
||||
import { collectActionInputsPresence } from "./collect-inputs";
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
collectActionInputsPresence();
|
||||
|
||||
// Parse GitHub context first to enable mode detection
|
||||
const context = parseGitHubContext();
|
||||
|
||||
// Auto-detect mode based on context
|
||||
const modeName = detectMode(context);
|
||||
console.log(
|
||||
`Auto-detected mode: ${modeName} for event: ${context.eventName}`,
|
||||
);
|
||||
|
||||
// Setup GitHub token
|
||||
const githubToken = await setupGitHubToken();
|
||||
const octokit = createOctokit(githubToken);
|
||||
|
||||
// Step 3: Check write permissions (entity contexts and workflow_run)
|
||||
if (isEntityContext(context) || isWorkflowRunEvent(context)) {
|
||||
// Check if github_token was provided as input (not from app)
|
||||
const githubTokenProvided = !!process.env.OVERRIDE_GITHUB_TOKEN;
|
||||
const hasWritePermissions = await checkWritePermissions(
|
||||
octokit.rest,
|
||||
context,
|
||||
context.inputs.allowedNonWriteUsers,
|
||||
githubTokenProvided,
|
||||
);
|
||||
if (!hasWritePermissions) {
|
||||
throw new Error(
|
||||
"Actor does not have write permissions to the repository",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Check trigger conditions
|
||||
const containsTrigger =
|
||||
modeName === "tag"
|
||||
? isEntityContext(context) && checkContainsTrigger(context)
|
||||
: !!context.inputs?.prompt;
|
||||
|
||||
// Debug logging
|
||||
console.log(`Mode: ${modeName}`);
|
||||
console.log(`Context prompt: ${context.inputs?.prompt || "NO PROMPT"}`);
|
||||
console.log(`Trigger result: ${containsTrigger}`);
|
||||
|
||||
// Set output for action.yml to check
|
||||
core.setOutput("contains_trigger", containsTrigger.toString());
|
||||
|
||||
if (!containsTrigger) {
|
||||
console.log("No trigger found, skipping remaining steps");
|
||||
// Still set github_token output even when skipping
|
||||
core.setOutput("github_token", githubToken);
|
||||
return;
|
||||
}
|
||||
|
||||
// Run prepare
|
||||
console.log(
|
||||
`Preparing with mode: ${modeName} for event: ${context.eventName}`,
|
||||
);
|
||||
if (modeName === "tag") {
|
||||
await prepareTagMode({
|
||||
context,
|
||||
octokit,
|
||||
githubToken,
|
||||
skipLfsDownloads: true,
|
||||
});
|
||||
} else {
|
||||
await prepareAgentMode({ context, octokit, githubToken });
|
||||
}
|
||||
|
||||
// MCP config is handled by individual modes (tag/agent) and included in their claude_args output
|
||||
|
||||
// Expose the GitHub token (Claude App token) as an output
|
||||
core.setOutput("github_token", githubToken);
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
core.setFailed(`Prepare step failed with error: ${errorMessage}`);
|
||||
// Also output the clean error message for the action to capture
|
||||
core.setOutput("prepare_error", errorMessage);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
run();
|
||||
}
|
||||
@@ -35,7 +35,10 @@ import type { GitHubContext } from "../github/context";
|
||||
import { detectMode } from "../modes/detector";
|
||||
import { prepareTagMode } from "../modes/tag";
|
||||
import { prepareAgentMode } from "../modes/agent";
|
||||
import { checkContainsTrigger } from "../github/validation/trigger";
|
||||
import {
|
||||
checkContainsTrigger,
|
||||
isModeration,
|
||||
} from "../github/validation/trigger";
|
||||
import {
|
||||
clearSessionState,
|
||||
disableGitPrograms,
|
||||
@@ -102,7 +105,7 @@ async function installClaudeCode(): Promise<string> {
|
||||
return customExecutable;
|
||||
}
|
||||
|
||||
const claudeCodeVersion = "2.1.327";
|
||||
const claudeCodeVersion = "2.1.328";
|
||||
console.log(`Installing Claude Code v${claudeCodeVersion}...`);
|
||||
|
||||
for (let attempt = 1; attempt <= 3; attempt++) {
|
||||
@@ -249,7 +252,8 @@ async function run() {
|
||||
const containsTrigger =
|
||||
modeName === "tag"
|
||||
? isEntityContext(context) && checkContainsTrigger(context)
|
||||
: !!context.inputs?.prompt;
|
||||
: !!context.inputs?.prompt &&
|
||||
!(isEntityContext(context) && isModeration(context));
|
||||
console.log(`Mode: ${modeName}`);
|
||||
console.log(`Context prompt: ${context.inputs?.prompt || "NO PROMPT"}`);
|
||||
console.log(`Trigger result: ${containsTrigger}`);
|
||||
|
||||
@@ -16,7 +16,8 @@ import {
|
||||
import { homedir } from "os";
|
||||
import { dirname, isAbsolute, join, resolve } from "path";
|
||||
|
||||
type TrackedFile = { label: string; path: string };
|
||||
// A session may write to one that keeps its writes, but not put a link in its place.
|
||||
type TrackedFile = { label: string; path: string; keepsWrites?: boolean };
|
||||
|
||||
// "opaque" is anything that can't be saved and compared: a directory, a FIFO, a
|
||||
// device, a file too large to hold, or one that can't be read.
|
||||
@@ -25,6 +26,7 @@ type FileSnapshot = TrackedFile & {
|
||||
wasSymlink: boolean;
|
||||
content?: Buffer;
|
||||
mode?: number;
|
||||
names?: number;
|
||||
// For a symlink: what it points to, and the regular file that ends up at.
|
||||
link?: { target: string; resolved: string };
|
||||
};
|
||||
@@ -121,8 +123,15 @@ function filesLaterStepsTrust(): TrackedFile[] {
|
||||
path ? [{ label, path }] : [],
|
||||
);
|
||||
|
||||
// The action adds to these after the session, so a link there would redirect that to
|
||||
// a file later steps trust.
|
||||
const written = ["GITHUB_OUTPUT", "GITHUB_STEP_SUMMARY"].flatMap((label) => {
|
||||
const path = process.env[label];
|
||||
return path ? [{ label, path, keepsWrites: true }] : [];
|
||||
});
|
||||
|
||||
const seen = new Set<string>();
|
||||
return [...named, ...gitConfigFilesInUse()].filter(({ path }) => {
|
||||
return [...named, ...gitConfigFilesInUse(), ...written].filter(({ path }) => {
|
||||
const absolute = resolve(path);
|
||||
if (seen.has(absolute)) return false;
|
||||
seen.add(absolute);
|
||||
@@ -152,6 +161,7 @@ function readSnapshot(file: TrackedFile): FileSnapshot {
|
||||
wasSymlink,
|
||||
content: readFileSync(fd),
|
||||
mode: stats.mode & 0o777,
|
||||
names: stats.nlink,
|
||||
...(wasSymlink && {
|
||||
link: {
|
||||
target: readlinkSync(file.path),
|
||||
@@ -190,6 +200,19 @@ function restorePath(before: FileSnapshot): string {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether what is written to a file now ends up in that file and no other. A new name
|
||||
* for a file that later steps trust is as good as a symlink to it.
|
||||
*/
|
||||
function isItsOwnFile(before: FileSnapshot): boolean {
|
||||
try {
|
||||
const stats = lstatSync(restorePath(before));
|
||||
return stats.isFile() && stats.nlink <= (before.names ?? 1);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Records the files later steps trust, and returns a function that puts them
|
||||
* back. Call the returned function as soon as the session ends and before the
|
||||
@@ -212,8 +235,12 @@ export function snapshotSessionFiles(beforeSession?: () => void): () => void {
|
||||
for (const [index, before] of snapshots.entries()) {
|
||||
try {
|
||||
const now = readSnapshot(before);
|
||||
if (isUnchanged(before, now)) continue;
|
||||
const changedBySession = !isUnchanged(atStart[index]!, now);
|
||||
if (before.keepsWrites && isItsOwnFile(before)) continue;
|
||||
// The file it leads to can have the same content so far.
|
||||
const leadsElsewhere = before.keepsWrites && now.state === "file";
|
||||
if (!leadsElsewhere && isUnchanged(before, now)) continue;
|
||||
const changedBySession =
|
||||
leadsElsewhere || !isUnchanged(atStart[index]!, now);
|
||||
if (before.state === "opaque") {
|
||||
core.warning(
|
||||
`Could not restore ${before.label} after the session: it was not a regular file before`,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import {
|
||||
isIssuesEvent,
|
||||
isIssuesAssignedEvent,
|
||||
@@ -12,13 +11,11 @@ import {
|
||||
import type { ParsedGitHubContext } from "../context";
|
||||
import { isSameLogin } from "./actor";
|
||||
|
||||
export function checkContainsTrigger(context: ParsedGitHubContext): boolean {
|
||||
const {
|
||||
inputs: { assigneeTrigger, labelTrigger, triggerPhrase, prompt },
|
||||
} = context;
|
||||
|
||||
// Deleting or editing someone else's comment or review fires these events with
|
||||
// the moderator as the actor. The text must come from the person who was checked.
|
||||
/**
|
||||
* Whether the text of a comment or review event comes from the person who was checked.
|
||||
* Deleting or editing someone else's fires these events with the moderator as the actor.
|
||||
*/
|
||||
function isTextFromActor(context: ParsedGitHubContext): boolean {
|
||||
if (
|
||||
(isIssueCommentEvent(context) ||
|
||||
isPullRequestReviewCommentEvent(context)) &&
|
||||
@@ -35,6 +32,26 @@ export function checkContainsTrigger(context: ParsedGitHubContext): boolean {
|
||||
console.log("Review was written by someone other than the actor");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a comment or review event comes from moderation, so that its text must not
|
||||
* start a run. A new comment or review is always its author's own, and some apps have
|
||||
* one login as its author and another as the actor.
|
||||
*/
|
||||
export function isModeration(context: ParsedGitHubContext): boolean {
|
||||
const isNew =
|
||||
context.eventAction === "created" || context.eventAction === "submitted";
|
||||
return !isNew && !isTextFromActor(context);
|
||||
}
|
||||
|
||||
export function checkContainsTrigger(context: ParsedGitHubContext): boolean {
|
||||
const {
|
||||
inputs: { assigneeTrigger, labelTrigger, triggerPhrase, prompt },
|
||||
} = context;
|
||||
|
||||
if (!isTextFromActor(context)) return false;
|
||||
|
||||
// A prompt replaces the trigger phrase, but a configured label or assignee
|
||||
// still decides which label or assignment event starts a run. Otherwise any
|
||||
@@ -195,9 +212,3 @@ function matchesAssigneeTrigger(
|
||||
export function escapeRegExp(string: string) {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
export async function checkTriggerAction(context: ParsedGitHubContext) {
|
||||
const containsTrigger = checkContainsTrigger(context);
|
||||
core.setOutput("contains_trigger", containsTrigger.toString());
|
||||
return containsTrigger;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "fs";
|
||||
import { tmpdir } from "os";
|
||||
import { join } from "path";
|
||||
|
||||
const writer = { login: "writer", type: "User" };
|
||||
const outsider = { login: "outsider", type: "User" };
|
||||
const repository = { id: 1, name: "r", owner: { login: "o" } };
|
||||
const issue = { number: 7, user: outsider };
|
||||
|
||||
// The directory is not a git repository, so a run that starts fails later on.
|
||||
async function runWithPrompt(eventName: string, event: object) {
|
||||
const dir = mkdtempSync(join(tmpdir(), "moderation-"));
|
||||
const server = Bun.serve({
|
||||
port: 0,
|
||||
hostname: "127.0.0.1",
|
||||
fetch: (request) =>
|
||||
request.url.endsWith("/permission")
|
||||
? Response.json({ permission: "write" })
|
||||
: Response.json({}, { status: 404 }),
|
||||
});
|
||||
try {
|
||||
for (const file of ["output", "env"]) writeFileSync(join(dir, file), "");
|
||||
writeFileSync(join(dir, "event.json"), JSON.stringify(event));
|
||||
const child = Bun.spawn(
|
||||
[
|
||||
process.execPath,
|
||||
"run",
|
||||
join(import.meta.dir, "../src/entrypoints/run.ts"),
|
||||
],
|
||||
{
|
||||
cwd: dir,
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
env: {
|
||||
PATH: process.env.PATH,
|
||||
HOME: dir,
|
||||
RUNNER_TEMP: dir,
|
||||
GITHUB_EVENT_NAME: eventName,
|
||||
GITHUB_EVENT_PATH: join(dir, "event.json"),
|
||||
GITHUB_REPOSITORY: "o/r",
|
||||
GITHUB_ACTOR: "writer",
|
||||
GITHUB_RUN_ID: "1",
|
||||
GITHUB_OUTPUT: join(dir, "output"),
|
||||
GITHUB_ENV: join(dir, "env"),
|
||||
GITHUB_API_URL: `http://127.0.0.1:${server.port}`,
|
||||
OVERRIDE_GITHUB_TOKEN: "t",
|
||||
ALLOW_FORK_PRS: "true",
|
||||
PROMPT: "Respond to this",
|
||||
},
|
||||
},
|
||||
);
|
||||
const log = await new Response(child.stdout).text();
|
||||
await child.exited;
|
||||
return log;
|
||||
} finally {
|
||||
server.stop(true);
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
const SKIPPED = "No trigger found, skipping remaining steps";
|
||||
const STARTED = "Preparing with mode: agent";
|
||||
|
||||
test("a prompt doesn't run when a maintainer edits or deletes someone else's comment", async () => {
|
||||
for (const action of ["edited", "deleted"]) {
|
||||
const log = await runWithPrompt("issue_comment", {
|
||||
action,
|
||||
repository,
|
||||
sender: writer,
|
||||
issue,
|
||||
comment: { id: 1, body: "x", user: outsider },
|
||||
});
|
||||
expect(log).toContain(SKIPPED);
|
||||
expect(log).not.toContain(STARTED);
|
||||
}
|
||||
});
|
||||
|
||||
test("a prompt runs on a new comment, and on events that have none", async () => {
|
||||
const events: [string, object][] = [
|
||||
[
|
||||
"issue_comment",
|
||||
{ action: "created", issue, comment: { id: 1, body: "x", user: writer } },
|
||||
],
|
||||
// With a prompt, label_trigger doesn't limit which label starts a run.
|
||||
["issues", { action: "labeled", issue, label: { name: "triage" } }],
|
||||
];
|
||||
for (const [eventName, event] of events) {
|
||||
const log = await runWithPrompt(eventName, {
|
||||
repository,
|
||||
sender: writer,
|
||||
...event,
|
||||
});
|
||||
expect(log).toContain(STARTED);
|
||||
}
|
||||
});
|
||||
@@ -2,7 +2,9 @@ import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
|
||||
import * as core from "@actions/core";
|
||||
import { execFileSync } from "child_process";
|
||||
import {
|
||||
appendFileSync,
|
||||
existsSync,
|
||||
linkSync,
|
||||
lstatSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
@@ -27,7 +29,9 @@ import {
|
||||
const KEYS = [
|
||||
"GITHUB_ACTION_PATH",
|
||||
"GITHUB_ENV",
|
||||
"GITHUB_OUTPUT",
|
||||
"GITHUB_PATH",
|
||||
"GITHUB_STEP_SUMMARY",
|
||||
"HOME",
|
||||
"XDG_CONFIG_HOME",
|
||||
"GIT_CONFIG_GLOBAL",
|
||||
@@ -154,6 +158,104 @@ describe("session guard", () => {
|
||||
expect(statSync(path).mode & 0o777).toBe(0o640);
|
||||
});
|
||||
|
||||
describe.each(["GITHUB_OUTPUT", "GITHUB_STEP_SUMMARY"])(
|
||||
"%s, which the action adds to after the session",
|
||||
(name) => {
|
||||
let path: string;
|
||||
|
||||
beforeEach(() => {
|
||||
path = join(dir, name);
|
||||
process.env[name] = path;
|
||||
writeFileSync(path, "by an earlier part\n");
|
||||
});
|
||||
|
||||
test("keeps what a session wrote", () => {
|
||||
const restore = snapshotSessionFiles();
|
||||
appendFileSync(path, "by the session\n");
|
||||
restore();
|
||||
expect(readFileSync(path, "utf8")).toBe(
|
||||
"by an earlier part\nby the session\n",
|
||||
);
|
||||
expect(warnings()).toEqual([]);
|
||||
});
|
||||
|
||||
test("keeps it if the session replaced the file", () => {
|
||||
const restore = snapshotSessionFiles();
|
||||
rmSync(path);
|
||||
writeFileSync(path, "by the session\n");
|
||||
restore();
|
||||
expect(readFileSync(path, "utf8")).toBe("by the session\n");
|
||||
expect(warnings()).toEqual([]);
|
||||
});
|
||||
|
||||
test.each([
|
||||
["a symlink", symlinkSync],
|
||||
["a hard link", linkSync],
|
||||
])("doesn't follow %s to a file later steps trust", (_, link) => {
|
||||
const restore = snapshotSessionFiles();
|
||||
rmSync(path);
|
||||
link(process.env.GITHUB_PATH!, path);
|
||||
restore();
|
||||
appendFileSync(path, "/tmp/shims\n");
|
||||
expect(readFileSync(process.env.GITHUB_PATH!, "utf8")).toBe(
|
||||
"/opt/tool\n",
|
||||
);
|
||||
expect(readFileSync(path, "utf8")).toBe(
|
||||
"by an earlier part\n/tmp/shims\n",
|
||||
);
|
||||
expect(warnings()[0]).toContain(name);
|
||||
});
|
||||
|
||||
test("doesn't follow a hard link to a file with the same content", () => {
|
||||
writeFileSync(path, "");
|
||||
writeFileSync(process.env.GITHUB_ENV!, "");
|
||||
const restore = snapshotSessionFiles();
|
||||
rmSync(path);
|
||||
linkSync(process.env.GITHUB_ENV!, path);
|
||||
restore();
|
||||
appendFileSync(path, "X=1\n");
|
||||
expect(readFileSync(process.env.GITHUB_ENV!, "utf8")).toBe("");
|
||||
expect(warnings()[0]).toContain(name);
|
||||
});
|
||||
|
||||
test("puts back a file the session deleted", () => {
|
||||
const restore = snapshotSessionFiles();
|
||||
rmSync(path);
|
||||
restore();
|
||||
expect(readFileSync(path, "utf8")).toBe("by an earlier part\n");
|
||||
});
|
||||
|
||||
test("says nothing if there was no file before and after", () => {
|
||||
rmSync(path);
|
||||
snapshotSessionFiles()();
|
||||
expect(existsSync(path)).toBe(false);
|
||||
expect(warnings()).toEqual([]);
|
||||
});
|
||||
|
||||
test("keeps what a session wrote to a file that had a second name before", () => {
|
||||
linkSync(path, join(dir, "second-name"));
|
||||
const restore = snapshotSessionFiles();
|
||||
appendFileSync(path, "by the session\n");
|
||||
restore();
|
||||
expect(readFileSync(path, "utf8")).toContain("by the session\n");
|
||||
expect(warnings()).toEqual([]);
|
||||
});
|
||||
|
||||
test("keeps a link that was there before, and what a session wrote to it", () => {
|
||||
const target = join(dir, "target");
|
||||
rmSync(path);
|
||||
writeFileSync(target, "");
|
||||
symlinkSync(target, path);
|
||||
const restore = snapshotSessionFiles();
|
||||
appendFileSync(path, "by the session\n");
|
||||
restore();
|
||||
expect(lstatSync(path).isSymbolicLink()).toBe(true);
|
||||
expect(readFileSync(target, "utf8")).toBe("by the session\n");
|
||||
expect(warnings()).toEqual([]);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
describe("a config that was already a symlink", () => {
|
||||
let target: string;
|
||||
let link: string;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
checkContainsTrigger,
|
||||
escapeRegExp,
|
||||
isModeration,
|
||||
} from "../src/github/validation/trigger";
|
||||
import { describe, it, expect } from "bun:test";
|
||||
import {
|
||||
@@ -625,3 +626,98 @@ describe("checkContainsTrigger when the text is someone else's", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isModeration", () => {
|
||||
const event = (
|
||||
base: ParsedGitHubContext,
|
||||
kind: "comment" | "review",
|
||||
eventAction: string,
|
||||
author: string | null,
|
||||
actor: string,
|
||||
) =>
|
||||
({
|
||||
...base,
|
||||
eventAction,
|
||||
actor,
|
||||
payload: {
|
||||
...base.payload,
|
||||
action: eventAction,
|
||||
[kind]: {
|
||||
...(base.payload as any)[kind],
|
||||
user: author && { login: author },
|
||||
},
|
||||
},
|
||||
}) as ParsedGitHubContext;
|
||||
const comments = [
|
||||
mockIssueCommentContext,
|
||||
mockPullRequestReviewCommentContext,
|
||||
];
|
||||
|
||||
it("is true when someone else edits or deletes a comment", () => {
|
||||
for (const base of comments) {
|
||||
for (const action of ["edited", "deleted"]) {
|
||||
for (const author of ["outsider", null]) {
|
||||
expect(
|
||||
isModeration(event(base, "comment", action, author, "maintainer")),
|
||||
).toBe(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("is true when someone else edits or dismisses a review", () => {
|
||||
for (const action of ["edited", "dismissed"]) {
|
||||
expect(
|
||||
isModeration(
|
||||
event(
|
||||
mockPullRequestReviewContext,
|
||||
"review",
|
||||
action,
|
||||
"outsider",
|
||||
"maintainer",
|
||||
),
|
||||
),
|
||||
).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("is true for any deleted comment", () => {
|
||||
for (const base of comments) {
|
||||
expect(
|
||||
isModeration(event(base, "comment", "deleted", "writer", "writer")),
|
||||
).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("is false for a person's own edit", () => {
|
||||
for (const base of comments) {
|
||||
expect(
|
||||
isModeration(event(base, "comment", "edited", "Writer", "writer")),
|
||||
).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it("is false for a new comment or review, whatever login its app has", () => {
|
||||
for (const base of comments) {
|
||||
expect(
|
||||
isModeration(event(base, "comment", "created", "app[bot]", "App")),
|
||||
).toBe(false);
|
||||
}
|
||||
expect(
|
||||
isModeration(
|
||||
event(
|
||||
mockPullRequestReviewContext,
|
||||
"review",
|
||||
"submitted",
|
||||
"app[bot]",
|
||||
"App",
|
||||
),
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("is false for events with no comment or review", () => {
|
||||
expect(isModeration(mockIssueLabeledContext)).toBe(false);
|
||||
expect(isModeration(mockIssueOpenedContext)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user