Skip to content

Commit

Permalink
Merge pull request #21 from jasonpenny/hotfix-count
Browse files Browse the repository at this point in the history
Script for hotfix counts
  • Loading branch information
jasonpenny authored Feb 24, 2022
2 parents 879d569 + 798c830 commit c1797b5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
25 changes: 25 additions & 0 deletions hotfix_count.rb
Original file line number Diff line number Diff line change
@@ -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__} <repo> <release number>"
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} is:merged")
puts "release-#{release.to_s.ljust(3)}: #{prs.length.to_s.rjust(3)}"
end
end
22 changes: 22 additions & 0 deletions lib/github-graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit c1797b5

Please sign in to comment.