Skip to content

Commit 9e2f446

Browse files
Working on ruby 3 support
1 parent 6d85dbc commit 9e2f446

File tree

17 files changed

+66
-164
lines changed

17 files changed

+66
-164
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ settings.yml
88
custom_hooks.rb
99
/ssh_keys/redmine_gitolite_admin_id_rsa*
1010
.DS_Store
11+
.vscode/
1112
coverage/
1213
.enable_dev

Diff for: .rubocop.yml

-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ Style/OptionHash:
9393
- params
9494
- parameters
9595
- settings
96-
Exclude:
97-
- lib/redmine_git_hosting/patches/*.rb
9896

9997
Style/ReturnNil:
10098
Enabled: true

Diff for: .rubocop_todo.yml

+9-91
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2021-04-25 08:33:10 UTC using RuboCop version 1.13.0.
3+
# on 2021-08-03 12:28:02 UTC using RuboCop version 1.18.4.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 1
10-
# Configuration parameters: AllowComments, AllowEmptyLambdas.
11-
Lint/EmptyBlock:
12-
Exclude:
13-
- 'spec/factories/member.rb'
14-
159
# Offense count: 1
1610
# Cop supports --auto-correct.
1711
Lint/Loop:
@@ -61,7 +55,7 @@ Naming/MemoizedInstanceVariableName:
6155
- 'lib/redmine_git_hosting/gitolite_handlers/repositories/move_repository.rb'
6256
- 'lib/redmine_git_hosting/redmine_plugin_loader.rb'
6357

64-
# Offense count: 3
58+
# Offense count: 2
6559
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
6660
# NamePrefix: is_, has_, have_
6761
# ForbiddenPrefixes: is_, has_, have_
@@ -70,7 +64,6 @@ Naming/MemoizedInstanceVariableName:
7064
Naming/PredicateName:
7165
Exclude:
7266
- 'app/models/concerns/gitolitable/validations.rb'
73-
- 'app/models/gitolite_public_key.rb'
7467
- 'lib/redmine_git_hosting/patches/grack_auth_patch.rb'
7568

7669
# Offense count: 26
@@ -90,48 +83,12 @@ Performance/ChainArrayAllocation:
9083
- 'lib/redmine_git_hosting/patches/user_patch.rb'
9184
- 'lib/redmine_git_hosting/recycle_bin/item_base.rb'
9285

93-
# Offense count: 3
94-
# Cop supports --auto-correct.
95-
Performance/Detect:
96-
Exclude:
97-
- 'lib/redmine_git_hosting/gitolite_handlers/ssh_keys/base.rb'
98-
- 'lib/redmine_git_hosting/plugins/gitolite_plugin.rb'
99-
10086
# Offense count: 1
10187
# Cop supports --auto-correct.
10288
Performance/RangeInclude:
10389
Exclude:
10490
- 'app/helpers/repository_mirrors_helper.rb'
10591

106-
# Offense count: 1
107-
# Cop supports --auto-correct.
108-
# Configuration parameters: AutoCorrect.
109-
Performance/StringInclude:
110-
Exclude:
111-
- 'app/use_cases/repositories/build_payload.rb'
112-
113-
# Offense count: 1
114-
# Configuration parameters: EnforcedStyle.
115-
# SupportedStyles: strict, flexible
116-
Rails/Date:
117-
Exclude:
118-
- 'app/reports/report_helper.rb'
119-
120-
# Offense count: 12
121-
# Cop supports --auto-correct.
122-
# Configuration parameters: Whitelist, AllowedMethods, AllowedReceivers.
123-
# Whitelist: find_by_sql
124-
# AllowedMethods: find_by_sql
125-
# AllowedReceivers: Gem::Specification
126-
Rails/DynamicFindBy:
127-
Exclude:
128-
- 'app/controllers/concerns/xitolite_repository_finder.rb'
129-
- 'app/models/concerns/gitolitable/cache.rb'
130-
- 'lib/redmine_git_hosting/patches/grack_auth_patch.rb'
131-
- 'lib/redmine_git_hosting/patches/grack_git_patch.rb'
132-
- 'spec/support/flat_organization.rb'
133-
- 'spec/support/hierarchical_organisation.rb'
134-
13592
# Offense count: 9
13693
# Configuration parameters: Include.
13794
# Include: app/models/**/*.rb
@@ -140,12 +97,11 @@ Rails/InverseOf:
14097
- 'app/models/repository/xitolite.rb'
14198
- 'app/models/repository_protected_branche.rb'
14299

