diff --git a/Gemfile b/Gemfile index 1c5e7e8f..b0672010 100644 --- a/Gemfile +++ b/Gemfile @@ -133,6 +133,7 @@ gem 'simple_form' gem 'tweet-button' gem 'mail_view' gem 'local_time' +gem 'github-api' # Mongo gem 'mongoid' diff --git a/Gemfile.lock b/Gemfile.lock index 115bb6be..bd5a4a03 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -271,6 +271,8 @@ GEM multi_json (~> 1.0) net-http-persistent (>= 2.7) net-http-pipeline + github-api (0.0.1) + httparty github-markdown (0.6.5) grackle (0.3.0) json @@ -740,6 +742,7 @@ DEPENDENCIES fukuzatsu fuubar (= 2.0.0.rc1) geocoder + github-api github-markdown grackle guard-rspec diff --git a/app/models/badges/ashcat.rb b/app/models/badges/ashcat.rb index 165599a0..cd979eb9 100644 --- a/app/models/badges/ashcat.rb +++ b/app/models/badges/ashcat.rb @@ -19,7 +19,7 @@ def award? end def self.perform - Github.new.repo_contributors("rails", "rails").each do |contributor| + GithubOld.new.repo_contributors("rails", "rails").each do |contributor| login = contributor[:login] add_contributor(login, contributor[:contributions]) end diff --git a/app/models/badges/entrepreneur.rb b/app/models/badges/entrepreneur.rb index 39840d41..ccd5ae0a 100644 --- a/app/models/badges/entrepreneur.rb +++ b/app/models/badges/entrepreneur.rb @@ -23,7 +23,7 @@ def self.perform repos.each do |repo| owner, name = repo.split('/')[-2..-1] - Github.new.repo_contributors(owner, name).each do |contributor| + GithubOld.new.repo_contributors(owner, name).each do |contributor| login = contributor[:login] add_contributor(repo, login, contributor[:contributions]) end diff --git a/app/models/github.rb b/app/models/github_old.rb similarity index 99% rename from app/models/github.rb rename to app/models/github_old.rb index 029cc0b0..5ce65fb6 100644 --- a/app/models/github.rb +++ b/app/models/github_old.rb @@ -1,4 +1,5 @@ -class Github +#@ deprecated +class GithubOld @@token = nil GITHUB_ROOT = "https://github.com" API_ROOT = 'https://api.github.com/' diff --git a/app/models/github_profile.rb b/app/models/github_profile.rb index ae07544a..7f924d52 100644 --- a/app/models/github_profile.rb +++ b/app/models/github_profile.rb @@ -70,7 +70,7 @@ def convert_repo_into_fact(repo, orgrepo = false) end def refresh!(client=nil, since) - client ||= Github.new + client ||= GithubOld.new username = self.login profile = client.profile(username, since) diff --git a/app/models/github_repo.rb b/app/models/github_repo.rb index f9e22510..91e3f969 100644 --- a/app/models/github_repo.rb +++ b/app/models/github_repo.rb @@ -33,7 +33,7 @@ def for_owner_and_name(owner, name, client=nil, prefetched={}) end def refresh!(client=nil, repo={}) - client ||= Github.new + client ||= GithubOld.new owner, name = self.owner.login, self.name repo = client.repo(owner, name) if repo.empty? diff --git a/app/models/user.rb b/app/models/user.rb index 54dd5479..618f3281 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -939,7 +939,7 @@ def build_repo_followed_activity!(refresh=false) REDIS.zremrangebyrank(followed_repo_key, 0, Time.now.to_i) if refresh epoch_now = Time.now.to_i first_time = refresh || REDIS.zcount(followed_repo_key, 0, epoch_now) <= 0 - links = Github.new.activities_for(self.github, (first_time ? 20 : 1)) + links = GithubOld.new.activities_for(self.github, (first_time ? 20 : 1)) links.each do |link| link[:user_id] = self.id REDIS.zadd(followed_repo_key, link[:date].to_i, link.to_json) diff --git a/spec/models/github_spec.rb b/spec/models/github_spec.rb index 64e2c8fc..d90d8ffc 100644 --- a/spec/models/github_spec.rb +++ b/spec/models/github_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Github, type: :model, functional: true, skip: ENV['TRAVIS'] do - let(:github) { Github.new } + let(:github) { GithubOld.new } it 'can get profile' do expect(github.profile('mdeiters')[:name]).to eq('Matthew Deiters') @@ -47,12 +47,12 @@ end it 'should scope requests by user' do - daniel = Github.new(daniel_h = '697b68755f419b475299873164e3c60fca21ae58') + daniel = GithubOld.new(daniel_h = '697b68755f419b475299873164e3c60fca21ae58') expect(daniel.profile['login']).to eq('flyingmachine') end it 'should scope requests by user but allow override' do - daniel = Github.new(daniel_h = '697b68755f419b475299873164e3c60fca21ae58') + daniel = GithubOld.new(daniel_h = '697b68755f419b475299873164e3c60fca21ae58') expect(daniel.profile['login']).not_to eq(daniel.profile('bguthrie')['login']) end end