如何筛选GitHub仓库近6个月未即时获批且含评审讨论的PR?
Absolutely—this is a totally doable task, and GitHub gives you several ways to pull this data, depending on whether you want a quick manual check or an automated report. Let's break down the options:
1. Quick Manual Check via GitHub Web UI
If you just need a one-off look, the web UI's search filters are your friend. Here's how to do it:
Head to your repository's Pull Requests tab.
In the top search bar, use this query (replace
YYYY-MM-DDwith the date exactly 6 months before today):is:pr created:>=YYYY-MM-DD comments:>=1 -review:noneLet's break down what this does:
is:pr: Targets only pull requests (not issues).created:>=YYYY-MM-DD: Limits results to PRs opened in the last 6 months.comments:>=1: Ensures the PR has at least one comment (so there's discussion during review).-review:none: Excludes PRs that never received any review at all (since we care about PRs that went through a review process).
For each PR in the results, click into it and check the Conversation tab. Look at the timeline: if the approval came after back-and-forth comments (or code review comments), that's evidence of meaningful review. If approval was the first action with no prior comments, you can flag those as "instant approvals" to exclude from your valid review set.
Pro tip: If you want to focus on code-specific review comments (not just general conversation), swap comments:>=1 with review-comments:>=1 in the query.
2. Automated Checks with GitHub CLI
If you want to automate this or export data for reporting, GitHub CLI (gh) is perfect. First, make sure you have gh installed and authenticated to your account.
- First, calculate the date 6 months ago (works on macOS/Linux):
SIX_MONTHS_AGO=$(date -d "-6 months" +%Y-%m-%d) - Then, run this command to list matching PRs with key details (replace
owner/repowith your repo's full name):
This outputs JSON with PR numbers, titles, creation dates, review status, and comment counts. You can pipe this togh pr list --repo owner/repo --created "$SIX_MONTHS_AGO".. --state all --search "comments:>=1 -review:none" --json number,title,createdAt,updatedAt,reviewDecision,commentsCountjqto filter further—for example, to get only approved PRs that had more than 1 comment (indicating discussion before approval):gh pr list --repo owner/repo --created "$SIX_MONTHS_AGO".. --state all --search "comments:>=1 -review:none" --json number,title,createdAt,updatedAt,reviewDecision,commentsCount | jq '.[] | select(.reviewDecision == "APPROVED" and .commentsCount > 1)'
3. Custom Reports with GitHub REST API
For full control (like building a custom dashboard or detailed report), use the GitHub REST API. Here's a high-level workflow:
- Use the pull requests endpoint to fetch all PRs created in the last 6 months, using parameters like
state=allandcreated>=YYYY-MM-DD. - For each PR, fetch its review comments and review events via dedicated endpoints for PR comments and reviews.
- Analyze the timeline: Check if the first review event was an approval with no prior comments (instant approval) or if there were comments/review iterations before approval (meaningful review).
You can write a simple script in Python, JavaScript, or any language of your choice to automate this and generate a structured report.
Important Considerations
- Define "Instant Approval": Be clear on what counts as "instant"—e.g., approval within 10 minutes of PR creation, or approval with no prior comments. Adjust your filters/scripts to match this definition.
- Repo Settings: If your repo doesn't require reviews, you'll want to exclude PRs that were merged without any review activity (the
-review:nonefilter helps with this). - False Positives: Some PRs might have trivial comments (like "LGTM" before approval)—you might want to add logic to filter those out if you're looking for substantial discussion.
Content of this question comes from Stack Exchange, asked by wintermeyer




