-
Notifications
You must be signed in to change notification settings - Fork 3
Add automation pipeline (merge gate, CI, PyPI release) #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| /** | ||
| * Idempotent CodeRabbit/Qodo kick for bot-opened PRs. | ||
| * @see .github/workflows/auto-pr-comment.yml, claude.yml, bot-pr-recovery.yml | ||
| */ | ||
|
|
||
| const KICK_AUTHORS = new Set(['MervinPraison', 'github-actions[bot]']); | ||
| const BOT_PR_AUTHORS = new Set(['praisonai-triage-agent[bot]', 'github-actions[bot]']); | ||
|
|
||
| async function listAllComments(github, owner, repo, issueNumber) { | ||
| if (typeof github.paginate === 'function') { | ||
| return github.paginate(github.rest.issues.listComments, { | ||
| owner, | ||
| repo, | ||
| issue_number: issueNumber, | ||
| per_page: 100, | ||
| }); | ||
| } | ||
| const { data } = await github.rest.issues.listComments({ | ||
| owner, | ||
| repo, | ||
| issue_number: issueNumber, | ||
| per_page: 100, | ||
| }); | ||
| return data; | ||
| } | ||
|
|
||
| function kickAuthored(comment, marker) { | ||
| return ( | ||
| KICK_AUTHORS.has(comment.user?.login) && | ||
| (comment.body || '').includes(marker) | ||
| ); | ||
| } | ||
|
|
||
| function coderabbitKickPosted(comments) { | ||
| return comments.some((c) => kickAuthored(c, '@coderabbitai review')); | ||
| } | ||
|
|
||
| function qodoKickPosted(comments) { | ||
| return comments.some( | ||
| (c) => KICK_AUTHORS.has(c.user?.login) && (c.body || '').trim() === '/review' | ||
| ); | ||
| } | ||
|
|
||
| function chainKickPosted(comments) { | ||
| return coderabbitKickPosted(comments) && qodoKickPosted(comments); | ||
| } | ||
|
|
||
| function isBotOpenedPr(pr) { | ||
| if (BOT_PR_AUTHORS.has(pr.user?.login)) return true; | ||
| return pr.user?.type === 'Bot'; | ||
| } | ||
|
|
||
| async function kickReviewChain(github, owner, repo, prNumber, core, preFetchedComments = null) { | ||
| const comments = preFetchedComments || await listAllComments(github, owner, repo, prNumber); | ||
| const needCoderabbit = !coderabbitKickPosted(comments); | ||
| const needQodo = !qodoKickPosted(comments); | ||
|
|
||
| if (!needCoderabbit && !needQodo) { | ||
| core?.info?.(`Review chain already kicked on PR #${prNumber}`); | ||
| return { kicked: false, reason: 'already_kicked' }; | ||
| } | ||
|
|
||
| if (needCoderabbit) { | ||
| await github.rest.issues.createComment({ | ||
| owner, | ||
| repo, | ||
| issue_number: prNumber, | ||
| body: '@coderabbitai review', | ||
| }); | ||
| } | ||
| if (needQodo) { | ||
| await github.rest.issues.createComment({ | ||
| owner, | ||
| repo, | ||
| issue_number: prNumber, | ||
| body: '/review', | ||
| }); | ||
| } | ||
| core?.info?.(`Kicked review chain for PR #${prNumber} (coderabbit=${needCoderabbit}, qodo=${needQodo})`); | ||
| return { kicked: true, coderabbit: needCoderabbit, qodo: needQodo }; | ||
| } | ||
|
|
||
| async function findOpenPrForIssue(github, owner, repo, issueNumber) { | ||
| const prefix = `claude/issue-${issueNumber}-`; | ||
| const { data: prs } = await github.rest.pulls.list({ | ||
| owner, | ||
| repo, | ||
| state: 'open', | ||
| sort: 'created', | ||
| direction: 'desc', | ||
| per_page: 30, | ||
| }); | ||
| return ( | ||
| prs.find( | ||
| (p) => (p.head?.ref || '').startsWith(prefix) && isBotOpenedPr(p) | ||
| ) || null | ||
| ); | ||
| } | ||
|
|
||
| async function kickReviewChainForIssue(github, owner, repo, issueNumber, core) { | ||
| const pr = await findOpenPrForIssue(github, owner, repo, issueNumber); | ||
| if (!pr) { | ||
| core?.info?.(`No open PR for issue #${issueNumber}, skipping review kick`); | ||
| return { kicked: false, reason: 'no_pr' }; | ||
| } | ||
| const result = await kickReviewChain(github, owner, repo, pr.number, core); | ||
| return { ...result, prNumber: pr.number }; | ||
| } | ||
|
|
||
| async function recoverStalledBotPrs(github, owner, repo, options, core) { | ||
| const { prNumber = null, minAgeMs = 10 * 60 * 1000, maxRecover = 10 } = options || {}; | ||
| let prs; | ||
| if (prNumber) { | ||
| const { data } = await github.rest.pulls.get({ owner, repo, pull_number: prNumber }); | ||
| prs = [data]; | ||
| } else if (typeof github.paginate === 'function') { | ||
| prs = await github.paginate(github.rest.pulls.list, { | ||
| owner, | ||
| repo, | ||
| state: 'open', | ||
| per_page: 100, | ||
| }); | ||
| } else { | ||
| const { data } = await github.rest.pulls.list({ owner, repo, state: 'open', per_page: 100 }); | ||
| prs = data; | ||
| } | ||
|
|
||
| const cutoff = Date.now() - minAgeMs; | ||
| let recovered = 0; | ||
| for (const pr of prs) { | ||
| if (recovered >= maxRecover) break; | ||
| if (!isBotOpenedPr(pr)) continue; | ||
| if (!prNumber && new Date(pr.created_at).getTime() > cutoff) continue; | ||
| const comments = await listAllComments(github, owner, repo, pr.number); | ||
| if (chainKickPosted(comments)) continue; | ||
| await kickReviewChain(github, owner, repo, pr.number, core, comments); | ||
| recovered += 1; | ||
| } | ||
| core?.info?.(`Recovery complete (${recovered} PR(s) kicked)`); | ||
| return recovered; | ||
| } | ||
|
|
||
| module.exports = { | ||
| KICK_AUTHORS, | ||
| BOT_PR_AUTHORS, | ||
| listAllComments, | ||
| chainKickPosted, | ||
| coderabbitKickPosted, | ||
| qodoKickPosted, | ||
| isBotOpenedPr, | ||
| kickReviewChain, | ||
| findOpenPrForIssue, | ||
| kickReviewChainForIssue, | ||
| recoverStalledBotPrs, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Run: node .github/scripts/ci-failure-claude-selftest.js | ||
| */ | ||
| const ciFix = require('./ci-failure-claude.js'); | ||
| const mergeGate = require('./merge-gate.js'); | ||
| const config = require('./gate-config.js'); | ||
|
|
||
| let failed = 0; | ||
| function assert(name, cond) { | ||
| if (!cond) { | ||
| console.error('FAIL:', name); | ||
| failed += 1; | ||
| } else { | ||
| console.log('ok:', name); | ||
| } | ||
| } | ||
|
|
||
| const LOG = ` | ||
| python UNKNOWN STEP FAILED (0.0100s) tests/unit/test_example.py::test_foo - AssertionError: bar | ||
| python UNKNOWN STEP ##[error]Process completed with exit code 1. | ||
| `; | ||
|
|
||
| const parsed = ciFix.parsePytestFailures(LOG); | ||
| assert('parses pytest failure', parsed.length === 1); | ||
| assert('uses CI workflow list', config.ciFailureWorkflowRuns.includes('CI')); | ||
|
|
||
| const comment = ciFix.buildCiFixComment({ | ||
| headSha: 'abc1234567890abcdef1234567890abcdef12', | ||
| failedChecks: [{ name: 'python', workflow: 'CI', html_url: 'https://example.com/job/1' }], | ||
| failureSummaries: [{ jobName: 'python', failures: parsed }], | ||
| }); | ||
| assert('comment mentions product guardrails', comment.includes('Product guardrails')); | ||
|
|
||
| process.exit(failed ? 1 : 0); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.