Skip to content

Commit 96a99d2

Browse files
committed
used github id to identify repo
1 parent b6ff1fa commit 96a99d2

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

app/models/project.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class Project < ActiveRecord::Base
33
has_many :tips
44

55
def update_github_info repo
6+
self.github_id = repo.id
67
self.name = repo.name
78
self.full_name = repo.full_name
89
self.source_full_name = repo.source.full_name rescue ''
@@ -119,12 +120,20 @@ def self.update_cache
119120
end
120121
end
121122

122-
def update_info
123+
def github_info
123124
client = Octokit::Client.new \
124125
:client_id => CONFIG['github']['key'],
125126
:client_secret => CONFIG['github']['secret']
127+
if github_id.present?
128+
client.get("/repositories/#{github_id}")
129+
else
130+
client.repo(full_name)
131+
end
132+
end
133+
134+
def update_info
126135
begin
127-
update_github_info(client.repo(full_name))
136+
update_github_info(github_info)
128137
rescue Octokit::BadGateway, Octokit::NotFound, Octokit::InternalServerError,
129138
Errno::ETIMEDOUT, Net::ReadTimeout, Faraday::Error::ConnectionFailed => e
130139
Rails.logger.info "Project ##{id}: #{e.class} happened"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddGithubIdToProjects < ActiveRecord::Migration
2+
def change
3+
add_column :projects, :github_id, :string
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20140102095035) do
14+
ActiveRecord::Schema.define(version: 20140207061855) do
1515

1616
create_table "deposits", force: true do |t|
1717
t.integer "project_id"
@@ -40,6 +40,7 @@
4040
t.string "language"
4141
t.string "last_commit"
4242
t.integer "available_amount_cache"
43+
t.string "github_id"
4344
end
4445

4546
create_table "sendmanies", force: true do |t|

0 commit comments

Comments
 (0)