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
6f0845eb
Commit
6f0845eb
authored
Mar 23, 2020
by
Kirstie Cook
Committed by
Grzegorz Bizon
Mar 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start merge request for custom dashboard if new branch is provided
parent
1826fe76
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
1 deletion
+70
-1
app/services/metrics/dashboard/update_dashboard_service.rb
app/services/metrics/dashboard/update_dashboard_service.rb
+19
-1
changelogs/unreleased/208174-create-merge-request.yml
changelogs/unreleased/208174-create-merge-request.yml
+5
-0
spec/services/metrics/dashboard/update_dashboard_service_spec.rb
...rvices/metrics/dashboard/update_dashboard_service_spec.rb
+46
-0
No files found.
app/services/metrics/dashboard/update_dashboard_service.rb
View file @
6f0845eb
...
...
@@ -12,7 +12,8 @@ module Metrics
steps
:check_push_authorized
,
:check_branch_name
,
:check_file_type
,
:update_file
:update_file
,
:create_merge_request
def
execute
execute_steps
...
...
@@ -49,6 +50,23 @@ module Metrics
end
end
def
create_merge_request
(
result
)
return
success
(
result
)
if
project
.
default_branch
==
branch
merge_request_params
=
{
source_branch:
branch
,
target_branch:
project
.
default_branch
,
title:
params
[
:commit_message
]
}
merge_request
=
::
MergeRequests
::
CreateService
.
new
(
project
,
current_user
,
merge_request_params
).
execute
if
merge_request
.
persisted?
success
(
result
.
merge
(
merge_request:
Gitlab
::
UrlBuilder
.
build
(
merge_request
)))
else
error
(
merge_request
.
errors
.
full_messages
.
join
(
','
),
:bad_request
)
end
end
def
push_authorized?
Gitlab
::
UserAccess
.
new
(
current_user
,
project:
project
).
can_push_to_branch?
(
branch
)
end
...
...
changelogs/unreleased/208174-create-merge-request.yml
0 → 100644
View file @
6f0845eb
---
title
:
Start merge request for custom dashboard if new branch is provided
merge_request
:
27189
author
:
type
:
added
spec/services/metrics/dashboard/update_dashboard_service_spec.rb
View file @
6f0845eb
...
...
@@ -92,6 +92,8 @@ describe Metrics::Dashboard::UpdateDashboardService, :use_clean_rails_memory_sto
end
context
'Files::UpdateService success'
do
let
(
:merge_request
)
{
project
.
merge_requests
.
last
}
before
do
allow
(
::
Files
::
UpdateService
).
to
receive
(
:new
).
and_return
(
double
(
execute:
{
status: :success
}))
end
...
...
@@ -107,6 +109,31 @@ describe Metrics::Dashboard::UpdateDashboardService, :use_clean_rails_memory_sto
expect
(
service_call
[
:status
]).
to
be
:success
expect
(
service_call
[
:http_status
]).
to
be
:created
expect
(
service_call
[
:dashboard
]).
to
match
dashboard_details
expect
(
service_call
[
:merge_request
]).
to
eq
(
Gitlab
::
UrlBuilder
.
build
(
merge_request
))
end
context
'when the merge request does not succeed'
do
let
(
:error_message
)
{
'There was an error'
}
let
(
:merge_request
)
do
build
(
:merge_request
,
target_project:
project
,
source_project:
project
,
author:
user
)
end
before
do
merge_request
.
errors
.
add
(
:base
,
error_message
)
allow_next_instance_of
(
::
MergeRequests
::
CreateService
)
do
|
mr
|
allow
(
mr
).
to
receive
(
:execute
).
and_return
(
merge_request
)
end
end
it
'returns an appropriate message and status code'
,
:aggregate_failures
do
result
=
service_call
expect
(
result
.
keys
).
to
contain_exactly
(
:message
,
:http_status
,
:status
,
:last_step
)
expect
(
result
[
:status
]).
to
eq
(
:error
)
expect
(
result
[
:http_status
]).
to
eq
(
:bad_request
)
expect
(
result
[
:message
]).
to
eq
(
error_message
)
end
end
context
'with escaped characters in file name'
do
...
...
@@ -125,6 +152,25 @@ describe Metrics::Dashboard::UpdateDashboardService, :use_clean_rails_memory_sto
expect
(
service_call
[
:dashboard
]).
to
match
dashboard_details
end
end
context
'when pushing to the default branch'
do
let
(
:branch
)
{
'master'
}
it
'does not create a merge request'
,
:aggregate_failures
do
dashboard_details
=
{
path:
'.gitlab/dashboards/custom_dashboard.yml'
,
display_name:
'custom_dashboard.yml'
,
default:
false
,
system_dashboard:
false
}
expect
(
::
MergeRequests
::
CreateService
).
not_to
receive
(
:new
)
expect
(
service_call
.
keys
).
to
contain_exactly
(
:dashboard
,
:http_status
,
:status
)
expect
(
service_call
[
:status
]).
to
be
:success
expect
(
service_call
[
:http_status
]).
to
be
:created
expect
(
service_call
[
:dashboard
]).
to
match
dashboard_details
end
end
end
context
'Files::UpdateService fails'
do
...
...
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