17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/models/hubstats/repo.rb', line 17
def self.create_or_update(github_repo)
github_repo = github_repo.to_h.with_indifferent_access if github_repo.respond_to? :to_h
repo_data = github_repo.slice(*column_names.map(&:to_sym))
if github_repo[:owner]
user = Hubstats::User.create_or_update(github_repo[:owner])
repo_data[:owner_id] = user[:id]
end
repo = where(:id => repo_data[:id]).first_or_create(repo_data)
return repo if repo.update_attributes(repo_data)
Rails.logger.warn repo.errors.inspect
end
|