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
87996a74
Commit
87996a74
authored
Jan 27, 2022
by
Nikolay Belokolodov
Committed by
Michael Kozono
Jan 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve filenames creation for Snowplow event definitions generator
parent
5057bc17
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
8 deletions
+47
-8
lib/generators/gitlab/snowplow_event_definition_generator.rb
lib/generators/gitlab/snowplow_event_definition_generator.rb
+6
-1
spec/lib/generators/gitlab/snowplow_event_definition_generator_spec.rb
...rators/gitlab/snowplow_event_definition_generator_spec.rb
+41
-7
No files found.
lib/generators/gitlab/snowplow_event_definition_generator.rb
View file @
87996a74
...
...
@@ -65,7 +65,12 @@ module Gitlab
end
def
file_name
"
#{
event_category
}
_
#{
event_action
}
.yml"
.
underscore
.
gsub
(
"/"
,
"__"
)
name
=
remove_special_chars
(
"
#{
Time
.
current
.
to_i
}
_
#{
event_category
}
_
#{
event_action
}
"
)
"
#{
name
[
0
..
95
]
}
.yml"
# max 100 chars, see https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/2030#note_679501200
end
def
remove_special_chars
(
input
)
input
.
gsub
(
"::"
,
"__"
).
gsub
(
/[^A-Za-z0-9_]/
,
''
)
end
end
end
spec/lib/generators/gitlab/snowplow_event_definition_generator_spec.rb
View file @
87996a74
...
...
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec
.
describe
Gitlab
::
SnowplowEventDefinitionGenerator
,
:silence_stdout
do
let
(
:ce_temp_dir
)
{
Dir
.
mktmpdir
}
let
(
:ee_temp_dir
)
{
Dir
.
mktmpdir
}
let
(
:timestamp
)
{
Time
.
current
.
to_i
}
let
(
:generator_options
)
{
{
'category'
=>
'Groups::EmailCampaignsController'
,
'action'
=>
'click'
}
}
before
do
...
...
@@ -12,6 +13,10 @@ RSpec.describe Gitlab::SnowplowEventDefinitionGenerator, :silence_stdout do
stub_const
(
"
#{
described_class
}
::EE_DIR"
,
ee_temp_dir
)
end
around
do
|
example
|
freeze_time
{
example
.
run
}
end
after
do
FileUtils
.
rm_rf
([
ce_temp_dir
,
ee_temp_dir
])
end
...
...
@@ -22,16 +27,41 @@ RSpec.describe Gitlab::SnowplowEventDefinitionGenerator, :silence_stdout do
end
let
(
:sample_event_dir
)
{
'lib/generators/gitlab/snowplow_event_definition_generator'
}
let
(
:file_name
)
{
Dir
.
children
(
ce_temp_dir
).
first
}
it
'creates CE event definition file using the template'
do
sample_event
=
::
Gitlab
::
Config
::
Loader
::
Yaml
.
new
(
fixture_file
(
File
.
join
(
sample_event_dir
,
'sample_event.yml'
))).
load_raw!
described_class
.
new
([],
generator_options
).
invoke_all
event_definition_path
=
File
.
join
(
ce_temp_dir
,
'groups__email_campaigns_controller_click.yml'
)
event_definition_path
=
File
.
join
(
ce_temp_dir
,
file_name
)
expect
(
::
Gitlab
::
Config
::
Loader
::
Yaml
.
new
(
File
.
read
(
event_definition_path
)).
load_raw!
).
to
eq
(
sample_event
)
end
describe
'generated filename'
do
it
'includes timestamp'
do
described_class
.
new
([],
generator_options
).
invoke_all
expect
(
file_name
).
to
include
(
timestamp
.
to_s
)
end
it
'removes special characters'
do
generator_options
=
{
'category'
=>
'"`ui:[mavenpackages | t5%348()-=@ ]`"'
,
'action'
=>
'click'
}
described_class
.
new
([],
generator_options
).
invoke_all
expect
(
file_name
).
to
include
(
'uimavenpackagest'
)
end
it
'cuts name if longer than 100 characters'
do
generator_options
=
{
'category'
=>
'a'
*
100
,
'action'
=>
'click'
}
described_class
.
new
([],
generator_options
).
invoke_all
expect
(
file_name
.
length
).
to
eq
(
100
)
end
end
context
'event definition already exists'
do
before
do
stub_const
(
'Gitlab::VERSION'
,
'12.11.0-pre'
)
...
...
@@ -44,7 +74,7 @@ RSpec.describe Gitlab::SnowplowEventDefinitionGenerator, :silence_stdout do
stub_const
(
'Gitlab::VERSION'
,
'13.11.0-pre'
)
described_class
.
new
([],
generator_options
.
merge
(
'force'
=>
true
)).
invoke_all
event_definition_path
=
File
.
join
(
ce_temp_dir
,
'groups__email_campaigns_controller_click.yml'
)
event_definition_path
=
File
.
join
(
ce_temp_dir
,
file_name
)
event_data
=
::
Gitlab
::
Config
::
Loader
::
Yaml
.
new
(
File
.
read
(
event_definition_path
)).
load_raw!
expect
(
event_data
).
to
eq
(
sample_event
)
...
...
@@ -56,13 +86,17 @@ RSpec.describe Gitlab::SnowplowEventDefinitionGenerator, :silence_stdout do
end
end
describe
'EE'
do
let
(
:file_name
)
{
Dir
.
children
(
ee_temp_dir
).
first
}
it
'creates EE event definition file using the template'
do
sample_event
=
::
Gitlab
::
Config
::
Loader
::
Yaml
.
new
(
fixture_file
(
File
.
join
(
sample_event_dir
,
'sample_event_ee.yml'
))).
load_raw!
described_class
.
new
([],
generator_options
.
merge
(
'ee'
=>
true
)).
invoke_all
event_definition_path
=
File
.
join
(
ee_temp_dir
,
'groups__email_campaigns_controller_click.yml'
)
event_definition_path
=
File
.
join
(
ee_temp_dir
,
file_name
)
expect
(
::
Gitlab
::
Config
::
Loader
::
Yaml
.
new
(
File
.
read
(
event_definition_path
)).
load_raw!
).
to
eq
(
sample_event
)
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