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
77 changes: 77 additions & 0 deletions src/utils/__tests__/changelog-generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,83 @@ describe('generateChangesetFromGit', () => {
);
});

it('credits AI agents as bots by their commit email', async () => {
setup(
[
{
hash: 'abcdef1234567890',
title: 'Allowed sentry-sdk 3.x',
body: '',
pr: { remote: { number: '123', author: { login: 'alice' } } },
},
],
null,
);
mockClient.mockResolvedValueOnce({
repository: {
P123: {
commits: {
nodes: [
{
commit: {
authors: {
nodes: [
{
email: 'alice@example.com',
user: { login: 'alice' },
},
// Resolves to a regular GitHub user, not a bot account
{
email: 'noreply@anthropic.com',
user: { login: 'claude' },
},
],
},
},
},
{
commit: {
authors: commitAuthors(['sentry-junior[bot]', 'bob']),
},
},
],
},
},
},
});
const result = await generateChangesetFromGit(dummyGit, '1.0.0', 3);
expect(result.changelog).toContain(
'Allowed sentry-sdk 3.x by @alice and @bob with @claude and @sentry-junior in [#123]',
);
});

it('credits an AI agent that authored a commit without a PR as a bot', async () => {
mockGetChangesSince.mockResolvedValueOnce([
{
hash: 'abcdef1234567890',
title: 'Fixed the kernel',
body: '',
pr: null,
},
]);
mockClient.mockResolvedValueOnce({
repository: {
Cabcdef1234567890: {
author: {
email: 'noreply@anthropic.com',
user: { login: 'claude' },
},
authors: commitAuthors(['bob']),
associatedPullRequests: { nodes: [] },
},
},
});
const result = await generateChangesetFromGit(dummyGit, '1.0.0', 3);
expect(result.changelog).toContain(
'Fixed the kernel by @bob with @claude in',
);
});

it('keeps PR co-authors that load when another PR number fails', async () => {
setup(
[
Expand Down
46 changes: 38 additions & 8 deletions src/utils/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,26 @@ async function fetchPRFiles(prNumber: number): Promise<string[]> {
}

interface CommitAuthors {
nodes: Array<{ user: { login: string } | null }>;
nodes: Array<{ email?: string | null; user: { login: string } | null }>;
}

/**
* Commit emails of AI coding agents that add themselves as co-authors. Some,
* like `noreply@anthropic.com`, resolve to a regular GitHub user (`claude`)
* instead of a bot account, so their login alone does not identify them.
*/
const AI_AGENT_EMAILS = new Set([
'noreply@anthropic.com',
'claude@anthropic.com',
'noreply@openai.com',
'codex@openai.com',
'cursoragent@cursor.com',
'devin@cognition.ai',
'175728472+copilot@users.noreply.github.com',
]);

function isAIAgentEmail(email: string | null | undefined): boolean {
return Boolean(email && AI_AGENT_EMAILS.has(email.toLowerCase()));
}

/** PRs keyed by `P<number>` aliases, `null` for numbers that are not PRs */
Expand All @@ -116,11 +135,19 @@ interface PRCommitAuthorsResult {
>;
}

/** Returns the GitHub logins of commit authors that GitHub matched to a user. */
/**
* Returns the GitHub logins of commit authors that GitHub matched to a user.
* AI agents get a `[bot]` suffix, so that they are credited as bots.
*/
function authorLogins(nodes: CommitAuthors['nodes'] = []): string[] {
return nodes
.map(node => node.user?.login)
.filter((login): login is string => Boolean(login));
return nodes.flatMap(({ email, user }) => {
if (!user?.login) {
return [];
}
return isAIAgentEmail(email) && !/\[bot\]$/i.test(user.login)
? [`${user.login}[bot]`]
: [user.login];
});
}

/**
Expand All @@ -146,7 +173,7 @@ async function fetchPRCoAuthors(
commits(first: ${MAX_PR_COMMITS}) {
nodes {
commit {
authors(first: ${MAX_COMMIT_AUTHORS}) { nodes { user { login } } }
authors(first: ${MAX_COMMIT_AUTHORS}) { nodes { email user { login } } }
}
}
}
Expand Down Expand Up @@ -859,7 +886,7 @@ function creditAuthors(
continue;
}
seen.add(key);
// Co-authors only identify bots by their `[bot]` login suffix
// Co-authors identify bots and AI agents by their `[bot]` login suffix
if ((login === author && authorIsBot) || /\[bot\]$/i.test(login)) {
credits.bots.push(login.replace(/\[bot\]$/i, ''));
} else {
Expand Down Expand Up @@ -2500,6 +2527,7 @@ async function generateChangesetFromGitImpl(

interface CommitInfo {
author: {
email?: string | null;
user?: { login: string };
};
authors?: CommitAuthors;
Expand Down Expand Up @@ -2574,10 +2602,11 @@ export async function getPRAndLabelsFromCommit(hashes: string[]): Promise<

fragment PRFragment on Commit {
author {
email
user { login }
}
authors(first: ${MAX_COMMIT_AUTHORS}) {
nodes { user { login } }
nodes { email user { login } }
}
associatedPullRequests(first: 1) {
nodes {
Expand Down Expand Up @@ -2674,6 +2703,7 @@ export async function getPRAndLabelsFromCommit(hashes: string[]): Promise<
}
: {
author: commit?.author.user?.login,
authorIsBot: isAIAgentEmail(commit?.author.email),
coAuthors,
pr: null,
prTitle: null,
Expand Down
Loading