Created
July 28, 2026 09:13
-
-
Save Paxa/9fbc6cb9dd9a5a027ecc5cd5d6e5dd76 to your computer and use it in GitHub Desktop.
check all repos in orgnaization for dependabot security alerts
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
| require 'excon' | |
| require 'json' | |
| require 'pp' | |
| GH_ORG = "my org".freeze | |
| GH_TOKEN = "xxx".freeze | |
| GH_HEADERS = { | |
| "accept" => "application/vnd.github+json", | |
| "authorization" => "Bearer #{GH_TOKEN}", | |
| "user-agent" => "Awesome-Octocat-App" | |
| }.freeze | |
| parsed = [] | |
| page_url = "https://api.github.com/orgs/#{GH_ORG}/dependabot/alerts?state=open&per_page=30" | |
| loop do | |
| # puts "get #{page_url}" | |
| response = Excon.get(page_url, headers: GH_HEADERS) | |
| parsed += JSON.parse(response.body, symbolize_names: true) | |
| print "#" | |
| if response.headers["Link"] | |
| link_match = response.headers["Link"].match(/<(.+?)>; rel=\"next\"/) | |
| break unless link_match | |
| page_url = link_match[1] | |
| else | |
| break | |
| end | |
| end | |
| puts "\nFetched #{parsed.count} alerts" | |
| by_repo = {} | |
| parsed.each do |alert| | |
| next if alert[:state] == "fixed" | |
| repo_name = alert[:repository][:full_name] | |
| by_repo[repo_name] ||= [] | |
| by_repo[repo_name] << alert | |
| end | |
| by_repo.each do |repo_name, alerts| | |
| puts "https://github.com/#{repo_name}:\t#{alerts.count}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment