From 8e281efb9300ac49b138e00ccde767940c274199 Mon Sep 17 00:00:00 2001 From: Jason Penny Date: Thu, 24 Feb 2022 13:55:42 -0500 Subject: [PATCH 1/2] Script to show a count of hotfix PRs --- hotfix_count.rb | 25 +++++++++++++++++++++++++ lib/github-graphql.rb | 22 ++++++++++++++++++++++ lib/github.rb | 5 +++++ 3 files changed, 52 insertions(+) create mode 100755 hotfix_count.rb diff --git a/hotfix_count.rb b/hotfix_count.rb new file mode 100755 index 0000000..c5b7937 --- /dev/null +++ b/hotfix_count.rb @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby + +require_relative "lib/github" + +if $PROGRAM_NAME == __FILE__ + if !ENV["GITHUB_ACCESS_TOKEN"] + puts "GITHUB_ACCESS_TOKEN environment var needs to be set to a personal access token" + exit(1) + end + + if ARGV.length != 2 + puts "Usage: #{__FILE__} " + exit(1) + end + + COUNT_TO_SHOW = 20 + n = ARGV[1].to_i + s = "Hotfix counts for the release-#{n} - release-#{n - COUNT_TO_SHOW}" + puts s + puts "-" * s.length + n.downto(n - COUNT_TO_SHOW) do |release| + prs = Github.all_pull_request_ids_for_repo(ARGV[0], "base:release-#{release}") + puts "release-#{release.to_s.ljust(3)}: #{prs.length.to_s.rjust(3)}" + end +end diff --git a/lib/github-graphql.rb b/lib/github-graphql.rb index e94b7c1..de76a10 100644 --- a/lib/github-graphql.rb +++ b/lib/github-graphql.rb @@ -251,6 +251,28 @@ def self.get_open_pull_requests_for_search(search) return query(qry, vars) end + def self.get_any_pull_request_ids_for_repo(search) + qry = <<-'GRAPHQL' + query($queryString: String!) { + search(query:$queryString, type: ISSUE, first: 100) { + edges { + node { + ... on PullRequest { + id + } + } + } + } + } + GRAPHQL + + vars = { + queryString: "is:pr #{search}" + } + + return query(qry, vars) + end + def self.get_open_pull_requests_for_author(login, extra_filters="") return get_open_pull_requests_for_search("author:#{login} #{extra_filters}") end diff --git a/lib/github.rb b/lib/github.rb index 6eb95cf..4906b63 100644 --- a/lib/github.rb +++ b/lib/github.rb @@ -27,6 +27,11 @@ def self.open_pull_requests_for_repo(repo, extra_filters="") return _map_pr_data_search(data) end + def self.all_pull_request_ids_for_repo(repo, extra_filters="") + data = GithubGraphql.get_any_pull_request_ids_for_repo("repo:#{repo} #{extra_filters}") + return data["data"]["search"]["edges"] + end + def self._map_pr_data_search(data) return data["data"]["search"]["edges"].map do |edge| _pr_data(edge["node"]) unless edge.nil? From 798c83051bbd4d9aca45924f70bc6c386ed3ea3b Mon Sep 17 00:00:00 2001 From: Jason Penny Date: Thu, 24 Feb 2022 13:57:00 -0500 Subject: [PATCH 2/2] Only count merged PRs --- hotfix_count.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotfix_count.rb b/hotfix_count.rb index c5b7937..50389ac 100755 --- a/hotfix_count.rb +++ b/hotfix_count.rb @@ -19,7 +19,7 @@ puts s puts "-" * s.length n.downto(n - COUNT_TO_SHOW) do |release| - prs = Github.all_pull_request_ids_for_repo(ARGV[0], "base:release-#{release}") + prs = Github.all_pull_request_ids_for_repo(ARGV[0], "base:release-#{release} is:merged") puts "release-#{release.to_s.ljust(3)}: #{prs.length.to_s.rjust(3)}" end end