perf(workspaces): use GraphQL for instantaneous fork discovery

This commit is contained in:
mkorwel
2026-03-18 11:38:39 -07:00
parent c63c0d0422
commit fe79087d7a

View File

@@ -93,13 +93,22 @@ and full builds) to a dedicated, high-performance GCP worker.
console.log(` - Upstream identified: ${upstreamRepo}`);
console.log(` - Searching for your forks of ${upstreamRepo}...`);
// Use gh api to find forks specifically linked to the upstream, which is much more accurate
const upstreamOwner = upstreamRepo.split('/')[0];
const upstreamName = upstreamRepo.split('/')[1];
const userRes = spawnSync('gh', ['api', 'user', '-q', '.login'], { stdio: 'pipe' });
const currentUser = userRes.stdout.toString().trim();
const forksRes = spawnSync('gh', ['api', `/repos/${upstreamOwner}/${upstreamName}/forks`, '--paginate', '-q', `.[] | select(.owner.login == "${currentUser}") | .full_name`], { stdio: 'pipe' });
// Use GraphQL to find your forks specifically. This is much faster than REST pagination.
const gqlQuery = `query {
viewer {
repositories(first: 100, isFork: true, affiliations: OWNER) {
nodes {
nameWithOwner
parent { nameWithOwner }
}
}
}
}`;
const forksRes = spawnSync('gh', ['api', 'graphql', '-f', `query=${gqlQuery}`, '--jq', `.data.viewer.repositories.nodes[] | select(.parent.nameWithOwner == "${upstreamRepo}") | .nameWithOwner`], { stdio: 'pipe' });
const myForks = forksRes.stdout.toString().trim().split('\n').filter(Boolean);
if (myForks.length > 0) {