Some checks failed
CI All / test-custom-executables (pull_request) Failing after 26s
CI All / test-base-action (pull_request) Failing after 1m37s
CI All / ci (pull_request) Failing after 2m0s
CI All / test-settings (pull_request) Failing after 2m38s
CI All / test-mcp-servers (pull_request) Failing after 2m48s
CI / test (pull_request) Failing after 1m14s
CI / prettier (pull_request) Failing after 1m0s
CI / typecheck (pull_request) Failing after 43s
Test Claude Code Action / test-inline-prompt (pull_request) Failing after 41s
CI All / test-structured-output (pull_request) Failing after 3m8s
Test Custom Executables / test-custom-executables (pull_request) Failing after 11s
Test Claude Code Action / test-prompt-file (pull_request) Failing after 41s
PR Review / review (pull_request) Failing after 1m23s
Test Settings Feature / test-settings-inline-allow (pull_request) Failing after 47s
Test Settings Feature / test-settings-inline-deny (pull_request) Failing after 49s
Test MCP Servers / test-mcp-integration (pull_request) Failing after 59s
Test Settings Feature / test-settings-file-allow (pull_request) Failing after 39s
Test MCP Servers / test-mcp-config-flag (pull_request) Failing after 1m18s
Test Settings Feature / test-settings-file-deny (pull_request) Failing after 30s
Test Structured Outputs / Test Basic Type Conversions (pull_request) Failing after 31s
Test Structured Outputs / Test Arrays and Objects (pull_request) Failing after 31s
Test Structured Outputs / Test Edge Cases (pull_request) Failing after 28s
Test Structured Outputs / Test Output Name Sanitization (pull_request) Failing after 28s
Test Structured Outputs / Test Execution File Format (pull_request) Failing after 32s
Test Structured Outputs / Summary (pull_request) Failing after 1s
119 lines
3.9 KiB
TypeScript
119 lines
3.9 KiB
TypeScript
#!/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 * as github from "@actions/github";
|
|
import { setupGitHubToken } from "../github/token";
|
|
import { checkWritePermissions } from "../github/validation/permissions";
|
|
import { createOctokit } from "../github/api/client";
|
|
import { parseGitHubContext, isEntityContext } from "../github/context";
|
|
import { getMode } from "../modes/registry";
|
|
import { prepare } from "../prepare";
|
|
import { collectActionInputsPresence } from "./collect-inputs";
|
|
import { setupGiteaRunId } from "../github/api/gitea-run-id";
|
|
|
|
async function run() {
|
|
try {
|
|
collectActionInputsPresence();
|
|
|
|
// Resolve Gitea run ID before parsing context (uses GITEA_RUN_NUMBER if available)
|
|
// We need a token for this - use either the override token or the default workflow token
|
|
const earlyToken =
|
|
process.env.OVERRIDE_GITHUB_TOKEN || process.env.DEFAULT_WORKFLOW_TOKEN;
|
|
if (earlyToken) {
|
|
const { owner, repo } = github.context.repo;
|
|
await setupGiteaRunId(earlyToken, owner, repo);
|
|
}
|
|
|
|
// Output the resolved run ID for subsequent steps
|
|
if (process.env.GITHUB_RUN_ID) {
|
|
core.setOutput("run_id", process.env.GITHUB_RUN_ID);
|
|
}
|
|
|
|
// Parse GitHub context first to enable mode detection
|
|
const context = parseGitHubContext();
|
|
|
|
// Auto-detect mode based on context
|
|
const mode = getMode(context);
|
|
|
|
// Setup GitHub token
|
|
const githubToken = await setupGitHubToken();
|
|
const octokit = createOctokit(githubToken);
|
|
|
|
// Step 3: Check write permissions (only for entity contexts)
|
|
if (isEntityContext(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 = mode.shouldTrigger(context);
|
|
|
|
// Debug logging
|
|
console.log(`Mode: ${mode.name}`);
|
|
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;
|
|
}
|
|
|
|
// Step 5: Use the new modular prepare function
|
|
const result = await prepare({
|
|
context,
|
|
octokit,
|
|
mode,
|
|
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);
|
|
|
|
// Step 6: Get system prompt from mode if available
|
|
if (mode.getSystemPrompt) {
|
|
const modeContext = mode.prepareContext(context, {
|
|
commentId: result.commentId,
|
|
baseBranch: result.branchInfo.baseBranch,
|
|
claudeBranch: result.branchInfo.claudeBranch,
|
|
});
|
|
const systemPrompt = mode.getSystemPrompt(modeContext);
|
|
if (systemPrompt) {
|
|
core.exportVariable("APPEND_SYSTEM_PROMPT", systemPrompt);
|
|
}
|
|
}
|
|
} 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();
|
|
}
|