-
Notifications
You must be signed in to change notification settings - Fork 372
PR review bot #3326
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
PR review bot #3326
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5ddd48f
PR review bot
5ff5538
updated reviewers
d64bb42
draft PR inclusion
12105c5
test draft PR for review bot
8c11874
copilot review fixes
7e2463c
Merge branch 'main' into Usr/sogh/prreviewbot
d085f1f
Merge branch 'main' into Usr/sogh/prreviewbot
9cfc781
added fixes and PR review suggesstions
0ec4dfc
Merge branch 'main' of https://github.com/Azure/data-api-builder into…
77733d6
Fixed review comments
194e274
Fixes and improvements
b169d89
Address review comments: paginate listReviews, strip label after assi…
d2fe2f3
Address review comments + add temp push trigger for testing
d74bcae
Merge branch 'main' into Usr/sogh/prreviewbot
9fb3069
Merge branch 'Usr/sogh/prreviewbot' of https://github.com/Azure/data-…
f9d9723
Fix: exclude PR author from assigned count — author cannot review the…
f700c93
Fix: remove duplicate author declaration
ac432e6
Turn off dry-run for live testing
97ec29a
Remove GHCP inst file and TODO section
1ca8743
remove GHCP inst file
7b206d6
Merge branch 'main' into Usr/sogh/prreviewbot
a43a208
Merge branch 'main' into Usr/sogh/prreviewbot
7973eef
Set DRY_RUN to false for pull_request_target events
2972316
Randomize assignees instead of fixed/alphabetical ordering
ca3d956
Merge branch 'main' into Usr/sogh/prreviewbot
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,160 @@ | ||
| name: PR Review Assignment Bot | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| types: [opened, reopened, synchronize, labeled] | ||
|
|
||
|
souvikghosh04 marked this conversation as resolved.
|
||
| workflow_dispatch: | ||
| inputs: | ||
| dry_run: | ||
| description: 'Run in dry-run mode (no actual assignments)' | ||
|
souvikghosh04 marked this conversation as resolved.
|
||
| required: false | ||
| default: 'true' | ||
| type: choice | ||
| options: | ||
| - 'true' | ||
| - 'false' | ||
|
|
||
| # schedule: | ||
| # - cron: "*/10 * * * *" | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: pr-review-assignment | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| assign-reviewers: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
|
souvikghosh04 marked this conversation as resolved.
|
||
| - name: Assign reviewers to eligible PRs | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const reviewers = ["souvikghosh04", "Aniruddh25", "aaronburtle", "anushakolan", "RubenCerna2079", "JerryNixon"]; | ||
| const REQUIRED_REVIEWERS = 2; | ||
| const DRY_RUN = '${{ github.event.inputs.dry_run || 'true' }}' === 'true'; | ||
|
souvikghosh04 marked this conversation as resolved.
Outdated
|
||
|
|
||
| const { owner, repo } = context.repo; | ||
|
|
||
| // Fetch all open PRs (paginated) | ||
|
souvikghosh04 marked this conversation as resolved.
Outdated
|
||
| const allPRs = await github.paginate(github.rest.pulls.list, { | ||
|
souvikghosh04 marked this conversation as resolved.
Outdated
|
||
| owner, | ||
| repo, | ||
| state: "open", | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| // Determine if a PR is eligible | ||
| function isEligible(pr) { | ||
| const labels = pr.labels.map((l) => l.name); | ||
| if (!labels.includes("assign-for-review")) return false; | ||
| // if (pr.draft) return false; | ||
|
souvikghosh04 marked this conversation as resolved.
Outdated
|
||
| const totalReviewers = (pr.requested_reviewers || []).length + (pr.requested_teams || []).length; | ||
| if (totalReviewers >= REQUIRED_REVIEWERS) return false; | ||
|
souvikghosh04 marked this conversation as resolved.
Outdated
|
||
| return true; | ||
| } | ||
|
|
||
| // Calculate PR weight from labels | ||
| function getWeight(pr) { | ||
| const labels = pr.labels.map((l) => l.name); | ||
|
souvikghosh04 marked this conversation as resolved.
|
||
| let weight = 1; | ||
| if (labels.includes("size-medium")) weight = 2; | ||
| else if (labels.includes("size-large")) weight = 3; | ||
| if (labels.includes("priority-high")) weight += 1; | ||
| return weight; | ||
| } | ||
|
|
||
| // Build load map from all load-relevant PRs (assigned + unassigned) | ||
| const load = {}; | ||
| for (const r of reviewers) { | ||
| load[r] = 0; | ||
| } | ||
|
|
||
| // Debug: log all open PRs for diagnosis | ||
| core.info(`Total open PRs fetched: ${allPRs.length}`); | ||
| for (const pr of allPRs) { | ||
| const labels = pr.labels.map((l) => l.name); | ||
| core.info(` PR #${pr.number}: draft=${pr.draft}, labels=[${labels.join(", ")}]`); | ||
| } | ||
|
|
||
| const loadRelevantPRs = allPRs.filter((pr) => { | ||
| const labels = pr.labels.map((l) => l.name); | ||
| return labels.includes("assign-for-review"); | ||
|
souvikghosh04 marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| const eligiblePRs = allPRs.filter(isEligible); | ||
| core.info(`Total eligible PRs: ${eligiblePRs.length}`); | ||
|
|
||
| for (const pr of loadRelevantPRs) { | ||
| const weight = getWeight(pr); | ||
| const assigned = (pr.requested_reviewers || []).map((r) => r.login); | ||
|
souvikghosh04 marked this conversation as resolved.
Outdated
|
||
| for (const reviewer of assigned) { | ||
| if (reviewer in load) { | ||
| load[reviewer] += weight; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| core.info(`Current load: ${JSON.stringify(load)}`); | ||
|
|
||
| // Sort eligible PRs by weight descending (prioritize large PRs) | ||
| eligiblePRs.sort((a, b) => getWeight(b) - getWeight(a)); | ||
|
|
||
| // Assign reviewers to each eligible PR | ||
| for (const pr of eligiblePRs) { | ||
| const weight = getWeight(pr); | ||
| const assigned = (pr.requested_reviewers || []).map((r) => r.login); | ||
| const needed = REQUIRED_REVIEWERS - assigned.length; | ||
|
|
||
| core.info(`PR #${pr.number} — weight: ${weight}, existing reviewers: [${assigned.join(", ")}]`); | ||
|
|
||
| if (needed <= 0) { | ||
| core.info(`PR #${pr.number} already has ${REQUIRED_REVIEWERS} reviewers, skipping.`); | ||
| continue; | ||
|
souvikghosh04 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| const author = pr.user.login; | ||
|
|
||
| // Build candidates: exclude author and already-assigned reviewers | ||
| const candidates = reviewers | ||
| .filter((r) => r !== author && !assigned.includes(r)); | ||
|
|
||
| if (candidates.length === 0) { | ||
| core.info(`PR #${pr.number} — no candidates after filtering.`); | ||
| continue; | ||
| } | ||
|
|
||
| candidates.sort((a, b) => { | ||
| if (load[a] !== load[b]) return load[a] - load[b]; | ||
| return a.localeCompare(b); | ||
| }); | ||
|
|
||
| core.info(`PR #${pr.number} candidates: ${JSON.stringify(candidates)}`); | ||
|
|
||
| const selected = candidates.slice(0, needed); | ||
|
|
||
| if (DRY_RUN) { | ||
| core.info(`[DRY RUN] Would assign [${selected.join(", ")}] to PR #${pr.number}`); | ||
| } else { | ||
| await github.rest.pulls.requestReviewers({ | ||
| owner, | ||
| repo, | ||
| pull_number: pr.number, | ||
| reviewers: selected, | ||
|
souvikghosh04 marked this conversation as resolved.
Outdated
|
||
| }); | ||
| core.info(`Assigned [${selected.join(", ")}] to PR #${pr.number}`); | ||
| } | ||
|
|
||
|
souvikghosh04 marked this conversation as resolved.
|
||
| // Update load in-memory | ||
| for (const reviewer of selected) { | ||
| load[reviewer] += weight; | ||
| } | ||
|
|
||
| core.info(`Updated load: ${JSON.stringify(load)}`); | ||
| } | ||
|
|
||
| core.info("Review assignment complete."); | ||
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.