Commit ee059f10 authored by Fabio Pelosin's avatar Fabio Pelosin

[Statistics] moved to Octokit

parent 873fd971
...@@ -17,4 +17,5 @@ group :development do ...@@ -17,4 +17,5 @@ group :development do
gem "vcr" gem "vcr"
gem "webmock" gem "webmock"
gem "awesome_print" gem "awesome_print"
gem "pry"
end end
...@@ -10,6 +10,7 @@ GEM ...@@ -10,6 +10,7 @@ GEM
addressable (2.2.7) addressable (2.2.7)
awesome_print (1.0.2) awesome_print (1.0.2)
bacon (1.1.0) bacon (1.1.0)
coderay (1.0.5)
colored (1.2) colored (1.2)
crack (0.3.1) crack (0.3.1)
escape (0.0.4) escape (0.0.4)
...@@ -24,6 +25,7 @@ GEM ...@@ -24,6 +25,7 @@ GEM
kicker (2.5.0) kicker (2.5.0)
rb-fsevent rb-fsevent
metaclass (0.0.1) metaclass (0.0.1)
method_source (0.7.1)
mocha (0.10.5) mocha (0.10.5)
metaclass (~> 0.0.1) metaclass (~> 0.0.1)
mocha-on-bacon (0.2.0) mocha-on-bacon (0.2.0)
...@@ -37,9 +39,14 @@ GEM ...@@ -37,9 +39,14 @@ GEM
hashie (~> 1.2) hashie (~> 1.2)
multi_json (~> 1.0) multi_json (~> 1.0)
open4 (1.3.0) open4 (1.3.0)
pry (0.9.8.4)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
slop (>= 2.4.4, < 3)
rack (1.4.1) rack (1.4.1)
rake (0.9.2.2) rake (0.9.2.2)
rb-fsevent (0.9.1) rb-fsevent (0.9.1)
slop (2.4.4)
vcr (2.0.1) vcr (2.0.1)
webmock (1.8.6) webmock (1.8.6)
addressable (>= 2.2.7) addressable (>= 2.2.7)
...@@ -58,6 +65,7 @@ DEPENDENCIES ...@@ -58,6 +65,7 @@ DEPENDENCIES
mocha-on-bacon mocha-on-bacon
octokit octokit
open4 open4
pry
rake rake
rb-fsevent rb-fsevent
vcr vcr
......
...@@ -54,7 +54,7 @@ module Pod ...@@ -54,7 +54,7 @@ module Pod
separator = "\n - " separator = "\n - "
t << separator + value.join(separator) t << separator + value.join(separator)
else else
t << " #{spaces + value}\n" t << " #{spaces + value.to_s}\n"
end end
end end
end end
......
...@@ -37,7 +37,7 @@ module Pod ...@@ -37,7 +37,7 @@ module Pod
end end
def create def create
if repo_id = @name_or_url[/github.com\/([^\/]*\/[^\/]*).*/, 1] if repo_id = @name_or_url[/github.com\/([^\/\.]*\/[^\/\.]*)\.*/, 1]
data = github_data_for_template(repo_id) data = github_data_for_template(repo_id)
puts semantic_versioning_notice(repo_id, data[:name]) if data[:tag] == 'HEAD' puts semantic_versioning_notice(repo_id, data[:name]) if data[:tag] == 'HEAD'
else else
......
require 'net/https'
require 'uri'
require 'yaml' require 'yaml'
require 'octokit'
module Pod module Pod
class Specification class Specification
...@@ -77,34 +76,23 @@ module Pod ...@@ -77,34 +76,23 @@ module Pod
def github_stats_if_needed(set) def github_stats_if_needed(set)
return if get_value(set, :gh_date) && get_value(set, :gh_date) > Time.now - cache_expiration return if get_value(set, :gh_date) && get_value(set, :gh_date) > Time.now - cache_expiration
spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification
url = spec.source.reject {|k,_| k == :commit || k == :tag }.values.first url = spec.source.reject {|k,_| k == :commit || k == :tag }.values.first
gh_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a) repo_id = url[/github.com\/([^\/\.]*\/[^\/\.]*)\.*/, 1]
return unless repo_id
return unless gh_url
response_body = fetch_stats(username, reponame) begin
repo = Octokit.repo(repo_id)
return unless response_body rescue
watchers = response_body.match(/"watchers"\W*:\W*([0-9]+)/).to_a[1] return
forks = response_body.match(/"forks"\W*:\W*([0-9]+)/).to_a[1] end
return unless watchers && forks
cache[set.name] ||= {} cache[set.name] ||= {}
set_value(set, :gh_watchers, watchers) set_value(set, :gh_watchers, repo['watchers'])
set_value(set, :gh_forks, forks) set_value(set, :gh_forks, repo['forks'])
set_value(set, :gh_date, Time.now) set_value(set, :gh_date, Time.now)
save_cache save_cache
end end
def fetch_stats(username, reponame)
uri = URI.parse("https://api.github.com/repos/#{username}/#{reponame}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
response.body if response.is_a?(Net::HTTPSuccess)
end
end end
end end
end end
...@@ -22,8 +22,8 @@ describe Pod::Command::Presenter do ...@@ -22,8 +22,8 @@ describe Pod::Command::Presenter do
end end
it "presents the stats of a specification set" do it "presents the stats of a specification set" do
response = '{"repository":{"homepage":"","url":"https://github.com/robbiehanson/CocoaLumberjack","has_downloads":true,"has_issues":true,"language":"Objective-C","master_branch":"master","forks":42,"fork":false,"created_at":"2011/03/30 19:38:39 -0700","has_wiki":true,"description":"A fast & simple, yet powerful & flexible logging framework for Mac and iOS","size":416,"private":false,"name":"CocoaLumberjack","owner":"robbiehanson","open_issues":4,"watchers":318,"pushed_at":"2012/03/26 12:39:36 -0700"}}% ' repo = {"forks"=>42, "watchers"=>318}
Pod::Specification::Statistics.instance.expects(:fetch_stats).with("robbiehanson", "CocoaLumberjack").returns(response) Octokit.expects(:repo).with("robbiehanson/CocoaLumberjack").returns(repo)
presenter = Presenter.new(argv('--stats')) presenter = Presenter.new(argv('--stats'))
output = presenter.describe(@set) output = presenter.describe(@set)
output.should.include? 'Author: Robbie Hanson' output.should.include? 'Author: Robbie Hanson'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment