Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/create-prompt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ ${
}
<claude_comment_id>${context.claudeCommentId}</claude_comment_id>
<trigger_username>${context.triggerUsername ?? "Unknown"}</trigger_username>
<trigger_display_name>${githubData.triggerDisplayName ?? context.triggerUsername ?? "Unknown"}</trigger_display_name>
<trigger_phrase>${context.triggerPhrase}</trigger_phrase>
${
(eventData.eventName === "issue_comment" ||
Expand Down Expand Up @@ -503,12 +504,14 @@ ${context.directPrompt ? ` - DIRECT INSTRUCTION: A direct instruction was prov
? `
- Push directly using mcp__github_file_ops__commit_files to the existing branch (works for both new and existing files).
- Use mcp__github_file_ops__commit_files to commit files atomically in a single commit (supports single or multiple files).
- When pushing changes with this tool and TRIGGER_USERNAME is not "Unknown", include a "Co-authored-by: ${context.triggerUsername} <${context.triggerUsername}@users.noreply.github.com>" line in the commit message.`
- When pushing changes with this tool and the trigger user is not "Unknown", include a Co-authored-by trailer in the commit message.
- Use: "Co-authored-by: ${githubData.triggerDisplayName ?? context.triggerUsername} <${context.triggerUsername}@users.noreply.github.com>"`
: `
- You are already on the correct branch (${eventData.claudeBranch || "the PR branch"}). Do not create a new branch.
- Push changes directly to the current branch using mcp__github_file_ops__commit_files (works for both new and existing files)
- Use mcp__github_file_ops__commit_files to commit files atomically in a single commit (supports single or multiple files).
- When pushing changes and TRIGGER_USERNAME is not "Unknown", include a "Co-authored-by: ${context.triggerUsername} <${context.triggerUsername}@users.noreply.github.com>" line in the commit message.
- When pushing changes and the trigger user is not "Unknown", include a Co-authored-by trailer in the commit message.
- Use: "Co-authored-by: ${githubData.triggerDisplayName ?? context.triggerUsername} <${context.triggerUsername}@users.noreply.github.com>"
${
eventData.claudeBranch
? `- Provide a URL to create a PR manually in this format:
Expand Down
1 change: 1 addition & 0 deletions src/entrypoints/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async function run() {
repository: `${context.repository.owner}/${context.repository.repo}`,
prNumber: context.entityNumber.toString(),
isPR: context.isPR,
triggerUsername: context.actor,
});

// Step 8: Setup branch
Expand Down
8 changes: 8 additions & 0 deletions src/github/api/queries/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,11 @@ export const ISSUE_QUERY = `
}
}
`;

export const USER_QUERY = `
query($login: String!) {
user(login: $login) {
name
}
}
`;
33 changes: 32 additions & 1 deletion src/github/data/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from "child_process";
import type { Octokits } from "../api/client";
import { ISSUE_QUERY, PR_QUERY } from "../api/queries/github";
import { ISSUE_QUERY, PR_QUERY, USER_QUERY } from "../api/queries/github";
import type {
GitHubComment,
GitHubFile,
Expand All @@ -18,6 +18,7 @@ type FetchDataParams = {
repository: string;
prNumber: string;
isPR: boolean;
triggerUsername?: string;
};

export type GitHubFileWithSHA = GitHubFile & {
Expand All @@ -31,13 +32,15 @@ export type FetchDataResult = {
changedFilesWithSHA: GitHubFileWithSHA[];
reviewData: { nodes: GitHubReview[] } | null;
imageUrlMap: Map<string, string>;
triggerDisplayName?: string | null;
};

export async function fetchGitHubData({
octokits,
repository,
prNumber,
isPR,
triggerUsername,
}: FetchDataParams): Promise<FetchDataResult> {
const [owner, repo] = repository.split("/");
if (!owner || !repo) {
Expand Down Expand Up @@ -191,12 +194,40 @@ export async function fetchGitHubData({
allComments,
);

// Fetch trigger user display name if username is provided
let triggerDisplayName: string | null | undefined;
if (triggerUsername) {
triggerDisplayName = await fetchUserDisplayName(octokits, triggerUsername);
}

return {
contextData,
comments,
changedFiles,
changedFilesWithSHA,
reviewData,
imageUrlMap,
triggerDisplayName,
};
}

export type UserQueryResponse = {
user: {
name: string | null;
};
};

export async function fetchUserDisplayName(
octokits: Octokits,
login: string,
): Promise<string | null> {
try {
const result = await octokits.graphql<UserQueryResponse>(USER_QUERY, {
login,
});
return result.user.name;
} catch (error) {
console.warn(`Failed to fetch user display name for ${login}:`, error);
return null;
}
}
1 change: 1 addition & 0 deletions src/github/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Types for GitHub GraphQL query responses
export type GitHubAuthor = {
login: string;
name?: string;
};

export type GitHubComment = {
Expand Down
2 changes: 1 addition & 1 deletion test/create-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ describe("generatePrompt", () => {

expect(prompt).toContain("<trigger_username>johndoe</trigger_username>");
expect(prompt).toContain(
"Co-authored-by: johndoe <johndoe@users.noreply.github.com>",
'Use: "Co-authored-by: johndoe <johndoe@users.noreply.github.com>"',
);
});

Expand Down