143-
# Offense count: 3
100+
# Offense count: 2
144101
# Configuration parameters: Include.
145102
# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb
146103
Rails/Output:
147104
Exclude:
148-
- 'app/use_cases/repository_protected_branches/member_manager.rb'
149105
- 'lib/redmine_git_hosting/config/base.rb'
150106
- 'lib/redmine_git_hosting/console_logger.rb'
151107

@@ -155,14 +111,13 @@ Rails/OutputSafety:
155111
- 'app/helpers/gitolite_plugin_settings_helper.rb'
156112
- 'app/presenters/repository_presenter.rb'
157113

158-
# Offense count: 6
114+
# Offense count: 4
159115
# Cop supports --auto-correct.
160116
# Configuration parameters: EnforcedStyle.
161117
# SupportedStyles: strict, flexible
162118
Rails/TimeZone:
163119
Exclude:
164120
- 'lib/redmine/scm/adapters/xitolite_adapter.rb'
165-
- 'lib/redmine_git_hosting/cache/abstract_cache.rb'
166121
- 'lib/redmine_git_hosting/plugins/extenders/readme_creator.rb'
167122

168123
# Offense count: 2
@@ -173,14 +128,7 @@ Rails/UniqueValidationWithoutIndex:
173128
- 'app/models/gitolite_public_key.rb'
174129
- 'app/models/repository_protected_branche.rb'
175130

176-
# Offense count: 9
177-
# Configuration parameters: AllowedChars.
178-
# AllowedChars: ©
179-
Style/AsciiComments:
180-
Exclude:
181-
- 'app/models/gitolite_public_key.rb'
182-
183-
# Offense count: 4
131+
# Offense count: 3
184132
# Cop supports --auto-correct.
185133
Style/CaseLikeIf:
186134
Exclude:
@@ -216,26 +164,13 @@ Style/DocumentDynamicEvalDefinition:
216164
Exclude:
217165
- 'lib/redmine_git_hosting/shell_redirector.rb'
218166

219-
# Offense count: 3
220-
# Cop supports --auto-correct.
221-
# Configuration parameters: EnforcedStyle.
222-
# SupportedStyles: always, always_true, never
223-
Style/FrozenStringLiteralComment:
224-
Exclude:
225-
- 'app/controllers/concerns/xitolite_repository_finder.rb'
226-
- 'app/use_cases/projects/base.rb'
227-
- 'contrib/scripts/puma.rb'
228-
229-
# Offense count: 11
167+
# Offense count: 8
230168
# Configuration parameters: MinBodyLength.
231169
Style/GuardClause:
232170
Exclude:
233171
- 'app/models/concerns/gitolitable/validations.rb'
234172
- 'app/services/redmine_hooks/github_issues_sync.rb'
235-
- 'lib/redmine/scm/adapters/xitolite_adapter.rb'
236-
- 'lib/redmine_git_hosting/git_access.rb'
237173
- 'lib/redmine_git_hosting/gitolite_handlers/repositories/move_repository.rb'
238-
- 'lib/redmine_git_hosting/gitolite_wrappers/base.rb'
239174
- 'lib/redmine_git_hosting/patches/grack_auth_patch.rb'
240175
- 'lib/redmine_git_hosting/patches/projects_controller_patch.rb'
241176
- 'lib/redmine_git_hosting/patches/setting_patch.rb'
@@ -261,23 +196,14 @@ Style/MissingRespondToMissing:
261196
Style/ModuleFunction:
262197
Enabled: false
263198

264-
# Offense count: 5
199+
# Offense count: 2
265200
# Cop supports --auto-correct.
266201
# Configuration parameters: EnforcedStyle.
267202
# SupportedStyles: literals, strict
268203
Style/MutableConstant:
269204
Exclude:
270205
- 'app/models/repository_git_config_key/git_config.rb'
271-
- 'lib/hrack/lib/hrack/server.rb'
272206
- 'lib/redmine_git_hosting/patches/repositories_controller_patch.rb'
273-
- 'lib/redmine_git_hosting/utils/git.rb'
274-
- 'lib/redmine_git_hosting/validators.rb'
275-
276-
# Offense count: 35
277-
# Configuration parameters: SuspiciousParamNames.
278-
# SuspiciousParamNames: options, opts, args, params, parameters
279-
Style/OptionHash:
280-
Enabled: false
281207

282208
# Offense count: 1
283209
# Configuration parameters: AllowedMethods.
@@ -294,20 +220,12 @@ Style/SpecialGlobalVars:
294220
Exclude:
295221
- 'lib/redmine_git_hosting/shell_redirector.rb'
296222

297-
# Offense count: 6
223+
# Offense count: 5
298224
# Cop supports --auto-correct.
225+
# Configuration parameters: Mode.
299226
Style/StringConcatenation:
300227
Exclude:
301228
- 'app/helpers/repository_deployment_credentials_helper.rb'
302-
- 'app/models/gitolite_public_key.rb'
303229
- 'app/use_cases/repository_mirrors/push.rb'
304230
- 'lib/redmine_git_hosting/commands/sudo.rb'
305231
- 'lib/redmine_git_hosting/mirror_keys_installer.rb'
306-
307-
# Offense count: 1
308-
# Cop supports --auto-correct.
309-
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, AllowedMethods.
310-
# AllowedMethods: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym
311-
Style/TrivialAccessors:
312-
Exclude:
313-
- 'lib/redmine_git_hosting/gitolite_hooks.rb'

Diff for: app/controllers/repository_git_config_keys_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def update
3333

3434
flash[:notice] = l :notice_git_config_key_updated
3535
options = @git_config_key.key_has_changed? ? { delete_git_config_key: @git_config_key.old_key } : {}
36-
call_use_case_and_redirect options
36+
call_use_case_and_redirect(**options)
3737
end
3838

3939
def destroy
4040
return unless @git_config_key.destroy
4141

4242
flash[:notice] = l :notice_git_config_key_deleted
4343
options = { delete_git_config_key: @git_config_key.key }
44-
call_use_case_and_redirect options
44+
call_use_case_and_redirect(**options)
4545
end
4646

4747
private

Diff for: app/models/gitolite_public_key.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class GitolitePublicKey < ActiveRecord::Base
2626
validates :key_type, presence: true, numericality: { only_integer: true },
2727
inclusion: { in: [KEY_TYPE_USER, KEY_TYPE_DEPLOY] }
2828

29-
validate :has_not_been_changed
29+
validate :not_been_changed?
3030
validate :key_correctness
3131
validate :key_not_admin
3232
validate :key_uniqueness
@@ -64,15 +64,15 @@ def data_for_destruction
6464
#
6565
#
6666
# keydir/
67-
# ├── redmine_git_hosting
68-
# │   └── redmine_admin_1
69-
# │   ├── redmine_test_key
70-
# │   │   └── redmine_admin_1.pub
71-
# │   ├── redmine_deploy_key_1
72-
# │   │   └── redmine_admin_1.pub
73-
# │   └── redmine_deploy_key_2
74-
# │   └── redmine_admin_1.pub
75-
# └── redmine_gitolite_admin_id_rsa.pub
67+
# redmine_git_hosting
68+
# redmine_admin_1
69+
# redmine_test_key
70+
# redmine_admin_1.pub
71+
# redmine_deploy_key_1
72+
# redmine_admin_1.pub
73+
# redmine_deploy_key_2
74+
# redmine_admin_1.pub
75+
# redmine_gitolite_admin_id_rsa.pub
7676
#
7777
#
7878
# The root folder for this user is the user's identifier
@@ -174,7 +174,7 @@ def set_fingerprint
174174
errors.add :key, :corrupted
175175
end
176176

177-
def has_not_been_changed
177+
def not_been_changed?
178178
return if new_record?
179179

180180
%w[identifier key user_id key_type title fingerprint].each do |attribute|

Diff for: lib/redmine_git_hosting/cache/abstract_cache.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ def logger
4949
def time_limit
5050
return if max_cache_time.to_i.negative? # No expiration needed
5151

52-
current_time = ActiveRecord::Base.default_timezone == :utc ? Time.now.utc : Time.now
52+
current_time = ActiveRecord::Base.default_timezone == :utc ? Time.now.utc : Time.zone.now
5353
current_time - max_cache_time
5454
end
5555

5656
def valid_cache_entry?(cached_entry_date)
5757
return true if max_cache_time.to_i.negative? # No expiration needed
5858

59-
current_time = ActiveRecord::Base.default_timezone == :utc ? Time.now.utc : Time.now
59+
current_time = ActiveRecord::Base.default_timezone == :utc ? Time.now.utc : Timezone.now
6060
expired = current_time.to_i - cached_entry_date.to_i > max_cache_time
6161
!expired
6262
end

Diff for: lib/redmine_git_hosting/git_access.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ def upload_access_check(actor, repository)
2020
return smart_http_is_disabled! repository unless smart_http_enabled_for_upload? repository
2121

2222
# Then check user permissions
23-
if actor.is_a? User
24-
user_upload_access_check actor, repository
25-
else
26-
raise 'Wrong actor'
27-
end
23+
raise 'Wrong actor' unless actor.is_a? User
24+
25+
user_upload_access_check actor, repository
2826
end
2927

3028
def user_download_access_check(user, repository)

Diff for: lib/redmine_git_hosting/gitolite_accessor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def destroy_repositories(repositories, **opts)
6161
end
6262
end
6363

64-
def update_projects(projects, **opts)
64+
def update_projects(projects, opts)
6565
message = opts.delete(:message) { ' ' }
6666
logger.info message
6767
resync_gitolite :update_projects, projects, **opts

Diff for: lib/redmine_git_hosting/gitolite_handlers/ssh_keys/base.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def logger
2929
end
3030

3131
def find_gitolite_key(owner, location)
32-
admin.ssh_keys[owner].find_all { |k| k.location == location && k.owner == owner }.first
32+
admin.ssh_keys[owner].find { |k| k.location == location && k.owner == owner }
3333
end
3434

3535
def build_gitolite_key(key)

Diff for: lib/redmine_git_hosting/gitolite_wrapper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def resync_gitolite(action, object, **options)
1818
# options = options.symbolize_keys
1919

2020
# Flush cache if needed
21-
flush_cache options
21+
flush_cache(**options)
2222

2323
# Return if the action is only to flush cache on Sidekiq side
2424
if action == :flush_settings_cache

Diff for: lib/redmine_git_hosting/patches/member_patch.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def self.prepended(base)
1717

1818
def update_project
1919
options = { message: "Membership changes on project '#{project}', update!" }
20-
gitolite_accessor.update_projects [project.id], options
20+
gitolite_accessor.update_projects [project.id], **options
2121
end
2222
end
2323
end

Diff for: lib/redmine_git_hosting/plugins/gitolite_plugin.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def all_plugins
1212
end
1313

1414
def sweepers
15-
plugins.select { |p| p.name.demodulize == 'BaseSweeper' }.first.subclasses
15+
plugins.find { |p| p.name.demodulize == 'BaseSweeper' }.subclasses
1616
end
1717

1818
def extenders
19-
plugins.select { |p| p.name.demodulize == 'BaseExtender' }.first.subclasses
19+
plugins.find { |p| p.name.demodulize == 'BaseExtender' }.subclasses
2020
end
2121

2222
def inherited(klass)

Diff for: lib/redmine_git_hosting/utils/git.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Git
66
extend self
77

88
REF_COMPONENT_PART = '[\\.\\-\\w_\\*]+'
9-
REF_COMPONENT_REGEX = %r{\A(refs/)?((#{REF_COMPONENT_PART})/)?(#{REF_COMPONENT_PART}(/#{REF_COMPONENT_PART})*)\z}
9+
REF_COMPONENT_REGEX = %r{\A(refs/)?((#{REF_COMPONENT_PART})/)?(#{REF_COMPONENT_PART}(/#{REF_COMPONENT_PART})*)\z}.freeze
1010

1111
# Parse a reference component. Two possibilities:
1212
#

Diff for: spec/factories/gitolite_public_key.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
sequence(:title) { |n| "test-key#{n}" }
66
key do
77
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDpqFJzsx3wTi3t3X/eOizU6rdtNQoqg5uSjL89F+Ojjm2/sah3ouzx+3E461FDYaoJL58Qs9eRhL+ev0BY7khYXp' \
8-
'h8nIVDzNEjhLqjevX+YhpaW9Ll7V807CwAyvMNm08aup/NrrlI/jO+At348/ivJrfO7ClcPhq4+Id9RZfvbrKaitGOURD7q6Bd7xjUjELUN8wmYxu5zvx/2n/5woVd' \
9-
'BUMXamTPxOY5y6DxTNJ+EYzrCr+bNb7459rWUvBHUQGI2fXDGmFpGiv6ShKRhRtwob1JHI8QC9OtxonrIUesa2dW6RFneUaM7tfRfffC704Uo7yuSswb7YK+p1A9QI' \
10-
't5 nicolas@tchoum'
8+
'h8nIVDzNEjhLqjevX+YhpaW9Ll7V807CwAyvMNm08aup/NrrlI/jO+At348/ivJrfO7ClcPhq4+Id9RZfvbrKaitGOURD7q6Bd7xjUjELUN8wmYxu5zvx/2n/5woVd' \
9+
'BUMXamTPxOY5y6DxTNJ+EYzrCr+bNb7459rWUvBHUQGI2fXDGmFpGiv6ShKRhRtwob1JHI8QC9OtxonrIUesa2dW6RFneUaM7tfRfffC704Uo7yuSswb7YK+p1A9QI' \
10+
't5 nicolas@tchoum'
1111
end
1212
key_type { 0 }
1313
association :user

Diff for: spec/factories/member.rb

-6
This file was deleted.

0 commit comments

Comments
 (0)