š„Letās Do DevOps: GitHub Power User ā Find All PRs with Specific Title Org-Wide with Rest API
--
This blog series focuses on presenting complex DevOps projects as simple and approachable via plain language and lots of pictures. You can do it!
Hey all!
Recently, Iāve been getting our GitHub Enterprise up to snuff. For other CI platforms, youād set policies at the Enterprise level that all the Orgs and Repos would inherit ā e.g., permissions. Thereās also usually robust search for things.
However, those features are either not quite present or are presented as a āyou can do it⦠with the APIā. So letās do it. With the API!
Letās dive into why you might need to search your whole Org for every Repo, and look at each PR. If youād rather skip to code, scroll to the bottom of this article and click on the GitHub link ā all code provided so you can build it too!
The Problem
In some CI tools, you have the ability to set a single Action/Automation as a required run, and set a single pipeline that must run for every PR to qualify to be merged. There are lots of justifications for this ā a tool that does static analysis of code, a code linter, a tool which validates that organization best-practices were followed.
GitHub lets you do this only at the single-Repo level. Which sounds totally reasonable until you need to deploy a tool like I described above to hundreds of repos. Thatās a huge, annoying problem. And I have a write-up coming for the tool Iāve built to do just that ā iterate through all repos, add Action(s), commit them, push to remote, and open a PR.
However, imagine weāre past that. Youāve now opened 180 PRs and need to track how many remain open so you can poke the teams that control those repos and havenāt yet taken care of merging them yet. Manually searching for those PRs is an annoying problem.
One which can be solved with GitHubās robust REST API and a bit of scripting magic. The script I wrote is linked at the bottom of this write-up. Letās step through each section and what it does. Thatās not much to it at all.