Enhance project item retrieval logic with pagination support (#1061)

This commit is contained in:
Sean Morley
2026-03-16 11:02:30 -04:00
committed by GitHub
parent 6ebc820630
commit 1e4711a6a2

View File

@@ -38,7 +38,7 @@ jobs:
const projectId = "PVT_kwHOBeIeKs4AfmUO";
const fieldId = "PVTSSF_lAHOBeIeKs4AfmUOzgU5pCI";
// find project item
// Fast path: find project item from the issue side.
const result = await github.graphql(`
query($issueId: ID!) {
node(id: $issueId) {
@@ -62,7 +62,52 @@ jobs:
(node) => node.project?.id === projectId
);
const itemId = item?.id;
let itemId = item?.id;
// Fallback: if not found from issue.projectItems, scan the target project items with pagination.
if (!itemId) {
let hasNextPage = true;
let cursor = null;
while (hasNextPage && !itemId) {
const projectItemsResult = await github.graphql(`
query($projectId: ID!, $cursor: String) {
node(id: $projectId) {
... on ProjectV2 {
items(first: 100, after: $cursor) {
pageInfo {
hasNextPage
endCursor
}
nodes {
id
content {
... on Issue {
id
}
}
}
}
}
}
}
`, {
projectId,
cursor
});
const items = projectItemsResult.node?.items?.nodes ?? [];
const match = items.find((projectItem) => projectItem.content?.id === issueNodeId);
if (match) {
itemId = match.id;
break;
}
hasNextPage = projectItemsResult.node?.items?.pageInfo?.hasNextPage ?? false;
cursor = projectItemsResult.node?.items?.pageInfo?.endCursor ?? null;
}
}
if (!itemId) {
console.log(`Issue not in project ${projectId}`);