mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
fix: replace REST API branch listing with GraphQL query for better performance
- Replaced REST API listBranches call with GraphQL query that filters branches by prefix - This fixes the issue where repositories with >100 branches could miss existing Claude branches - The GraphQL query directly filters by prefix, making it more efficient and accurate Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
This commit is contained in:
@@ -88,19 +88,36 @@ export async function setupBranch(
|
|||||||
if (!isPR) {
|
if (!isPR) {
|
||||||
// Check for existing Claude branches for this issue
|
// Check for existing Claude branches for this issue
|
||||||
try {
|
try {
|
||||||
const { data: branches } = await octokits.rest.repos.listBranches({
|
// Use GraphQL to efficiently search for branches with a specific prefix
|
||||||
|
const query = `
|
||||||
|
query($owner: String!, $repo: String!, $prefix: String!) {
|
||||||
|
repository(owner: $owner, name: $repo) {
|
||||||
|
refs(refPrefix: "refs/heads/", query: $prefix, first: 100) {
|
||||||
|
nodes {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const response = await octokits.graphql<{
|
||||||
|
repository: {
|
||||||
|
refs: {
|
||||||
|
nodes: Array<{ name: string }>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}>(query, {
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
per_page: 100,
|
prefix: `claude/issue-${entityNumber}-`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Look for existing branches with pattern claude/issue-{entityNumber}-*
|
const branches = response.repository.refs.nodes;
|
||||||
const existingBranch = branches.find(branch =>
|
|
||||||
branch.name.startsWith(`claude/issue-${entityNumber}-`)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existingBranch) {
|
if (branches.length > 0) {
|
||||||
branchToUse = existingBranch.name;
|
// Use the first matching branch (could be sorted by date in future)
|
||||||
|
branchToUse = branches[0].name;
|
||||||
isReusedBranch = true;
|
isReusedBranch = true;
|
||||||
console.log(`Found existing Claude branch for issue #${entityNumber}: ${branchToUse}`);
|
console.log(`Found existing Claude branch for issue #${entityNumber}: ${branchToUse}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user