Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2927425f
Commit
2927425f
authored
Dec 02, 2021
by
Zhu Shung
Committed by
Lin Jen-Shin
Dec 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor is_ee/is_jh and add tests
parent
f4a90915
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
182 additions
and
8 deletions
+182
-8
rubocop/code_reuse_helpers.rb
rubocop/code_reuse_helpers.rb
+8
-0
rubocop/cop/gitlab/mark_used_feature_flags.rb
rubocop/cop/gitlab/mark_used_feature_flags.rb
+2
-4
scripts/lib/gitlab.rb
scripts/lib/gitlab.rb
+13
-0
scripts/used-feature-flags
scripts/used-feature-flags
+3
-4
spec/rubocop/code_reuse_helpers_spec.rb
spec/rubocop/code_reuse_helpers_spec.rb
+75
-0
spec/scripts/lib/gitlab_spec.rb
spec/scripts/lib/gitlab_spec.rb
+81
-0
No files found.
rubocop/code_reuse_helpers.rb
View file @
2927425f
...
...
@@ -180,5 +180,13 @@ module RuboCop
def
rails_root
File
.
expand_path
(
'..'
,
__dir__
)
end
def
ee?
File
.
exist?
(
File
.
expand_path
(
'../ee/app/models/license.rb'
,
__dir__
))
&&
!
%w[true 1]
.
include?
(
ENV
[
'FOSS_ONLY'
].
to_s
)
end
def
jh?
ee?
&&
Dir
.
exist?
(
File
.
expand_path
(
'../jh'
,
__dir__
))
&&
!
%w[true 1]
.
include?
(
ENV
[
'EE_ONLY'
].
to_s
)
end
end
end
rubocop/cop/gitlab/mark_used_feature_flags.rb
View file @
2927425f
...
...
@@ -255,14 +255,12 @@ module RuboCop
]
# For EE additionally process `ee/` feature flags
is_ee
=
File
.
exist?
(
File
.
expand_path
(
'../../../ee/app/models/license.rb'
,
__dir__
))
&&
!
%w[true 1]
.
include?
(
ENV
[
'FOSS_ONLY'
].
to_s
)
if
is_ee
if
ee?
flags_paths
<<
'ee/config/feature_flags/**/*.yml'
end
# For JH additionally process `jh/` feature flags
is_jh
=
is_ee
&&
Dir
.
exist?
(
File
.
expand_path
(
'../../../jh'
,
__dir__
))
&&
!
%w[true 1]
.
include?
(
ENV
[
'EE_ONLY'
].
to_s
)
if
is_jh
if
jh?
flags_paths
<<
'jh/config/feature_flags/**/*.yml'
end
...
...
scripts/lib/gitlab.rb
0 → 100644
View file @
2927425f
# frozen_string_literal: true
module
Gitlab
module_function
def
ee?
File
.
exist?
(
File
.
expand_path
(
'../../ee/app/models/license.rb'
,
__dir__
))
&&
!
%w[true 1]
.
include?
(
ENV
[
'FOSS_ONLY'
].
to_s
)
end
def
jh?
ee?
&&
Dir
.
exist?
(
File
.
expand_path
(
'../../jh'
,
__dir__
))
&&
!
%w[true 1]
.
include?
(
ENV
[
'EE_ONLY'
].
to_s
)
end
end
scripts/used-feature-flags
View file @
2927425f
...
...
@@ -3,6 +3,7 @@
require
'set'
require
'fileutils'
require_relative
'lib/gitlab'
class
String
def
red
...
...
@@ -27,8 +28,7 @@ flags_paths = [
]
# For EE additionally process `ee/` feature flags
is_ee
=
File
.
exist?
(
'ee/app/models/license.rb'
)
&&
!
%w[true 1]
.
include?
(
ENV
[
'FOSS_ONLY'
].
to_s
)
if
is_ee
if
Gitlab
.
ee?
flags_paths
<<
'ee/config/feature_flags/**/*.yml'
# Geo feature flags are constructed dynamically and there's no explicit checks in the codebase so we mark all
...
...
@@ -43,8 +43,7 @@ if is_ee
end
# For JH additionally process `jh/` feature flags
is_jh
=
is_ee
&&
Dir
.
exist?
(
'jh'
)
&&
!
%w[true 1]
.
include?
(
ENV
[
'EE_ONLY'
].
to_s
)
if
is_jh
if
Gitlab
.
jh?
flags_paths
<<
'jh/config/feature_flags/**/*.yml'
Dir
.
glob
(
'jh/app/replicators/geo/*_replicator.rb'
).
each_with_object
(
Set
.
new
)
do
|
path
,
memo
|
...
...
spec/rubocop/code_reuse_helpers_spec.rb
View file @
2927425f
...
...
@@ -21,6 +21,8 @@ RSpec.describe RuboCop::CodeReuseHelpers do
end
.
new
end
let
(
:ee_file_path
)
{
File
.
expand_path
(
'../../ee/app/models/license.rb'
,
__dir__
)
}
describe
'#send_to_constant?'
do
it
'returns true when sending to a constant'
do
node
=
build_and_parse_source
(
'Foo.bar'
)
...
...
@@ -312,4 +314,77 @@ RSpec.describe RuboCop::CodeReuseHelpers do
cop
.
disallow_send_to
(
def_node
,
'Finder'
,
'oops'
)
end
end
describe
'#ee?'
do
before
do
stub_env
(
'FOSS_ONLY'
,
nil
)
allow
(
File
).
to
receive
(
:exist?
).
with
(
ee_file_path
)
{
true
}
end
it
'returns true when ee/app/models/license.rb exists'
do
expect
(
cop
.
ee?
).
to
eq
(
true
)
end
end
describe
'#jh?'
do
context
'when jh directory exists and EE_ONLY is not set'
do
before
do
stub_env
(
'EE_ONLY'
,
nil
)
allow
(
Dir
).
to
receive
(
:exist?
).
with
(
File
.
expand_path
(
'../../jh'
,
__dir__
))
{
true
}
end
context
'when ee/app/models/license.rb exists'
do
before
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
ee_file_path
)
{
true
}
end
context
'when FOSS_ONLY is not set'
do
before
do
stub_env
(
'FOSS_ONLY'
,
nil
)
end
it
'returns true'
do
expect
(
cop
.
jh?
).
to
eq
(
true
)
end
end
context
'when FOSS_ONLY is set to 1'
do
before
do
stub_env
(
'FOSS_ONLY'
,
'1'
)
end
it
'returns false'
do
expect
(
cop
.
jh?
).
to
eq
(
false
)
end
end
end
context
'when ee/app/models/license.rb not exist'
do
before
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
ee_file_path
)
{
false
}
end
context
'when FOSS_ONLY is not set'
do
before
do
stub_env
(
'FOSS_ONLY'
,
nil
)
end
it
'returns true'
do
expect
(
cop
.
jh?
).
to
eq
(
false
)
end
end
context
'when FOSS_ONLY is set to 1'
do
before
do
stub_env
(
'FOSS_ONLY'
,
'1'
)
end
it
'returns false'
do
expect
(
cop
.
jh?
).
to
eq
(
false
)
end
end
end
end
end
end
spec/scripts/lib/gitlab_spec.rb
0 → 100644
View file @
2927425f
# frozen_string_literal: true
require
'fast_spec_helper'
require_relative
'../../../scripts/lib/gitlab'
RSpec
.
describe
'scripts/lib/gitlab.rb'
do
let
(
:ee_file_path
)
{
File
.
expand_path
(
'../../../ee/app/models/license.rb'
,
__dir__
)
}
describe
'.ee?'
do
before
do
stub_env
(
'FOSS_ONLY'
,
nil
)
allow
(
File
).
to
receive
(
:exist?
).
with
(
ee_file_path
)
{
true
}
end
it
'returns true when ee/app/models/license.rb exists'
do
expect
(
Gitlab
.
ee?
).
to
eq
(
true
)
end
end
describe
'.jh?'
do
context
'when jh directory exists and EE_ONLY is not set'
do
before
do
stub_env
(
'EE_ONLY'
,
nil
)
allow
(
Dir
).
to
receive
(
:exist?
).
with
(
File
.
expand_path
(
'../../../jh'
,
__dir__
))
{
true
}
end
context
'when ee/app/models/license.rb exists'
do
before
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
ee_file_path
)
{
true
}
end
context
'when FOSS_ONLY is not set'
do
before
do
stub_env
(
'FOSS_ONLY'
,
nil
)
end
it
'returns true'
do
expect
(
Gitlab
.
jh?
).
to
eq
(
true
)
end
end
context
'when FOSS_ONLY is set to 1'
do
before
do
stub_env
(
'FOSS_ONLY'
,
'1'
)
end
it
'returns false'
do
expect
(
Gitlab
.
jh?
).
to
eq
(
false
)
end
end
end
context
'when ee/app/models/license.rb not exist'
do
before
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
ee_file_path
)
{
false
}
end
context
'when FOSS_ONLY is not set'
do
before
do
stub_env
(
'FOSS_ONLY'
,
nil
)
end
it
'returns true'
do
expect
(
Gitlab
.
jh?
).
to
eq
(
false
)
end
end
context
'when FOSS_ONLY is set to 1'
do
before
do
stub_env
(
'FOSS_ONLY'
,
'1'
)
end
it
'returns false'
do
expect
(
Gitlab
.
jh?
).
to
eq
(
false
)
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment