Skip to content

Commit 0f07aee

Browse files
authored
Use modern noreply email for co-author trailers (#1369)
1 parent a221ad2 commit 0f07aee

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎src/create-prompt/index.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,27 @@ export function prepareContext(
122122

123123
// Extract trigger username and comment data based on event type
124124
let triggerUsername: string | undefined;
125+
let triggerUserId: number | undefined;
125126
let commentId: string | undefined;
126127
let commentBody: string | undefined;
127128

128129
if (isIssueCommentEvent(context)) {
129130
commentId = context.payload.comment.id.toString();
130131
commentBody = context.payload.comment.body;
131132
triggerUsername = context.payload.comment.user.login;
133+
triggerUserId = context.payload.comment.user.id;
132134
} else if (isPullRequestReviewEvent(context)) {
133135
commentBody = context.payload.review.body ?? "";
134136
triggerUsername = context.payload.review.user.login;
137+
triggerUserId = context.payload.review.user.id;
135138
} else if (isPullRequestReviewCommentEvent(context)) {
136139
commentId = context.payload.comment.id.toString();
137140
commentBody = context.payload.comment.body;
138141
triggerUsername = context.payload.comment.user.login;
142+
triggerUserId = context.payload.comment.user.id;
139143
} else if (isIssuesEvent(context)) {
140144
triggerUsername = context.payload.issue.user.login;
145+
triggerUserId = context.payload.issue.user.id;
141146
}
142147

143148
// Create infrastructure fields object
@@ -146,6 +151,7 @@ export function prepareContext(
146151
claudeCommentId,
147152
triggerPhrase,
148153
...(triggerUsername && { triggerUsername }),
154+
...(triggerUserId && { triggerUserId }),
149155
...(prompt && { prompt }),
150156
...(claudeBranch && { claudeBranch }),
151157
};
@@ -394,9 +400,16 @@ function getCommitInstructions(
394400
context: PreparedContext,
395401
useCommitSigning: boolean,
396402
): string {
403+
const triggerName = githubData.triggerDisplayName ?? context.triggerUsername;
404+
const triggerEmail =
405+
context.triggerUserId && context.triggerUsername
406+
? `${context.triggerUserId}+${context.triggerUsername}@users.noreply.github.com`
407+
: context.triggerUsername
408+
? `${context.triggerUsername}@users.noreply.github.com`
409+
: undefined;
397410
const coAuthorLine =
398-
(githubData.triggerDisplayName ?? context.triggerUsername) !== "Unknown"
399-
? `Co-authored-by: ${githubData.triggerDisplayName ?? context.triggerUsername} <${context.triggerUsername}@users.noreply.github.com>`
411+
triggerName && triggerName !== "Unknown" && triggerEmail
412+
? `Co-authored-by: ${triggerName} <${triggerEmail}>`
400413
: "";
401414

402415
if (useCommitSigning) {

‎src/create-prompt/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type CommonFields = {
55
claudeCommentId: string;
66
triggerPhrase: string;
77
triggerUsername?: string;
8+
triggerUserId?: number;
89
prompt?: string;
910
claudeBranch?: string;
1011
};

‎test/create-prompt.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,32 @@ describe("generatePrompt", () => {
495495
);
496496
});
497497

498+
test("should use numeric GitHub noreply address when trigger user id is provided", async () => {
499+
const envVars: PreparedContext = {
500+
repository: "owner/repo",
501+
claudeCommentId: "12345",
502+
triggerPhrase: "@claude",
503+
triggerUsername: "johndoe",
504+
triggerUserId: 123456,
505+
eventData: {
506+
eventName: "issue_comment",
507+
commentId: "67890",
508+
isPR: false,
509+
issueNumber: "123",
510+
baseBranch: "main",
511+
claudeBranch: "claude/issue-67890-20240101-1200",
512+
commentBody: "@claude please fix this",
513+
},
514+
};
515+
516+
const prompt = await generatePrompt(envVars, mockGitHubData, false, "tag");
517+
518+
expect(prompt).toContain(
519+
"Co-authored-by: johndoe <[email protected]>",
520+
);
521+
expect(prompt).not.toContain("<[email protected]>");
522+
});
523+
498524
test("should include PR-specific instructions only for PR events", async () => {
499525
const envVars: PreparedContext = {
500526
repository: "owner/repo",

0 commit comments

Comments
 (0)