* feat: use GitHub display name in Co-authored-by trailers - Add name field to GitHubAuthor type - Update GraphQL queries to fetch user display names - Add triggerDisplayName to CommonFields type - Extract display name from fetched GitHub data in prepareContext - Update Co-authored-by trailer generation to use display name when available This ensures consistency with GitHub's web interface behavior where Co-authored-by trailers use the user's display name rather than username. Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com> * fix: update GraphQL queries to handle Actor type correctly The name field is only available on the User subtype of Actor in GitHub's GraphQL API. This commit updates the queries to use inline fragments (... on User) to conditionally access the name field when the actor is a User type. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: clarify Co-authored-by instructions in prompt Replace interpolated values with clear references to XML tags and add explicit formatting instructions. This makes it clearer how to use the GitHub display name when available while maintaining the username for the email portion. Changes: - Use explicit references to <trigger_display_name> and <trigger_username> tags - Add clear formatting instructions and example - Explain fallback behavior when display name is not available 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: fetch trigger user display name via dedicated GraphQL query Instead of trying to extract the display name from existing data (which was incomplete due to Actor type limitations), we now: - Add a dedicated USER_QUERY to fetch user display names - Pass the trigger username to fetchGitHubData - Fetch the display name during data collection phase - Simplify prepareContext to use the pre-fetched display name This ensures we always get the correct display name for Co-authored-by trailers, regardless of where the trigger came from. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
111 lines
3.6 KiB
TypeScript
111 lines
3.6 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 { setupGitHubToken } from "../github/token";
|
|
import { checkTriggerAction } from "../github/validation/trigger";
|
|
import { checkHumanActor } from "../github/validation/actor";
|
|
import { checkWritePermissions } from "../github/validation/permissions";
|
|
import { createInitialComment } from "../github/operations/comments/create-initial";
|
|
import { setupBranch } from "../github/operations/branch";
|
|
import { updateTrackingComment } from "../github/operations/comments/update-with-branch";
|
|
import { prepareMcpConfig } from "../mcp/install-mcp-server";
|
|
import { createPrompt } from "../create-prompt";
|
|
import { createOctokit } from "../github/api/client";
|
|
import { fetchGitHubData } from "../github/data/fetcher";
|
|
import { parseGitHubContext } from "../github/context";
|
|
|
|
async function run() {
|
|
try {
|
|
// Step 1: Setup GitHub token
|
|
const githubToken = await setupGitHubToken();
|
|
const octokit = createOctokit(githubToken);
|
|
|
|
// Step 2: Parse GitHub context (once for all operations)
|
|
const context = parseGitHubContext();
|
|
|
|
// Step 3: Check write permissions
|
|
const hasWritePermissions = await checkWritePermissions(
|
|
octokit.rest,
|
|
context,
|
|
);
|
|
if (!hasWritePermissions) {
|
|
throw new Error(
|
|
"Actor does not have write permissions to the repository",
|
|
);
|
|
}
|
|
|
|
// Step 4: Check trigger conditions
|
|
const containsTrigger = await checkTriggerAction(context);
|
|
|
|
if (!containsTrigger) {
|
|
console.log("No trigger found, skipping remaining steps");
|
|
return;
|
|
}
|
|
|
|
// Step 5: Check if actor is human
|
|
await checkHumanActor(octokit.rest, context);
|
|
|
|
// Step 6: Create initial tracking comment
|
|
const commentId = await createInitialComment(octokit.rest, context);
|
|
|
|
// Step 7: Fetch GitHub data (once for both branch setup and prompt creation)
|
|
const githubData = await fetchGitHubData({
|
|
octokits: octokit,
|
|
repository: `${context.repository.owner}/${context.repository.repo}`,
|
|
prNumber: context.entityNumber.toString(),
|
|
isPR: context.isPR,
|
|
triggerUsername: context.actor,
|
|
});
|
|
|
|
// Step 8: Setup branch
|
|
const branchInfo = await setupBranch(octokit, githubData, context);
|
|
|
|
// Step 9: Update initial comment with branch link (only for issues that created a new branch)
|
|
if (branchInfo.claudeBranch) {
|
|
await updateTrackingComment(
|
|
octokit,
|
|
context,
|
|
commentId,
|
|
branchInfo.claudeBranch,
|
|
);
|
|
}
|
|
|
|
// Step 10: Create prompt file
|
|
await createPrompt(
|
|
commentId,
|
|
branchInfo.baseBranch,
|
|
branchInfo.claudeBranch,
|
|
githubData,
|
|
context,
|
|
);
|
|
|
|
// Step 11: Get MCP configuration
|
|
const additionalMcpConfig = process.env.MCP_CONFIG || "";
|
|
const mcpConfig = await prepareMcpConfig({
|
|
githubToken,
|
|
owner: context.repository.owner,
|
|
repo: context.repository.repo,
|
|
branch: branchInfo.currentBranch,
|
|
additionalMcpConfig,
|
|
claudeCommentId: commentId.toString(),
|
|
allowedTools: context.inputs.allowedTools,
|
|
});
|
|
core.setOutput("mcp_config", mcpConfig);
|
|
} 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();
|
|
}
|