-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask2.rb
executable file
·29 lines (27 loc) · 1003 Bytes
/
task2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
type = ARGV[0]
repo = ARGV[1]
# check for input parameters
if type.nil? || repo.nil? || (type != 'issues' && type != 'pulls') || repo.match(%r{[\w\.\-\@]+/[\w\.\-]+}).nil?
puts 'Sample script that shows doc stats for a github repo.'
puts 'usage: pulls|issues github/repo'
puts 'Example: ruby myprog.rb issues openshift/origin'
exit 1
end
repo_user, repo_name = repo.scan(%r{([\w\.\-\@]+)/([\w\.\-]+)})[0]
type = 'pr' if 'pulls' == type
# now ask github twice for open and closed issues, dependent of type
begin
rep = {}
%w(open closed).each do |state|
request = "https://api.github.com/search/issues?q=type:#{type}+state:#{state}+repo:#{repo}"
body = URI.parse(request).read
rep[state] = JSON.parse(body)['total_count']
end
puts "#{repo} #{'pr' == type ? 'pull requests' : 'issues'}: #{rep['closed']} closed, #{rep['open']} open"
rescue URI::Error => err
puts err.message
exit 1
end