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
b4b93272
Commit
b4b93272
authored
Apr 30, 2021
by
Jaime Martinez
Committed by
Shinya Maeda
Apr 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add snowplow tracking to Releases API
parent
4f178c56
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
0 deletions
+53
-0
changelogs/unreleased/296612-instrument-release-cli.yml
changelogs/unreleased/296612-instrument-release-cli.yml
+5
-0
lib/api/releases.rb
lib/api/releases.rb
+23
-0
spec/requests/api/releases_spec.rb
spec/requests/api/releases_spec.rb
+25
-0
No files found.
changelogs/unreleased/296612-instrument-release-cli.yml
0 → 100644
View file @
b4b93272
---
title
:
Add snoplow tracking to Releases API
merge_request
:
58221
author
:
type
:
added
lib/api/releases.rb
View file @
b4b93272
...
...
@@ -6,9 +6,12 @@ module API
RELEASE_ENDPOINT_REQUIREMENTS
=
API
::
NAMESPACE_OR_PROJECT_REQUIREMENTS
.
merge
(
tag_name:
API
::
NO_SLASH_URL_PART_REGEX
)
RELEASE_CLI_USER_AGENT
=
'GitLab-release-cli'
before
{
authorize_read_releases!
}
after
{
track_release_event
}
feature_category
:release_orchestration
params
do
...
...
@@ -17,6 +20,7 @@ module API
resource
:projects
,
requirements:
API
::
NAMESPACE_OR_PROJECT_REQUIREMENTS
do
desc
'Get a project releases'
do
detail
'This feature was introduced in GitLab 11.7.'
named
'get_releases'
success
Entities
::
Release
end
params
do
...
...
@@ -34,6 +38,7 @@ module API
desc
'Get a single project release'
do
detail
'This feature was introduced in GitLab 11.7.'
named
'get_release'
success
Entities
::
Release
end
params
do
...
...
@@ -47,6 +52,7 @@ module API
desc
'Create a new release'
do
detail
'This feature was introduced in GitLab 11.7.'
named
'create_release'
success
Entities
::
Release
end
params
do
...
...
@@ -84,6 +90,7 @@ module API
desc
'Update a release'
do
detail
'This feature was introduced in GitLab 11.7.'
named
'update_release'
success
Entities
::
Release
end
params
do
...
...
@@ -112,6 +119,7 @@ module API
desc
'Delete a release'
do
detail
'This feature was introduced in GitLab 11.7.'
named
'delete_release'
success
Entities
::
Release
end
params
do
...
...
@@ -176,6 +184,21 @@ module API
def
log_release_milestones_updated_audit_event
# extended in EE
end
def
release_cli?
request
.
env
[
'HTTP_USER_AGENT'
]
&
.
include?
(
RELEASE_CLI_USER_AGENT
)
==
true
end
def
event_context
{
release_cli:
release_cli?
}
end
def
track_release_event
Gitlab
::
Tracking
.
event
(
options
[
:for
].
name
,
options
[
:route_options
][
:named
],
project:
user_project
,
user:
current_user
,
**
event_context
)
end
end
end
end
...
...
spec/requests/api/releases_spec.rb
View file @
b4b93272
...
...
@@ -1136,8 +1136,33 @@ RSpec.describe API::Releases do
end
end
describe
'Track API events'
,
:snowplow
do
context
'when tracking event with labels from User-Agent'
do
it
'adds the tracked User-Agent to the label of the tracked event'
do
get
api
(
"/projects/
#{
project
.
id
}
/releases"
,
maintainer
),
headers:
{
'User-Agent'
=>
described_class
::
RELEASE_CLI_USER_AGENT
}
assert_snowplow_event
(
'get_releases'
,
true
)
end
it
'skips label when User-Agent is invalid'
do
get
api
(
"/projects/
#{
project
.
id
}
/releases"
,
maintainer
),
headers:
{
'User-Agent'
=>
'invalid_user_agent'
}
assert_snowplow_event
(
'get_releases'
,
false
)
end
end
end
def
initialize_tags
project
.
repository
.
add_tag
(
maintainer
,
'v0.1'
,
commit
.
id
)
project
.
repository
.
add_tag
(
maintainer
,
'v0.2'
,
commit
.
id
)
end
def
assert_snowplow_event
(
action
,
release_cli
,
user
=
maintainer
)
expect_snowplow_event
(
category:
described_class
.
name
,
action:
action
,
project:
project
,
user:
user
,
release_cli:
release_cli
)
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