Created
June 12, 2015 03:04
-
-
Save tgxworld/c37cfe223ffc0aee5fa4 to your computer and use it in GitHub Desktop.
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
# git log --since 03-02-2014 --pretty=format:"%H %ad" > a.txt | |
require 'byebug' | |
require 'date' | |
require 'json' | |
require 'faraday' | |
commits = [] | |
File.open('/home/guoxiang/work/ruby/a.txt', 'r').each_line do |line| | |
line =~ /\A(\w{40}) (.+)/ | |
commits << [$1, DateTime.parse($2)] | |
end | |
commits.sort_by! do |c| | |
c[1] | |
end | |
commits.each_slice(3) do |slice| | |
connection = Faraday.new(url: 'https://api.github.com') | |
response = connection.get do |request| | |
request.url "/repos/ruby/ruby/commits/#{slice.first.first}" | |
request.params = { access_token: 'b2dfd026c817f2df2cd344f717c5c8c8126ce60c' } | |
end | |
commit_hash = JSON.parse(response.body) | |
connection_2 = Faraday.new(url: 'http://rubybench.org/') | |
connection_2.basic_auth('production', 'c5a74f5d0f7c94281eee94f1e62840f4bbfd452469a7ef292dc9ede8d99866246f16ffc7246096854037d87c44681101df9c3992e86fdfd4e00cc4d0cd771851') | |
connection_2.post do |request| | |
request.url '/github_event_handler' | |
request.params = { | |
'head_commit' => { | |
'id' => commit_hash['sha'], | |
'message' => commit_hash['commit']['message'], | |
'url' => commit_hash['html_url'], | |
'timestamp' => commit_hash['commit']['committer']['date'], | |
'author' => { | |
'name' => commit_hash['commit']['author']['name'] | |
} | |
}, | |
'repository' => { | |
'full_name' => 'tgxworld/ruby', | |
html_url: 'https://github.com/tgxworld/ruby' | |
} | |
} | |
request.headers['X-Github-Event'] = 'push' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment