Skip to content

Commit

Permalink
chore: fix rubucop lint
Browse files Browse the repository at this point in the history
  • Loading branch information
icyleaf committed Apr 19, 2024
1 parent cc3a299 commit feeaa9e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 19 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ Lint/AssignmentInCondition:

Lint/SuppressedException:
Enabled: false

Style/HashSyntax:
Enabled: false

Style/NumericLiterals:
Enabled: false

Style/OptionalBooleanParameter:
Enabled: false
7 changes: 3 additions & 4 deletions lib/hpr/client.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: tru
# frozen_string_literal: true

require 'gitlab'
require 'fileutils'
Expand Down Expand Up @@ -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!
Expand All @@ -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
Expand Down Expand Up @@ -132,6 +132,5 @@ def gitlab
private_token: Hpr::Configuration.gitlab.private_token
)
end

end
end
6 changes: 3 additions & 3 deletions lib/hpr/ext/git_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/hpr/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/hpr/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions lib/hpr/web.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: tru
# frozen_string_literal: true

require 'sinatra'
require 'sinatra/json'
Expand All @@ -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?
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions lib/hpr/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions lib/hpr/workers/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit feeaa9e

Please sign in to comment.