diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..a25353e --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,79 @@ +--- +version: 2.1 +orbs: + samvera: samvera/circleci-orb@1.0 +jobs: + bundle_lint_test: + parameters: + ruby_version: + type: string + bundler_version: + type: string + default: 2.3.14 + executor: + name: 'samvera/ruby' + ruby_version: << parameters.ruby_version >> + environment: + NOKOGIRI_USE_SYSTEM_LIBRARIES: true + steps: + - samvera/cached_checkout + - run: + name: Check for a branch named 'master' + command: | + git fetch --all --quiet --prune --prune-tags + if [[ -n "$(git branch --all --list master */master)" ]]; then + echo "A branch named 'master' was found. Please remove it." + echo "$(git branch --all --list master */master)" + fi + [[ -z "$(git branch --all --list master */master)" ]] + - samvera/bundle: + ruby_version: << parameters.ruby_version >> + bundler_version: << parameters.bundler_version >> + - samvera/rubocop + - run: + name: 'Lint the source code files using RuboCop' + command: 'bundle exec rubocop --config=./.rubocop.yml --parallel' + #- samvera/parallel_rspec + - run: + name: 'Executing the test suites using RSpec' + command: | + mkdir /tmp/test-results + bundle exec rspec spec/ + - store_test_results: + path: /tmp/test-results + - store_artifacts: + path: /tmp/test-results + destination: test-results + +workflows: + version: 2 + ci: + jobs: + - bundle_lint_test: + name: bundle_ruby3-1 + ruby_version: 3.1.2 + - bundle_lint_test: + name: bundle_ruby3-0 + ruby_version: 3.0.4 + - bundle_lint_test: + name: bundle_ruby2-7 + ruby_version: 2.7.6 + + nightly: + triggers: + - schedule: + cron: "0 0 * * *" + filters: + branches: + only: + - main + jobs: + - bundle_lint_test: + name: bundle_ruby3-1 + ruby_version: 3.1.2 + - bundle_lint_test: + name: bundle_ruby3-0 + ruby_version: 3.0.4 + - bundle_lint_test: + name: bundle_ruby2-7 + ruby_version: 2.7.6 diff --git a/.rubocop.yml b/.rubocop.yml index f34d81c..918c2ad 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,11 @@ +inherit_gem: + bixby: bixby_default.yml + AllCops: Exclude: + - 'Rakefile' - 'script/**/*' + - 'vendor/**/*' Layout/LineLength: Exclude: diff --git a/Gemfile b/Gemfile index 49bf200..a6923c7 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ group :development do gem 'bixby' gem 'pry-byebug' gem 'rspec' + gem 'rspec_junit_formatter' gem 'simplecov' gem 'webmock' gem 'yard' diff --git a/lib/samvera/gem_query_service.rb b/lib/samvera/gem_query_service.rb index 19774b6..addde6e 100644 --- a/lib/samvera/gem_query_service.rb +++ b/lib/samvera/gem_query_service.rb @@ -236,6 +236,7 @@ def remove(owners:) add_command = RemoveOwnersCommand.new add_command.options[:args] = [@gem_name] owner_logins = owners.map(&:login) + add_command.options[:add] = [] add_command.options[:remove] = owner_logins add_command.execute diff --git a/lib/samvera/git_hub.rb b/lib/samvera/git_hub.rb index d37c22d..aca4000 100644 --- a/lib/samvera/git_hub.rb +++ b/lib/samvera/git_hub.rb @@ -6,7 +6,7 @@ module Samvera class GitHub class << self def authorization_token - @authorization_token = ENV['GITHUB_SAMVERA_TOKEN'] || raise( + @authorization_token = ENV.fetch('GITHUB_SAMVERA_TOKEN', nil) || raise( ArgumentError, 'GitHub authorization token was not found in the GITHUB_SAMVERA_TOKEN environment variable' ) @@ -49,7 +49,7 @@ def samvera_team end def admin_team - @admin_team = samvera_team.select { |team| team.name == 'admins' }.first + @admin_team = samvera_team.find { |team| team.name == 'admins' } end def admin_response @@ -70,7 +70,7 @@ def samvera_admins end def contrib_team - @contrib_team = samvera_team.select { |team| team.name == 'contributors' }.first + @contrib_team = samvera_team.find { |team| team.name == 'contributors' } end def contrib_response diff --git a/lib/samvera/org.rb b/lib/samvera/org.rb index af34c4a..2b82d14 100644 --- a/lib/samvera/org.rb +++ b/lib/samvera/org.rb @@ -28,9 +28,7 @@ def repositories desc('add_owners', 'Ensure that all members of the administrator GitHub Team are Gem Owners for RubyGems entries') def add_owners GitHub.repositories.each do |repo| - if !RubyGems.gem_exists?(name: repo.name) - say("Could not find the Gem for #{repo.name}...", :red) - else + if RubyGems.gem_exists?(name: repo.name) current_owners = RubyGems.show_gem_owners(name: repo.name) owners = GitHub.samvera_admins.reject { |o| current_owners.map(&:login).include?(o.login) } @@ -40,6 +38,8 @@ def add_owners rescue StandardError => e raise(Thor::Error, e.message) end + else + say("Could not find the Gem for #{repo.name}...", :red) end end end @@ -48,9 +48,7 @@ def add_owners 'Ensure that all Gem Owners for RubyGems entries which are *not* members of the administrator GitHub Team are removed') def remove_owners GitHub.repositories.each do |repo| - if !RubyGems.gem_exists?(name: repo.name) - say("Could not find the Gem for #{repo.name}...", :red) - else + if RubyGems.gem_exists?(name: repo.name) current_owners = RubyGems.show_gem_owners(name: repo.name) owners = GitHub.samvera_admins.reject { |o| current_owners.map(&:login).include?(o.login) } @@ -60,6 +58,8 @@ def remove_owners rescue StandardError => e raise(Thor::Error, e.message) end + else + say("Could not find the Gem for #{repo.name}...", :red) end end end diff --git a/spec/system/cli_spec.rb b/spec/system/cli_spec.rb index 6e73b17..fc54fa6 100644 --- a/spec/system/cli_spec.rb +++ b/spec/system/cli_spec.rb @@ -133,9 +133,12 @@ ].to_yaml end - before do + before(:all) do + ENV["GEM_HOST_API_KEY"] = 'secret' ENV['GITHUB_SAMVERA_TOKEN'] = 'secret' + end + before do allow(::Github).to receive(:new).and_return(github_client) allow(github_client).to receive(:orgs).and_return(github_orgs) allow(github_client).to receive(:repos).with(user: 'samvera').and_return(github_samvera_repos) @@ -205,7 +208,8 @@ cli end - after do + after(:all) do + ENV["GEM_HOST_API_KEY"] = nil ENV['GITHUB_SAMVERA_TOKEN'] = nil end