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
5b9e57e0
Commit
5b9e57e0
authored
May 13, 2020
by
Derek Knox
Committed by
Paul Slaughter
May 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tracking for commit northstar
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31350
parent
ab2b2108
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
2 deletions
+34
-2
app/assets/javascripts/static_site_editor/constants.js
app/assets/javascripts/static_site_editor/constants.js
+2
-0
app/assets/javascripts/static_site_editor/services/submit_content_changes.js
...pts/static_site_editor/services/submit_content_changes.js
+7
-2
spec/frontend/static_site_editor/mock_data.js
spec/frontend/static_site_editor/mock_data.js
+2
-0
spec/frontend/static_site_editor/services/submit_content_changes_spec.js
...tatic_site_editor/services/submit_content_changes_spec.js
+23
-0
No files found.
app/assets/javascripts/static_site_editor/constants.js
View file @
5b9e57e0
...
@@ -15,3 +15,5 @@ export const LOAD_CONTENT_ERROR = __(
...
@@ -15,3 +15,5 @@ export const LOAD_CONTENT_ERROR = __(
);
);
export
const
DEFAULT_HEADING
=
s__
(
'
StaticSiteEditor|Static site editor
'
);
export
const
DEFAULT_HEADING
=
s__
(
'
StaticSiteEditor|Static site editor
'
);
export
const
TRACKING_ACTION_CREATE_COMMIT
=
'
create_commit
'
;
app/assets/javascripts/static_site_editor/services/submit_content_changes.js
View file @
5b9e57e0
import
Api
from
'
~/api
'
;
import
Api
from
'
~/api
'
;
import
Tracking
from
'
~/tracking
'
;
import
{
s__
,
sprintf
}
from
'
~/locale
'
;
import
{
s__
,
sprintf
}
from
'
~/locale
'
;
import
{
convertObjectPropsToSnakeCase
}
from
'
~/lib/utils/common_utils
'
;
import
{
convertObjectPropsToSnakeCase
}
from
'
~/lib/utils/common_utils
'
;
import
generateBranchName
from
'
~/static_site_editor/services/generate_branch_name
'
;
import
generateBranchName
from
'
~/static_site_editor/services/generate_branch_name
'
;
...
@@ -8,6 +9,7 @@ import {
...
@@ -8,6 +9,7 @@ import {
SUBMIT_CHANGES_BRANCH_ERROR
,
SUBMIT_CHANGES_BRANCH_ERROR
,
SUBMIT_CHANGES_COMMIT_ERROR
,
SUBMIT_CHANGES_COMMIT_ERROR
,
SUBMIT_CHANGES_MERGE_REQUEST_ERROR
,
SUBMIT_CHANGES_MERGE_REQUEST_ERROR
,
TRACKING_ACTION_CREATE_COMMIT
,
}
from
'
../constants
'
;
}
from
'
../constants
'
;
const
createBranch
=
(
projectId
,
branch
)
=>
const
createBranch
=
(
projectId
,
branch
)
=>
...
@@ -18,8 +20,10 @@ const createBranch = (projectId, branch) =>
...
@@ -18,8 +20,10 @@ const createBranch = (projectId, branch) =>
throw
new
Error
(
SUBMIT_CHANGES_BRANCH_ERROR
);
throw
new
Error
(
SUBMIT_CHANGES_BRANCH_ERROR
);
});
});
const
commitContent
=
(
projectId
,
message
,
branch
,
sourcePath
,
content
)
=>
const
commitContent
=
(
projectId
,
message
,
branch
,
sourcePath
,
content
)
=>
{
Api
.
commitMultiple
(
Tracking
.
event
(
document
.
body
.
dataset
.
page
,
TRACKING_ACTION_CREATE_COMMIT
);
return
Api
.
commitMultiple
(
projectId
,
projectId
,
convertObjectPropsToSnakeCase
({
convertObjectPropsToSnakeCase
({
branch
,
branch
,
...
@@ -35,6 +39,7 @@ const commitContent = (projectId, message, branch, sourcePath, content) =>
...
@@ -35,6 +39,7 @@ const commitContent = (projectId, message, branch, sourcePath, content) =>
).
catch
(()
=>
{
).
catch
(()
=>
{
throw
new
Error
(
SUBMIT_CHANGES_COMMIT_ERROR
);
throw
new
Error
(
SUBMIT_CHANGES_COMMIT_ERROR
);
});
});
};
const
createMergeRequest
=
(
projectId
,
title
,
sourceBranch
,
targetBranch
=
DEFAULT_TARGET_BRANCH
)
=>
const
createMergeRequest
=
(
projectId
,
title
,
sourceBranch
,
targetBranch
=
DEFAULT_TARGET_BRANCH
)
=>
Api
.
createProjectMergeRequest
(
Api
.
createProjectMergeRequest
(
...
...
spec/frontend/static_site_editor/mock_data.js
View file @
5b9e57e0
...
@@ -45,3 +45,5 @@ export const createMergeRequestResponse = {
...
@@ -45,3 +45,5 @@ export const createMergeRequestResponse = {
iid
:
'
123
'
,
iid
:
'
123
'
,
web_url
:
'
/merge_requests/123
'
,
web_url
:
'
/merge_requests/123
'
,
};
};
export
const
trackingCategory
=
'
projects:static_site_editor:show
'
;
spec/frontend/static_site_editor/services/submit_content_changes_spec.js
View file @
5b9e57e0
import
Api
from
'
~/api
'
;
import
Api
from
'
~/api
'
;
import
{
convertObjectPropsToSnakeCase
}
from
'
~/lib/utils/common_utils
'
;
import
{
convertObjectPropsToSnakeCase
}
from
'
~/lib/utils/common_utils
'
;
import
{
mockTracking
,
unmockTracking
}
from
'
helpers/tracking_helper
'
;
import
{
import
{
DEFAULT_TARGET_BRANCH
,
DEFAULT_TARGET_BRANCH
,
SUBMIT_CHANGES_BRANCH_ERROR
,
SUBMIT_CHANGES_BRANCH_ERROR
,
SUBMIT_CHANGES_COMMIT_ERROR
,
SUBMIT_CHANGES_COMMIT_ERROR
,
SUBMIT_CHANGES_MERGE_REQUEST_ERROR
,
SUBMIT_CHANGES_MERGE_REQUEST_ERROR
,
TRACKING_ACTION_CREATE_COMMIT
,
}
from
'
~/static_site_editor/constants
'
;
}
from
'
~/static_site_editor/constants
'
;
import
generateBranchName
from
'
~/static_site_editor/services/generate_branch_name
'
;
import
generateBranchName
from
'
~/static_site_editor/services/generate_branch_name
'
;
import
submitContentChanges
from
'
~/static_site_editor/services/submit_content_changes
'
;
import
submitContentChanges
from
'
~/static_site_editor/services/submit_content_changes
'
;
...
@@ -18,6 +20,7 @@ import {
...
@@ -18,6 +20,7 @@ import {
createMergeRequestResponse
,
createMergeRequestResponse
,
sourcePath
,
sourcePath
,
sourceContent
as
content
,
sourceContent
as
content
,
trackingCategory
,
}
from
'
../mock_data
'
;
}
from
'
../mock_data
'
;
jest
.
mock
(
'
~/static_site_editor/services/generate_branch_name
'
);
jest
.
mock
(
'
~/static_site_editor/services/generate_branch_name
'
);
...
@@ -25,6 +28,8 @@ jest.mock('~/static_site_editor/services/generate_branch_name');
...
@@ -25,6 +28,8 @@ jest.mock('~/static_site_editor/services/generate_branch_name');
describe
(
'
submitContentChanges
'
,
()
=>
{
describe
(
'
submitContentChanges
'
,
()
=>
{
const
mergeRequestTitle
=
`Update
${
sourcePath
}
file`
;
const
mergeRequestTitle
=
`Update
${
sourcePath
}
file`
;
const
branch
=
'
branch-name
'
;
const
branch
=
'
branch-name
'
;
let
trackingSpy
;
let
origPage
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
jest
.
spyOn
(
Api
,
'
createBranch
'
).
mockResolvedValue
({
data
:
commitBranchResponse
});
jest
.
spyOn
(
Api
,
'
createBranch
'
).
mockResolvedValue
({
data
:
commitBranchResponse
});
...
@@ -34,6 +39,15 @@ describe('submitContentChanges', () => {
...
@@ -34,6 +39,15 @@ describe('submitContentChanges', () => {
.
mockResolvedValue
({
data
:
createMergeRequestResponse
});
.
mockResolvedValue
({
data
:
createMergeRequestResponse
});
generateBranchName
.
mockReturnValue
(
branch
);
generateBranchName
.
mockReturnValue
(
branch
);
origPage
=
document
.
body
.
dataset
.
page
;
document
.
body
.
dataset
.
page
=
trackingCategory
;
trackingSpy
=
mockTracking
(
document
.
body
.
dataset
.
page
,
undefined
,
jest
.
spyOn
);
});
afterEach
(()
=>
{
document
.
body
.
dataset
.
page
=
origPage
;
unmockTracking
();
});
});
it
(
'
creates a branch named after the username and target branch
'
,
()
=>
{
it
(
'
creates a branch named after the username and target branch
'
,
()
=>
{
...
@@ -69,6 +83,15 @@ describe('submitContentChanges', () => {
...
@@ -69,6 +83,15 @@ describe('submitContentChanges', () => {
});
});
});
});
it
(
'
sends the correct tracking event when committing content changes
'
,
()
=>
{
return
submitContentChanges
({
username
,
projectId
,
sourcePath
,
content
}).
then
(()
=>
{
expect
(
trackingSpy
).
toHaveBeenCalledWith
(
document
.
body
.
dataset
.
page
,
TRACKING_ACTION_CREATE_COMMIT
,
);
});
});
it
(
'
notifies error when content could not be committed
'
,
()
=>
{
it
(
'
notifies error when content could not be committed
'
,
()
=>
{
Api
.
commitMultiple
.
mockRejectedValueOnce
();
Api
.
commitMultiple
.
mockRejectedValueOnce
();
...
...
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