From 060dd8aced2a492c6911e2e55a911701274cc2c7 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 19 Jun 2016 17:40:23 +0200 Subject: [PATCH] delete github/find_or_create[org|repo|user] services --- Rakefile | 17 +--- .../travis-core/lib/travis/github/services.rb | 7 +- .../github/services/find_or_create_org.rb | 80 ------------------- .../github/services/find_or_create_repo.rb | 44 ---------- .../github/services/find_or_create_user.rb | 66 --------------- vendor/travis-core/lib/travis/model/user.rb | 1 + 6 files changed, 4 insertions(+), 211 deletions(-) delete mode 100644 vendor/travis-core/lib/travis/github/services/find_or_create_org.rb delete mode 100644 vendor/travis-core/lib/travis/github/services/find_or_create_repo.rb delete mode 100644 vendor/travis-core/lib/travis/github/services/find_or_create_user.rb diff --git a/Rakefile b/Rakefile index 27b2da1b..dde12314 100644 --- a/Rakefile +++ b/Rakefile @@ -26,7 +26,7 @@ end # not sure how else to include the spec_helper namespace :spec do desc 'Run all specs' - task :api do + task :all do sh 'bundle exec rspec -r spec_helper spec spec_core' end @@ -42,18 +42,3 @@ namespace :spec do end task :default => :'spec:all' - -desc "generate gemspec" -task 'travis-api.gemspec' do - content = File.read 'travis-api.gemspec' - - fields.each do |field, values| - updated = " s.#{field} = [" - updated << values.map { |v| "\n %p" % v }.join(',') - updated << "\n ]" - content.sub!(/ s\.#{field} = \[\n( .*\n)* \]/, updated) - end - - File.open('travis-api.gemspec', 'w') { |f| f << content } -end -task default: 'travis-api.gemspec' diff --git a/vendor/travis-core/lib/travis/github/services.rb b/vendor/travis-core/lib/travis/github/services.rb index 4f2b028a..b955f341 100644 --- a/vendor/travis-core/lib/travis/github/services.rb +++ b/vendor/travis-core/lib/travis/github/services.rb @@ -1,11 +1,8 @@ +require 'travis/github/services/set_hook' + module Travis module Github module Services - require 'travis/github/services/find_or_create_org' - require 'travis/github/services/find_or_create_repo' - require 'travis/github/services/find_or_create_user' - require 'travis/github/services/set_hook' - class << self def register constants(false).each { |name| const_get(name) } diff --git a/vendor/travis-core/lib/travis/github/services/find_or_create_org.rb b/vendor/travis-core/lib/travis/github/services/find_or_create_org.rb deleted file mode 100644 index 7bb4e748..00000000 --- a/vendor/travis-core/lib/travis/github/services/find_or_create_org.rb +++ /dev/null @@ -1,80 +0,0 @@ -require 'gh' -require 'travis/services/base' -require 'travis/model/organization' -require 'travis/model/repository' -require 'travis/model/user' - -module Travis - module Github - module Services - class FindOrCreateOrg < Travis::Services::Base - register :github_find_or_create_org - - def run - find || create - end - - private - - def find - ::Organization.where(:github_id => params[:github_id]).first.tap do |organization| - if organization - ActiveRecord::Base.transaction do - login = params[:login] || data['login'] - if organization.login != login - Repository.where(owner_name: organization.login). - update_all(owner_name: login) - organization.update_attributes(login: login) - end - - nullify_logins(organization.github_id, organization.login) - end - end - end - end - - def nullify_logins(github_id, login) - users = User.where(["login = ?", login]) - if users.exists? - Travis.logger.info("About to nullify login (#{login}) for users: #{users.map(&:id).join(', ')}") - users.update_all(login: nil) - end - - organizations = Organization.where(["github_id <> ? AND login = ?", github_id, login]) - if organizations.exists? - Travis.logger.info("About to nullify login (#{login}) for organizations: #{organizations.map(&:id).join(', ')}") - organizations.update_all(login: nil) - end - end - - def create - organization = Organization.create!( - :name => data['name'], - :login => data['login'], - :github_id => data['id'], - :email => data['email'], - :location => data['location'], - :avatar_url => data['_links'] && data['_links']['avatar'].try(:fetch, 'href'), - :company => data['company'], - :homepage => data['_links'] && data['_links']['blog'].try(:fetch, 'href') - ) - - nullify_logins(organization.github_id, organization.login) - - organization - rescue ActiveRecord::RecordNotUnique - find - end - - def avatar_url(github_data) - href = github_data.try(:fetch, 'href') - href ? href[/^(https:\/\/[\w\.\/]*)/, 1] : nil - end - - def data - @data ||= GH["organizations/#{params[:github_id]}"] || raise(Travis::GithubApiError) - end - end - end - end -end diff --git a/vendor/travis-core/lib/travis/github/services/find_or_create_repo.rb b/vendor/travis-core/lib/travis/github/services/find_or_create_repo.rb deleted file mode 100644 index c85835cf..00000000 --- a/vendor/travis-core/lib/travis/github/services/find_or_create_repo.rb +++ /dev/null @@ -1,44 +0,0 @@ -module Travis - module Github - module Services - class FindOrCreateRepo < Travis::Services::Base - register :github_find_or_create_repo - - def run - repo = find || create - repo.update_attributes(params) - repo - end - - private - - def find - unless params[:github_id] - message = "No github_id passed to FindOrCreateRepo#find, params: #{params.inspect}" - ActiveSupport::Deprecation.warn(message) - Travis.logger.info(message) - end - - query = if params[:github_id] - { github_id: params[:github_id] } - else - { owner_name: params[:owner_name], name: params[:name] } - end - - run_service(:find_repo, query) - end - - def create - unless params[:github_id] - message = "No github_id passed to FindOrCreateRepo#find, params: #{params.inspect}" - ActiveSupport::Deprecation.warn(message) - Travis.logger.info(message) - end - Repository.create!(:owner_name => params[:owner_name], :name => params[:name], github_id: params[:github_id]) - rescue ActiveRecord::RecordNotUnique - find - end - end - end - end -end diff --git a/vendor/travis-core/lib/travis/github/services/find_or_create_user.rb b/vendor/travis-core/lib/travis/github/services/find_or_create_user.rb deleted file mode 100644 index 839eb5e8..00000000 --- a/vendor/travis-core/lib/travis/github/services/find_or_create_user.rb +++ /dev/null @@ -1,66 +0,0 @@ -require 'gh' -require 'travis/model/repository' -require 'travis/model/user' -require 'travis/model/user/renaming' -require 'travis/services/base' - -module Travis - module Github - module Services - class FindOrCreateUser < Travis::Services::Base - register :github_find_or_create_user - - def run - find || create - end - - private - - include ::User::Renaming - - def find - ::User.where(github_id: params[:github_id]).first.tap do |user| - if user - ActiveRecord::Base.transaction do - login = params[:login] || data['login'] - if user.login != login - Travis.logger.info("Changing # login: current=\"#{user.login}\", new=\"#{login}\" (FindOrCreateUser), data: #{data.inspect}") - rename_repos_owner(user.login, login) - user.update_attributes(login: login) - end - end - - nullify_logins(user.github_id, user.login) - end - end - end - - def create - user = User.create!( - :name => data['name'], - :login => data['login'], - :email => data['email'], - :github_id => data['id'], - :gravatar_id => data['gravatar_id'] - ) - - nullify_logins(user.github_id, user.login) - - user - rescue ActiveRecord::RecordNotUnique - find - end - - def data - @data ||= fetch_data - end - - def fetch_data - data = GH["user/#{params[:github_id]}"] || raise(Travis::GithubApiError) - Travis.logger.info("Fetching data for github_id=#{params[:github_id]} (FindOrCreateUser), data: #{data.inspect}") - data - end - end - end - end -end diff --git a/vendor/travis-core/lib/travis/model/user.rb b/vendor/travis-core/lib/travis/model/user.rb index 89a2ec9c..9cfe0fcf 100644 --- a/vendor/travis-core/lib/travis/model/user.rb +++ b/vendor/travis-core/lib/travis/model/user.rb @@ -4,6 +4,7 @@ require 'travis/github/oauth' class User < Travis::Model require 'travis/model/user/oauth' + require 'travis/model/user/renaming' has_many :tokens, dependent: :destroy has_many :memberships, dependent: :destroy