Last active
July 6, 2016 02:06
-
-
Save y-takagi/3862914 to your computer and use it in GitHub Desktop.
Auto code review group matcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'net/https' | |
require 'json' | |
require 'pit' | |
@host = "api.github.com" | |
@ng_member = [] # for bot | |
def group_match app_id, team_id, groups | |
@token = access_token(app_id) | |
member_list = team_member(team_id).delete_if { |m| @ng_member.include?(m) } | |
number = (member_list.size / groups.to_f).ceil | |
member_list.sort_by { rand }.each_slice(number).map { |m| m } | |
end | |
def team_member id | |
path = "/teams/#{id}/members?access_token=#{@token}" | |
req = Net::HTTP::Get.new(path) | |
res = https_access(req).body | |
JSON.parse(res).map { |member| member['login'] } | |
end | |
# using below link's api to get access token | |
# http://developer.github.com/v3/oauth/#get-a-single-authorization | |
def access_token app_id | |
account = Pit.get('github.com') | |
req = Net::HTTP::Get.new("/authorizations/#{app_id}") | |
req.basic_auth(account['github_username'], account['github_passwd']) | |
res = https_access(req).body | |
JSON.parse(res)['token'] | |
end | |
def https_access req | |
http = Net::HTTP.new(@host, 443) | |
http.use_ssl = true | |
http.request(req) | |
end | |
if __FILE__ == $0 | |
app_id = ARGV.shift | |
team_id = ARGV.shift | |
groups = ARGV.shift | |
group_match(app_id, team_id, groups).each do |l| | |
puts l | |
puts | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment