Skip to content

Instantly share code, notes, and snippets.

@gnarl
Forked from anonymous/github_issues.rb
Created December 17, 2012 16:09
Show Gist options
  • Save gnarl/4319469 to your computer and use it in GitHub Desktop.
Save gnarl/4319469 to your computer and use it in GitHub Desktop.
require 'rest-client'
require 'json'
require 'pp'
DEBUG = true
TAB = " "
HOST = 'https://api.github.com/'
PORT = '443'
USER_NAME = 'gnarl'
TOKEN = 'secret'
OAUTH = 'access_token=' + TOKEN
def get_user_info(username)
RestClient.get HOST + 'users/' + username + '?' + OAUTH
end
def get_netapp_repo_issues(repo, page_num)
RestClient.get "#{HOST}repos/NetApp/#{repo}/issues?page=#{page_num.to_s};per_page=100;filter=all;#{OAUTH}"
end
def print_issue(issue)
#pp issue
puts issue['title']
#puts issue['assignee']['login']
puts issue['number']
end
def get_issues
page_num = 1
finished = false
issues = []
while !finished
response = get_netapp_repo_issues('SC-Framework', page_num)
page_of_issues = JSON.parse(response.body)
issues = issues + page_of_issues
page_num = page_num + 1
finished = true if page_of_issues.size < 100
end
issues
end
def issues_by_label(issues, label)
res = []
issues.each do |x|
res << x if find_label(x, label)
end
res
end
def issues_filter(issues, label)
res = []
issues.each do |x|
res << x unless find_label(x, label)
end
res
end
def issues_by_milestone(issues, version)
res = []
issues.each do |x|
unless x['milestone'].nil?
res << x if x['milestone']['title'].eql?(version)
end
end
res
end
def find_in_issues(issues)
res = []
issues.each do |x|
yield x
end
res
end
def find_label(issue, label)
found = false
issue['labels'].each do |x|
found = true if x['name'].eql?(label)
end
found
end
def log msg
puts msg if DEBUG
end
##########################################################
response = get_user_info(USER_NAME)
puts "User Info: #{response.code}"
result = JSON.parse(response.body)
puts TAB + result['email']
issues = get_issues
milestone_issues = issues_by_milestone(issues, '4.0c')
p2_issues = issues_by_label(milestone_issues, 'P2')
p2_issues_no_testme = issues_filter(p2_issues, 'TESTME')
p2_map = {}
p2_issues_no_testme.each do |x|
uname = x['assignee']['login']
unless p2_map.include? uname
p2_map[uname] = []
end
p2_map[uname] << x
end
p2_map.each do |key, value|
pp key
value.each do |issue|
puts " #{issue['number'].to_s} : #{issue['title']}"
end
puts "\n"
end
puts "P2, BUG, !TESTME => #{p2_issues_no_testme.size}"
@gnarl
Copy link
Author

gnarl commented Dec 17, 2012

Forked my own gist since I wasn't logged in when I added it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment