Skip to content

Commit 8208e5c

Browse files
committed
Add a script to count the number of active Gerrit projects
1 parent 1c366f5 commit 8208e5c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

gerrit/count-active-projects.rb

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env ruby
2+
3+
require_relative '../bundle/bundler/setup'
4+
5+
require 'gerry'
6+
require 'set'
7+
8+
uri_str, age = ARGV
9+
if uri_str.nil? || age.nil?
10+
script = File.basename(__FILE__)
11+
puts <<EOT
12+
Usage : #{script} <uri> <age>
13+
Example : #{script} [user:password@]host[:port] 3mon
14+
15+
Rationale : Count the number of owners whose change(s) have been merged
16+
in the given age period backwards from now.
17+
EOT
18+
exit(1)
19+
end
20+
21+
uri_str = 'https://' + uri_str unless uri_str.start_with?('https://', 'http://')
22+
uri = URI.parse(uri_str)
23+
24+
uri.user = ENV['USER'] || ENV['USERNAME'] if uri.user.nil?
25+
uri.password = ENV['GERRIT_HTTP_PASSWORD'] if uri.password.nil?
26+
27+
Gerry::Client.default_options.update(verify: false)
28+
client = Gerry.new("#{uri.scheme}://#{uri.host}", uri.user, uri.password)
29+
30+
projects = Set.new
31+
changes = client.changes(["q=status:merged+-age:#{age}"])
32+
changes.each do |change|
33+
projects << change['project']
34+
end
35+
36+
puts "Number of active projects in the last #{age}: #{projects.size}"

0 commit comments

Comments
 (0)