github
solutions
transformations

How to Use the GitHub Plugin to Find Pull Requests Merged Without Review

Ron Shemesh

Ron Shemesh

Did you know that you can find pull requests (PRs) on GitHub that were merged without any review? It might sound surprising, but it happens more often than you think. Unreviewed code could introduce potential risks to your codebase.The good news is that with the GitHub plugin, you can easily identify these PRs by running a straightforward query.
In this guide, we’ll show you how to build a simple query using CloudQuery’s GitHub integration to identify these unreviewed PRs. Why does it matter? Reviews catch bugs, align contributors, and improve the overall quality of your code. By finding and addressing unreviewed merges, you can ensure a higher standard of code integrity across your repositories.

Getting Started with CloudQuery and Syncing GitHub Data #

If you're new to CloudQuery, simply head over to the Downloads page to install the CloudQuery CLI and get up and running. Once you're set, you can sync your GitHub data using the CloudQuery GitHub integration plugin. This plugin pulls all your essential GitHub data—issues, pull requests, reviews, and more—into your database. After syncing, you'll be able to run insightful queries like the one we’ve discussed to uncover valuable information about your repositories.

The Search for Merges Without Reviews #

Pull requests are central to collaboration on GitHub, but sometimes they get merged without a thorough review. Why does this matter? Reviews help catch bugs, provide constructive feedback, and confirm that all contributors are aligned before the code gets integrated into the main branch. When a PR bypasses this essential process, it can introduce hidden issues into the codebase.

How to Find These PRs #

Let’s get practical. Here’s a query that you can run to find PRs that were merged without any review:
SELECT
    i.repository_id,
    i.updated_at,
    i.id,
    i.number,
    i.state,
    i.title,
    (i.pull_request->>'merged_at') AS merged_at,
    (i.user->>'login') AS user
FROM github_issues i
LEFT JOIN github_issue_pullrequest_reviews r
    ON i._cq_id = r._cq_parent_id
WHERE r._cq_parent_id IS NULL
  AND i.is_pull_request IS TRUE
  AND i.state = 'closed'
  AND (i.pull_request->>'merged_at') IS NOT NULL;
repository_idupdated_atidnumberstatetitlemerged_atuser
6686139402024-08-12 17:36:2924615565241022closedchore: Ignore non existing macro directories2024-08-12T17:36:26Zuser1
6686139402024-07-11 09:26:552401235038972closedchore: Switch to googleapis/release-please-action2024-07-11T09:26:53Zuser1
6686139402024-05-02 12:17:312275389166833closedFeat: Added IAM Macros Athena2024-05-02T12:17:30Zuser2
This query checks for all closed pull requests that have been merged but didn't have any associated reviews. The LEFT JOIN ensures we grab those PRs without a corresponding review in github_issue_pullrequest_reviews. We’re pulling in details like the repository ID, the time it was updated, the PR number, and of course, the author.

What Tables Are We Using? #

We’re working with two main tables here:
  • github_issues: This table holds the issue and pull request data, like the title, state, and author of each PR.
  • github_issue_pullrequest_reviews: This table logs the reviews for PRs. We’re using a LEFT JOIN to make sure we grab the PRs that don’t have any reviews associated with them.

Summary #

Finding pull requests that were merged without review could save you from potential headaches down the line. By running the query above, you can quickly identify and address those unreviewed merges. Whether it's tightening up the review process or just making sure nothing critical was missed, this is an easy way to boost the quality of your codebase.
Ready to dive deeper into your GitHub data? Try CloudQuery today and gain powerful insights into your repos. If you’ve got questions or want to chat with the team, reach out to us or join our Discord to connect with other users and engineers.
Ron Shemesh

Written by Ron Shemesh

Ron is a Senior Software Engineer at CloudQuery and has a background in data science and now works as a senior software engineer at CloudQuery. He has experience working in Python, SQL, React, Java and R. At CloudQuery, Ron has worked on our range of integrations and several projects foundational to platform performance. He loves taking on a challenge and using it to improve his skills.

Turn cloud chaos into clarity

Find out how CloudQuery can help you get clarity from a chaotic cloud environment with a personalized conversation and demo.

Join our mailing list

Subscribe to our newsletter to make sure you don't miss any updates.

Legal

© 2024 CloudQuery, Inc. All rights reserved.

We use tracking cookies to understand how you use the product and help us improve it. Please accept cookies to help us improve. You can always opt out later via the link in the footer.