diff --git a/.gitignore b/.gitignore index 8355d94..2900862 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ config/secrets.yml coverage/ .bundle/ *.db -repostore/ -temp/ +_* diff --git a/Rakefile b/Rakefile index 6ad3e9c..6d279ec 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,7 @@ require 'rake/testtask' +desc 'Print all rake commands' task :default do puts `rake -T` end @@ -13,127 +14,108 @@ task :config do @config = @app.config end -desc 'run tests' +desc 'Run tests once' Rake::TestTask.new(:spec) do |t| t.pattern = 'spec/*_spec.rb' t.warning = false end -desc 'rerun tests' +desc 'Keep rerunning tests upon changes' task :respec => :config do puts 'REMEMBER: need to run `rake run:[dev|test]:worker` in another process' sh "rerun -c 'rake spec' --ignore 'coverage/*' --ignore '#{@config.REPOSTORE_PATH}/*'" end -desc 'run application console (pry)' +desc 'Run application console (pry)' task :console do sh 'pry -r ./spec/test_load_all' end -namespace :run do - namespace :api do - task :dev => :config do +namespace :api do + namespace :run do + desc 'Rerun the API server in development mode' + task :development => :config do puts 'REMEMBER: need to run `rake run:dev:worker` in another process' - sh "rerun -c 'rackup -p 3030' --ignore 'coverage/*' --ignore '#{@config.REPOSTORE_PATH}/*'" + sh "rerun -c 'rackup -p 3030' --ignore '#{@config.REPOSTORE_PATH}/*'" end + desc 'Rerun the API server in test mode' task :test => :config do puts 'REMEMBER: need to run `rake run:test:worker` in another process' sh "rerun -c 'RACK_ENV=test rackup -p 3000' --ignore 'coverage/*' --ignore '#{@config.REPOSTORE_PATH}/*'" end end +end - namespace :worker do - task :dev => :config do - sh 'bundle exec shoryuken -r ./workers/clone_repo_worker.rb -C ./workers/shoryuken.yml' +namespace :worker do + namespace :run do + desc 'Run the background cloning worker in development mode' + task :development => :config do + sh 'RACK_ENV=development bundle exec shoryuken -r ./workers/clone_repo_worker.rb -C ./workers/shoryuken_dev.yml' end + desc 'Run the background cloning worker in testing mode' task :test => :config do sh 'RACK_ENV=test bundle exec shoryuken -r ./workers/clone_repo_worker.rb -C ./workers/shoryuken_test.yml' end - end -end -namespace :ls do - desc 'list cloned repos in repo store' - task :repostore => :config do - puts `ls #{@config.REPOSTORE_PATH}` + desc 'Run the background cloning worker in production mode' + task :production => :config do + sh 'RACK_ENV=production bundle exec shoryuken -r ./workers/clone_repo_worker.rb -C ./workers/shoryuken.yml' + end end end -namespace :rm do - desc 'delete cassette fixtures' - task :vcr do +namespace :vcr do + desc 'Delete cassette fixtures' + task :delete do sh 'rm spec/fixtures/cassettes/*.yml' do |ok, _| puts(ok ? 'Cassettes deleted' : 'No cassettes found') end end +end - desc 'delete cloned repos in repo store' - task :repostore => :config do +namespace :repostore do + desc 'List cloned repos in repo store' + task :create => :config do + puts `mkdir #{@config.REPOSTORE_PATH}` + end + + desc 'Delete cloned repos in repo store' + task :delete => :config do sh "rm -rf #{@config.REPOSTORE_PATH}/*" do |ok, _| puts(ok ? 'Cloned repos deleted' : "Could not delete cloned repos") end end + + desc 'List cloned repos in repo store' + task :list => :config do + puts `ls #{@config.REPOSTORE_PATH}` + end end namespace :quality do CODE = '**/*.rb' - desc 'run all quality checks' + desc 'Run all quality checks' task all: %i[rubocop reek flog] + desc 'Run Rubocop quality checks' task :rubocop do sh "rubocop #{CODE}" end + desc 'Run Reek quality checks' task :reek do sh "reek #{CODE}" end + desc 'Run Flog quality checks' task :flog do sh "flog #{CODE}" end end -namespace :db do - require_relative 'config/environment.rb' # load config info - require 'sequel' # TODO: remove after create orm - - Sequel.extension :migration - app = CodePraise::Api - - desc 'Run migrations' - task :migrate do - puts "Migrating #{app.environment} database to latest" - Sequel::Migrator.run(app.DB, 'infrastructure/database/migrations') - end - - desc 'Drop all tables' - task :drop do - require_relative 'config/environment.rb' - # drop according to dependencies - app.DB.drop_table :repos_contributors - app.DB.drop_table :repos - app.DB.drop_table :collaborators - app.DB.drop_table :schema_info - end - - desc 'Reset all database tables' - task reset: [:drop, :migrate] - - desc 'Delete dev or test database file' - task :wipe do - if app.environment == :production - puts 'Cannot wipe production database!' - return - end - - FileUtils.rm(app.config.DB_FILENAME) - puts "Deleted #{app.config.DB_FILENAME}" - end -end - namespace :queue do require 'aws-sdk-sqs' @@ -161,6 +143,7 @@ namespace :queue do end end + desc "Purge messages in SQS queue for Shoryuken" task :purge => :config do sqs = Aws::SQS::Client.new(region: @config.AWS_REGION) @@ -172,3 +155,41 @@ namespace :queue do end end end + +namespace :db do + require_relative 'config/environment.rb' # load config info + require 'sequel' # TODO: remove after create orm + + Sequel.extension :migration + app = CodePraise::Api + + desc 'Run migrations' + task :migrate do + puts "Migrating #{app.environment} database to latest" + Sequel::Migrator.run(app.DB, 'infrastructure/database/migrations') + end + + desc 'Drop all tables' + task :drop do + require_relative 'config/environment.rb' + # drop according to dependencies + app.DB.drop_table :repos_contributors + app.DB.drop_table :repos + app.DB.drop_table :collaborators + app.DB.drop_table :schema_info + end + + desc 'Reset all database tables' + task reset: [:drop, :migrate] + + desc 'Delete dev or test database file' + task :wipe do + if app.environment == :production + puts 'Cannot wipe production database!' + return + end + + FileUtils.rm(app.config.DB_FILENAME) + puts "Deleted #{app.config.DB_FILENAME}" + end +end diff --git a/config/secrets.yml.example b/config/secrets.yml.example index 6838924..463a2cc 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -1,6 +1,16 @@ --- development: GH_TOKEN: + AWS_ACCESS_KEY_ID: + AWS_SECRET_ACCESS_KEY: + AWS_REGION: + CLONE_QUEUE: + CLONE_QUEUE_URL: test: - GH_TOKEN: \ No newline at end of file + GH_TOKEN: + AWS_ACCESS_KEY_ID: + AWS_SECRET_ACCESS_KEY: + AWS_REGION: + CLONE_QUEUE: + CLONE_QUEUE_URL: diff --git a/config/setup_codeship b/config/setup_codeship new file mode 100755 index 0000000..63d4530 --- /dev/null +++ b/config/setup_codeship @@ -0,0 +1,4 @@ +rvm use 2.4.2 --install +bundle install --without production +RACK_ENV=test bundle exec rake db:migrate +bundle exec rake run:worker:test & \ No newline at end of file diff --git a/infrastructure/gitrepo/repostore/.gitignore b/infrastructure/gitrepo/repostore/.gitignore new file mode 100644 index 0000000..80f5bd0 --- /dev/null +++ b/infrastructure/gitrepo/repostore/.gitignore @@ -0,0 +1,5 @@ +# This file puts the repostore folder into git version control: +# https://steindom.com/articles/add-empty-directory-git-repository + +* +!.gitignore \ No newline at end of file diff --git a/spec/api_spec.rb b/spec/api_spec.rb index 6b71e7f..152a489 100644 --- a/spec/api_spec.rb +++ b/spec/api_spec.rb @@ -18,12 +18,13 @@ describe 'Cloning repos' do before do - CodePraise::Repository::RepoStore.delete_all! CodePraise::LoadFromGithub.new.call( config: app.config, ownername: USERNAME, reponame: REPO_NAME ) + + CodePraise::Repository::RepoStore.delete_all! end after do @@ -34,7 +35,6 @@ get "#{API_VER}/summary/#{USERNAME}/#{REPO_NAME}" _(last_response.status).must_equal 202 - STDOUT.sync 5.times { sleep(1); print '.' } get "#{API_VER}/summary/#{USERNAME}/#{REPO_NAME}" @@ -100,6 +100,8 @@ ownername: USERNAME, reponame: REPO_NAME ) + + CodePraise::Repository::Repos.clone_all! end it '(HAPPY) should get blame summary for root of loaded repo' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4985904..26b152f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,6 +31,9 @@ c.filter_sensitive_data('') { CGI.escape(github_token) } end +# To flush dots and output during testing +STDOUT.sync + # DB = app.DB # require 'database_cleaner' # DatabaseCleaner.strategy = :truncation \ No newline at end of file diff --git a/workers/shoryuken_dev.yml b/workers/shoryuken_dev.yml new file mode 100644 index 0000000..7c57cfe --- /dev/null +++ b/workers/shoryuken_dev.yml @@ -0,0 +1,2 @@ +queues: + - https://sqs.us-east-1.amazonaws.com/503315808870/codepraise-clone_dev.fifo