diff --git a/.rubocop.yml b/.rubocop.yml index 6e74e06..651139f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -25,3 +25,12 @@ Lint/AssignmentInCondition: Lint/SuppressedException: Enabled: false + +Style/HashSyntax: + Enabled: false + +Style/NumericLiterals: + Enabled: false + +Style/OptionalBooleanParameter: + Enabled: false diff --git a/lib/hpr/client.rb b/lib/hpr/client.rb index b5454ae..a70a598 100644 --- a/lib/hpr/client.rb +++ b/lib/hpr/client.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: tru +# frozen_string_literal: true require 'gitlab' require 'fileutils' @@ -93,7 +93,7 @@ def create_gitlab_repository(name, url) def search_gitlab_repository(name) projects = gitlab.project_search(name).select { |project| project.namespace.id == current_group.id } - return projects[0] unless projects.empty? + projects[0] unless projects.empty? end def determine_repository_path! @@ -104,7 +104,7 @@ def determine_repository_path! def determine_gitlab_configure! raise NotRoleError, 'Please enable create group role.' unless current_user.can_create_group raise NotRoleError, 'Please enable create project role.' unless current_user.can_create_project - raise MissingSSHKeyError, "Please add ssh key for `#{current_user.name}` user." if gitlab.ssh_keys.size.zero? + raise MissingSSHKeyError, "Please add ssh key for `#{current_user.name}` user." if gitlab.ssh_keys.empty? end def current_user @@ -132,6 +132,5 @@ def gitlab private_token: Hpr::Configuration.gitlab.private_token ) end - end end diff --git a/lib/hpr/ext/git_mixin.rb b/lib/hpr/ext/git_mixin.rb index 21bcf08..dda45e2 100644 --- a/lib/hpr/ext/git_mixin.rb +++ b/lib/hpr/ext/git_mixin.rb @@ -17,16 +17,16 @@ def config(name = nil, *values, append: false) class Lib def config_set(name, *values, append: false) - command('config', _config_set_args(name, values.pop, append)) + command('config', _config_set_args(name, values.pop, append: append)) values.each do |value| - command('config', _config_set_args(name, value, true)) + command('config', _config_set_args(name, value, append: true)) end end private - def _config_set_args(name, value, append = false) + def _config_set_args(name, value, append: false) [].tap do |obj| obj << '--add' if append obj << name << value diff --git a/lib/hpr/helper.rb b/lib/hpr/helper.rb index 950ae93..063558c 100644 --- a/lib/hpr/helper.rb +++ b/lib/hpr/helper.rb @@ -54,7 +54,7 @@ def ssh_paths def http_paths uri = URI.parse(@url) path = uri.path - (path.start_with?('/') ? path[1..-1] : path).split('/') + (path.start_with?('/') ? path[1..] : path).split('/') end def ssh_protocol? diff --git a/lib/hpr/repository.rb b/lib/hpr/repository.rb index 77e7f2f..87f5de4 100644 --- a/lib/hpr/repository.rb +++ b/lib/hpr/repository.rb @@ -5,6 +5,6 @@ module Hpr class Repository < ActiveRecord::Base enum status: %i[idle cloning fetching pushing] - validates :name, :url, :mirror_url, :gitlab_project_id, :status, presence: true + validates :name, :url, :mirror_url, :gitlab_project_id, :status, presence: true end end diff --git a/lib/hpr/web.rb b/lib/hpr/web.rb index fe67ee4..8ab48b0 100644 --- a/lib/hpr/web.rb +++ b/lib/hpr/web.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: tru +# frozen_string_literal: true require 'sinatra' require 'sinatra/json' @@ -13,7 +13,7 @@ class Web < Sinatra::Base helpers Sinatra::Streaming configure do - use Rack::CommonLogger, Logger.new(STDOUT) + use Rack::CommonLogger, Logger.new($stdout) use Sentry::Rack::CaptureExceptions if Configuration.basic_auth? @@ -185,7 +185,7 @@ def busy_jobs(name = nil) entry = [] workers.each do |process, thread, msg| job = Sidekiq::JobRecord.new(msg['payload']) - worker_type = job.display_class[5..-1].downcase + worker_type = job.display_class[5..].downcase repository = job.display_args[0] stats = { @@ -221,7 +221,7 @@ def retry_failures_jobs data = set.item obj << { name: data['args'].first, - worker: data['class'][5..-1].downcase, + worker: data['class'][5..].downcase, error_class: data['error_class'], error_message: data['error_message'], failed_at: data['failed_at'], diff --git a/lib/hpr/worker.rb b/lib/hpr/worker.rb index 614a202..19a11b7 100644 --- a/lib/hpr/worker.rb +++ b/lib/hpr/worker.rb @@ -20,7 +20,7 @@ def schedule_update_job(name, repository) def scheduled?(name) scheduled = Sidekiq::ScheduledSet.new rs = scheduled.select { |s| JSON.parse(s.value)['args'].first == name } - return rs unless rs.empty? + rs unless rs.empty? end def ensure_git_repository_not_exist(name) @@ -43,7 +43,7 @@ def ensure_git_repository_exist(name) def git_repository_exist?(name) path = git_repository_path(name) - return path if File.directory? path + path if File.directory? path end def git_repository_path(name) diff --git a/lib/hpr/workers/clone.rb b/lib/hpr/workers/clone.rb index 53cc6ef..ec70c3e 100644 --- a/lib/hpr/workers/clone.rb +++ b/lib/hpr/workers/clone.rb @@ -18,14 +18,15 @@ def perform(name, url, mirror_url, gitlab_project_id) @mirror_url = mirror_url @gitlab_project_id = gitlab_project_id @repository = Repository.find_or_create_by name: name, url: url, mirror_url: mirror_url, - gitlab_project_id: gitlab_project_id, status: :cloning + gitlab_project_id: gitlab_project_id, + status: :cloning clone configure pushing schedule_update_job name, @repository rescue => e - Sentry.capture_exception(e) + Sentry.capture_exception e clean_clone_artifacts raise e end @@ -34,8 +35,8 @@ def perform(name, url, mirror_url, gitlab_project_id) def clone logger.debug "cloning #{@url} ... #{@name}" - @git = ::Git.clone @url, @name, path: repository_path, mirror: true, log: nil, - config: 'core.sshCommand=ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + git_clone_config = 'core.sshCommand=ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + @git = ::Git.clone @url, @name, path: repository_path, mirror: true, log: nil, config: git_clone_config end def configure