mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
fix(agents): replace gh CLI with curl for PR checking to prevent duplicate work
Agents do not have access to gh CLI, causing them to skip the pre-flight PR check and collide on duplicate work. This replaces all gh-based PR checking commands with curl + jq using the GitHub REST API, updates the task claiming protocol to use branch push + started log file as the primary lock mechanism, and updates automation scripts to use curl for PR listing and git fetch for PR checkout. Files updated: - AGENTS.md (Section 12 coordination rules) - CLAUDE.md (coordination rules) - META_PROMPTS.md (daily + weekly meta prompts) - daily-scheduler.md (pre-flight gate, task claiming, error handling) - weekly-scheduler.md (pre-flight gate, task claiming, error handling) - bitvid-pr-review-agent.md (PR enumeration + checkout) - bitvid-ci-health-agent.md (CI run gathering) - bitvid-weekly-synthesis-agent.md (PR metadata gathering) - bitvid-changelog-agent.md (PR metadata verification) - scripts/agent/review-open-prs.mjs (PR listing + checkout) - scripts/automated-pr-review.mjs (--all mode PR listing + checkout) https://claude.ai/code/session_01L5bzzGpZ6YTiLXcfqaL81G
This commit is contained in:
11 files changed
+97
-103
No files matched your search
@@ -13,18 +13,25 @@ function runCommand(command, args = [], options = {}) {
|
||||
}
|
||||
|
||||
function getOpenPRs() {
|
||||
console.log('Fetching open PRs...');
|
||||
console.log('Fetching open PRs via GitHub API...');
|
||||
try {
|
||||
const res = spawnSync('gh', ['pr', 'list', '--json', 'number,headRefName,baseRefName,url'], { encoding: 'utf-8' });
|
||||
const res = spawnSync('curl', ['-s', 'https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100'], { encoding: 'utf-8' });
|
||||
if (res.error) {
|
||||
console.error('Error fetching PRs (gh CLI not installed?):', res.error.message);
|
||||
console.error('Error fetching PRs (curl not available?):', res.error.message);
|
||||
return [];
|
||||
}
|
||||
if (res.status !== 0) {
|
||||
console.error('Error fetching PRs:', res.stderr);
|
||||
return [];
|
||||
}
|
||||
return JSON.parse(res.stdout);
|
||||
const apiPRs = JSON.parse(res.stdout);
|
||||
// Map GitHub API response to the shape we need
|
||||
return apiPRs.map(pr => ({
|
||||
number: pr.number,
|
||||
headRefName: pr.head.ref,
|
||||
baseRefName: pr.base.ref,
|
||||
url: pr.html_url
|
||||
}));
|
||||
} catch (e) {
|
||||
console.error('Exception fetching PRs:', e);
|
||||
return [];
|
||||
@@ -52,15 +59,16 @@ async function main() {
|
||||
for (const pr of openPRs) {
|
||||
console.log(`\n=== Processing PR #${pr.number}: ${pr.url} ===`);
|
||||
try {
|
||||
// Checkout PR
|
||||
runCommand('gh', ['pr', 'checkout', pr.number]);
|
||||
// Checkout PR via git fetch
|
||||
runCommand('git', ['fetch', 'origin', `pull/${pr.number}/head:pr-${pr.number}`]);
|
||||
runCommand('git', ['checkout', `pr-${pr.number}`]);
|
||||
|
||||
// Set Environment Variables
|
||||
const env = {
|
||||
...process.env,
|
||||
PR_NUMBER: pr.number.toString(),
|
||||
GITHUB_BASE_REF: pr.baseRefName,
|
||||
// Assuming origin is the base repo or gh pr checkout handled the remote setup.
|
||||
// Assuming origin is the base repo.
|
||||
// automated-pr-review.mjs handles missing GITHUB_BASE_REPO_URL by defaulting to upstream/origin.
|
||||
};
|
||||
|
||||
|
||||
@@ -258,16 +258,20 @@ async function main() {
|
||||
const isAll = process.argv.includes('--all');
|
||||
|
||||
if (isAll) {
|
||||
console.log('Fetching all open PRs...');
|
||||
// Get list of open PRs
|
||||
const listCmd = ['pr', 'list', '--state', 'open', '--json', 'number,baseRefName,headRefName'];
|
||||
const result = spawnSync('gh', listCmd, { encoding: 'utf-8' });
|
||||
console.log('Fetching all open PRs via GitHub API...');
|
||||
// Get list of open PRs via curl (no gh dependency)
|
||||
const result = spawnSync('curl', ['-s', 'https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100'], { encoding: 'utf-8' });
|
||||
|
||||
if (result.error || result.status !== 0) {
|
||||
throw new Error(`Failed to list PRs: ${result.stderr || result.error?.message}`);
|
||||
}
|
||||
|
||||
const prs = JSON.parse(result.stdout);
|
||||
const apiPRs = JSON.parse(result.stdout);
|
||||
const prs = apiPRs.map(pr => ({
|
||||
number: pr.number,
|
||||
baseRefName: pr.base.ref,
|
||||
headRefName: pr.head.ref
|
||||
}));
|
||||
console.log(`Found ${prs.length} open PRs.`);
|
||||
|
||||
let hasGlobalFailures = false;
|
||||
@@ -284,8 +288,9 @@ async function main() {
|
||||
try {
|
||||
console.log(`\n=== Processing PR #${pr.number} ===`);
|
||||
|
||||
// Checkout PR
|
||||
runCommand('gh', ['pr', 'checkout', pr.number]);
|
||||
// Checkout PR via git fetch
|
||||
runCommand('git', ['fetch', 'origin', `pull/${pr.number}/head:pr-${pr.number}`]);
|
||||
runCommand('git', ['checkout', `pr-${pr.number}`]);
|
||||
|
||||
// Run Review
|
||||
await reviewPR(pr.number, pr.baseRefName);
|
||||
@@ -296,7 +301,7 @@ async function main() {
|
||||
// Continue to next PR
|
||||
} finally {
|
||||
// Clean up or reset if needed?
|
||||
// Since we use gh pr checkout, we are on a different branch.
|
||||
// Since we fetch and checkout each PR branch, we are on a different branch.
|
||||
// Next iteration will checkout another branch.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user