mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-03 09:48:31 +08:00
Use modern noreply email for co-author trailers (#1369)
This commit is contained in:
parent
a221ad2dd9
commit
0f07aee435
@ -122,6 +122,7 @@ export function prepareContext(
|
|||||||
|
|
||||||
// Extract trigger username and comment data based on event type
|
// Extract trigger username and comment data based on event type
|
||||||
let triggerUsername: string | undefined;
|
let triggerUsername: string | undefined;
|
||||||
|
let triggerUserId: number | undefined;
|
||||||
let commentId: string | undefined;
|
let commentId: string | undefined;
|
||||||
let commentBody: string | undefined;
|
let commentBody: string | undefined;
|
||||||
|
|
||||||
@ -129,15 +130,19 @@ export function prepareContext(
|
|||||||
commentId = context.payload.comment.id.toString();
|
commentId = context.payload.comment.id.toString();
|
||||||
commentBody = context.payload.comment.body;
|
commentBody = context.payload.comment.body;
|
||||||
triggerUsername = context.payload.comment.user.login;
|
triggerUsername = context.payload.comment.user.login;
|
||||||
|
triggerUserId = context.payload.comment.user.id;
|
||||||
} else if (isPullRequestReviewEvent(context)) {
|
} else if (isPullRequestReviewEvent(context)) {
|
||||||
commentBody = context.payload.review.body ?? "";
|
commentBody = context.payload.review.body ?? "";
|
||||||
triggerUsername = context.payload.review.user.login;
|
triggerUsername = context.payload.review.user.login;
|
||||||
|
triggerUserId = context.payload.review.user.id;
|
||||||
} else if (isPullRequestReviewCommentEvent(context)) {
|
} else if (isPullRequestReviewCommentEvent(context)) {
|
||||||
commentId = context.payload.comment.id.toString();
|
commentId = context.payload.comment.id.toString();
|
||||||
commentBody = context.payload.comment.body;
|
commentBody = context.payload.comment.body;
|
||||||
triggerUsername = context.payload.comment.user.login;
|
triggerUsername = context.payload.comment.user.login;
|
||||||
|
triggerUserId = context.payload.comment.user.id;
|
||||||
} else if (isIssuesEvent(context)) {
|
} else if (isIssuesEvent(context)) {
|
||||||
triggerUsername = context.payload.issue.user.login;
|
triggerUsername = context.payload.issue.user.login;
|
||||||
|
triggerUserId = context.payload.issue.user.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create infrastructure fields object
|
// Create infrastructure fields object
|
||||||
@ -146,6 +151,7 @@ export function prepareContext(
|
|||||||
claudeCommentId,
|
claudeCommentId,
|
||||||
triggerPhrase,
|
triggerPhrase,
|
||||||
...(triggerUsername && { triggerUsername }),
|
...(triggerUsername && { triggerUsername }),
|
||||||
|
...(triggerUserId && { triggerUserId }),
|
||||||
...(prompt && { prompt }),
|
...(prompt && { prompt }),
|
||||||
...(claudeBranch && { claudeBranch }),
|
...(claudeBranch && { claudeBranch }),
|
||||||
};
|
};
|
||||||
@ -394,9 +400,16 @@ function getCommitInstructions(
|
|||||||
context: PreparedContext,
|
context: PreparedContext,
|
||||||
useCommitSigning: boolean,
|
useCommitSigning: boolean,
|
||||||
): string {
|
): string {
|
||||||
|
const triggerName = githubData.triggerDisplayName ?? context.triggerUsername;
|
||||||
|
const triggerEmail =
|
||||||
|
context.triggerUserId && context.triggerUsername
|
||||||
|
? `${context.triggerUserId}+${context.triggerUsername}@users.noreply.github.com`
|
||||||
|
: context.triggerUsername
|
||||||
|
? `${context.triggerUsername}@users.noreply.github.com`
|
||||||
|
: undefined;
|
||||||
const coAuthorLine =
|
const coAuthorLine =
|
||||||
(githubData.triggerDisplayName ?? context.triggerUsername) !== "Unknown"
|
triggerName && triggerName !== "Unknown" && triggerEmail
|
||||||
? `Co-authored-by: ${githubData.triggerDisplayName ?? context.triggerUsername} <${context.triggerUsername}@users.noreply.github.com>`
|
? `Co-authored-by: ${triggerName} <${triggerEmail}>`
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
if (useCommitSigning) {
|
if (useCommitSigning) {
|
||||||
|
|||||||
@ -5,6 +5,7 @@ export type CommonFields = {
|
|||||||
claudeCommentId: string;
|
claudeCommentId: string;
|
||||||
triggerPhrase: string;
|
triggerPhrase: string;
|
||||||
triggerUsername?: string;
|
triggerUsername?: string;
|
||||||
|
triggerUserId?: number;
|
||||||
prompt?: string;
|
prompt?: string;
|
||||||
claudeBranch?: string;
|
claudeBranch?: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -495,6 +495,32 @@ describe("generatePrompt", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should use numeric GitHub noreply address when trigger user id is provided", async () => {
|
||||||
|
const envVars: PreparedContext = {
|
||||||
|
repository: "owner/repo",
|
||||||
|
claudeCommentId: "12345",
|
||||||
|
triggerPhrase: "@claude",
|
||||||
|
triggerUsername: "johndoe",
|
||||||
|
triggerUserId: 123456,
|
||||||
|
eventData: {
|
||||||
|
eventName: "issue_comment",
|
||||||
|
commentId: "67890",
|
||||||
|
isPR: false,
|
||||||
|
issueNumber: "123",
|
||||||
|
baseBranch: "main",
|
||||||
|
claudeBranch: "claude/issue-67890-20240101-1200",
|
||||||
|
commentBody: "@claude please fix this",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const prompt = await generatePrompt(envVars, mockGitHubData, false, "tag");
|
||||||
|
|
||||||
|
expect(prompt).toContain(
|
||||||
|
"Co-authored-by: johndoe <123456+johndoe@users.noreply.github.com>",
|
||||||
|
);
|
||||||
|
expect(prompt).not.toContain("<johndoe@users.noreply.github.com>");
|
||||||
|
});
|
||||||
|
|
||||||
test("should include PR-specific instructions only for PR events", async () => {
|
test("should include PR-specific instructions only for PR events", async () => {
|
||||||
const envVars: PreparedContext = {
|
const envVars: PreparedContext = {
|
||||||
repository: "owner/repo",
|
repository: "owner/repo",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user