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
ca09a858
Commit
ca09a858
authored
Jun 26, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add namespace license checks for squash before merge
parent
ad8e7eb1
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
112 additions
and
15 deletions
+112
-15
app/assets/javascripts/vue_merge_request_widget/ee/stores/mr_widget_store.js
...pts/vue_merge_request_widget/ee/stores/mr_widget_store.js
+2
-1
app/controllers/ee/projects/merge_requests_controller.rb
app/controllers/ee/projects/merge_requests_controller.rb
+12
-7
app/models/ee/merge_request.rb
app/models/ee/merge_request.rb
+5
-0
app/models/license.rb
app/models/license.rb
+7
-3
app/services/merge_requests/squash_service.rb
app/services/merge_requests/squash_service.rb
+4
-0
app/views/projects/merge_requests/_show.html.haml
app/views/projects/merge_requests/_show.html.haml
+1
-0
app/views/shared/issuable/form/ee/_squash_merge_param.html.haml
...ews/shared/issuable/form/ee/_squash_merge_param.html.haml
+4
-0
changelogs/unreleased-ee/2571-namespace-squash-and-merge.yml
changelogs/unreleased-ee/2571-namespace-squash-and-merge.yml
+4
-0
lib/api/entities.rb
lib/api/entities.rb
+2
-1
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+1
-1
lib/api/v3/entities.rb
lib/api/v3/entities.rb
+2
-1
lib/api/v3/merge_requests.rb
lib/api/v3/merge_requests.rb
+1
-1
spec/features/merge_requests/squash_spec.rb
spec/features/merge_requests/squash_spec.rb
+20
-0
spec/models/ee/merge_request_spec.rb
spec/models/ee/merge_request_spec.rb
+37
-0
spec/services/merge_requests/squash_service_spec.rb
spec/services/merge_requests/squash_service_spec.rb
+10
-0
No files found.
app/assets/javascripts/vue_merge_request_widget/ee/stores/mr_widget_store.js
View file @
ca09a858
...
...
@@ -18,7 +18,8 @@ export default class MergeRequestStore extends CEMergeRequestStore {
initSquashBeforeMerge
(
data
)
{
this
.
squashBeforeMergeHelpPath
=
this
.
squashBeforeMergeHelpPath
||
data
.
squash_before_merge_help_path
;
this
.
enableSquashBeforeMerge
=
true
;
this
.
enableSquashBeforeMerge
=
this
.
enableSquashBeforeMerge
||
data
.
enable_squash_before_merge
;
}
initRebase
(
data
)
{
...
...
app/controllers/ee/projects/merge_requests_controller.rb
View file @
ca09a858
...
...
@@ -69,7 +69,10 @@ module EE
end
def
merge_params_attributes
super
+
[
:squash
]
attrs
=
super
attrs
<<
:squash
if
project
.
feature_available?
(
:merge_request_squash
)
attrs
end
def
merge_request_params
...
...
@@ -77,12 +80,14 @@ module EE
end
def
merge_request_params_attributes
super
+
%i[
approvals_before_merge
approver_group_ids
approver_ids
squash
]
attrs
=
super
.
push
(
:approvals_before_merge
,
:approver_group_ids
,
:approver_ids
)
attrs
<<
:squash
if
project
.
feature_available?
(
:merge_request_squash
)
attrs
end
# If the number of approvals is not greater than the project default, set to
...
...
app/models/ee/merge_request.rb
View file @
ca09a858
...
...
@@ -45,5 +45,10 @@ module EE
true
end
end
def
squash
super
&&
project
.
feature_available?
(
:merge_request_squash
)
end
alias_method
:squash?
,
:squash
end
end
app/models/license.rb
View file @
ca09a858
...
...
@@ -11,6 +11,7 @@ class License < ActiveRecord::Base
RELATED_ISSUES_FEATURE
=
'RelatedIssues'
.
freeze
EXPORT_ISSUES_FEATURE
=
'GitLab_ExportIssues'
.
freeze
MERGE_REQUEST_REBASE_FEATURE
=
'GitLab_MergeRequestRebase'
.
freeze
MERGE_REQUEST_SQUASH_FEATURE
=
'GitLab_MergeRequestSquash'
.
freeze
FEATURE_CODES
=
{
geo:
GEO_FEATURE
,
...
...
@@ -23,7 +24,8 @@ class License < ActiveRecord::Base
deploy_board:
DEPLOY_BOARD_FEATURE
,
file_lock:
FILE_LOCK_FEATURE
,
export_issues:
EXPORT_ISSUES_FEATURE
,
merge_request_rebase:
MERGE_REQUEST_REBASE_FEATURE
merge_request_rebase:
MERGE_REQUEST_REBASE_FEATURE
,
merge_request_squash:
MERGE_REQUEST_SQUASH_FEATURE
}.
freeze
STARTER_PLAN
=
'starter'
.
freeze
...
...
@@ -35,7 +37,8 @@ class License < ActiveRecord::Base
{
ELASTIC_SEARCH_FEATURE
=>
1
},
{
RELATED_ISSUES_FEATURE
=>
1
},
{
EXPORT_ISSUES_FEATURE
=>
1
},
{
MERGE_REQUEST_REBASE_FEATURE
=>
1
}
{
MERGE_REQUEST_REBASE_FEATURE
=>
1
},
{
MERGE_REQUEST_SQUASH_FEATURE
=>
1
}
].
freeze
EEP_FEATURES
=
[
...
...
@@ -69,7 +72,8 @@ class License < ActiveRecord::Base
{
SERVICE_DESK_FEATURE
=>
1
},
{
OBJECT_STORAGE_FEATURE
=>
1
},
{
EXPORT_ISSUES_FEATURE
=>
1
},
{
MERGE_REQUEST_REBASE_FEATURE
=>
1
}
{
MERGE_REQUEST_REBASE_FEATURE
=>
1
},
{
MERGE_REQUEST_SQUASH_FEATURE
=>
1
}
].
freeze
FEATURES_BY_PLAN
=
{
...
...
app/services/merge_requests/squash_service.rb
View file @
ca09a858
...
...
@@ -17,6 +17,10 @@ module MergeRequests
return
success
(
squash_sha:
merge_request
.
diff_head_sha
)
end
unless
project
.
feature_available?
(
:merge_request_squash
)
return
error
(
'License does not allow squashing'
)
end
if
merge_request
.
squash_in_progress?
return
error
(
'Squash task canceled: another squash is already in progress.'
)
end
...
...
app/views/projects/merge_requests/_show.html.haml
View file @
ca09a858
...
...
@@ -23,6 +23,7 @@
// Object.assign would be useful here, but it blows up Phantom.js in tests
window
.
gl
.
mrWidgetData
.
is_geo_secondary_node
=
'
#{
Gitlab
::
Geo
.
secondary?
}
'
===
'
true
'
;
window
.
gl
.
mrWidgetData
.
geo_secondary_help_path
=
'
#{
help_page_path
(
"/gitlab-geo/configuration.md"
)
}
'
;
window
.
gl
.
mrWidgetData
.
enable_squash_before_merge
=
'
#{
@merge_request
.
project
.
feature_available?
(
:merge_request_squash
)
}
'
===
'
true
'
;
window
.
gl
.
mrWidgetData
.
squash_before_merge_help_path
=
'
#{
help_page_path
(
"user/project/merge_requests/squash_and_merge"
)
}
'
;
#js-vue-mr-widget
.mr-widget
...
...
app/views/shared/issuable/form/ee/_squash_merge_param.html.haml
View file @
ca09a858
-
issuable
=
local_assigns
.
fetch
(
:issuable
)
-
return
unless
issuable
.
project
.
feature_available?
(
:merge_request_squash
)
.form-group
.col-sm-10.col-sm-offset-2
.checkbox
...
...
changelogs/unreleased-ee/2571-namespace-squash-and-merge.yml
0 → 100644
View file @
ca09a858
---
title
:
Add namespace license checks for squash before merge
merge_request
:
2249
author
:
lib/api/entities.rb
View file @
ca09a858
...
...
@@ -363,7 +363,8 @@ module API
expose
:approvals_before_merge
expose
:should_remove_source_branch?
,
as: :should_remove_source_branch
expose
:force_remove_source_branch?
,
as: :force_remove_source_branch
expose
:squash
expose
:squash
,
if:
->
(
mr
,
_
)
{
mr
.
project
.
feature_available?
(
:merge_request_squash
)
}
expose
:web_url
do
|
merge_request
,
options
|
Gitlab
::
UrlBuilder
.
build
(
merge_request
)
...
...
lib/api/merge_requests.rb
View file @
ca09a858
...
...
@@ -232,7 +232,7 @@ module API
render_api_error!
(
"SHA does not match HEAD of source branch:
#{
merge_request
.
diff_head_sha
}
"
,
409
)
end
if
params
[
:squash
]
if
params
[
:squash
]
&&
merge_request
.
project
.
feature_available?
(
:merge_request_squash
)
merge_request
.
update
(
squash:
params
[
:squash
])
end
...
...
lib/api/v3/entities.rb
View file @
ca09a858
...
...
@@ -160,7 +160,8 @@ module API
expose
:approvals_before_merge
expose
:should_remove_source_branch?
,
as: :should_remove_source_branch
expose
:force_remove_source_branch?
,
as: :force_remove_source_branch
expose
:squash
expose
:squash
,
if:
->
(
mr
,
_
)
{
mr
.
project
.
feature_available?
(
:merge_request_squash
)
}
expose
:web_url
do
|
merge_request
,
options
|
Gitlab
::
UrlBuilder
.
build
(
merge_request
)
...
...
lib/api/v3/merge_requests.rb
View file @
ca09a858
...
...
@@ -209,7 +209,7 @@ module API
render_api_error!
(
"SHA does not match HEAD of source branch:
#{
merge_request
.
diff_head_sha
}
"
,
409
)
end
if
params
[
:squash
]
if
params
[
:squash
]
&&
merge_request
.
project
.
feature_available?
(
:merge_request_squash
)
merge_request
.
update
(
squash:
params
[
:squash
])
end
...
...
spec/features/merge_requests/squash_spec.rb
View file @
ca09a858
...
...
@@ -121,4 +121,24 @@ feature 'Squashing merge requests', js: true, feature: true do
include_examples
'no squash'
end
end
context
'squash is unlicensed'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
,
source_branch:
source_branch
,
target_branch:
'master'
,
squash:
true
)
}
before
do
stub_licensed_features
(
merge_request_squash:
false
)
end
it
'does not show squash option when creating MR'
do
visit
new_namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request:
{
target_branch:
'master'
,
source_branch:
source_branch
})
expect
(
page
).
to
have_no_field
(
'merge_request[squash]'
)
end
it
'does not show squash option when viewing MR'
do
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
)
expect
(
page
).
to
have_no_field
(
'squash'
)
end
end
end
spec/models/ee/merge_request_spec.rb
View file @
ca09a858
...
...
@@ -90,4 +90,41 @@ describe MergeRequest, models: true do
expect
(
subject
.
squash_in_progress?
).
to
be_falsey
end
end
describe
'#squash?'
do
let
(
:merge_request
)
{
build
(
:merge_request
,
squash:
squash
)
}
subject
{
merge_request
.
squash?
}
context
'unlicensed'
do
before
do
stub_licensed_features
(
merge_request_squash:
false
)
end
context
'disabled in database'
do
let
(
:squash
)
{
false
}
it
{
is_expected
.
to
be_falsy
}
end
context
'enabled in database'
do
let
(
:squash
)
{
true
}
it
{
is_expected
.
to
be_falsy
}
end
end
context
'licensed'
do
context
'disabled in database'
do
let
(
:squash
)
{
false
}
it
{
is_expected
.
to
be_falsy
}
end
context
'licensed'
do
let
(
:squash
)
{
true
}
it
{
is_expected
.
to
be_truthy
}
end
end
end
end
spec/services/merge_requests/squash_service_spec.rb
View file @
ca09a858
...
...
@@ -96,6 +96,16 @@ describe MergeRequests::SquashService do
include_examples
'the squash succeeds'
end
context
'squashing is unlicensed'
do
before
do
stub_licensed_features
(
merge_request_squash:
false
)
end
subject
{
service
.
execute
(
merge_request_with_only_new_files
)
}
it
{
is_expected
.
to
match
(
status: :error
,
message:
a_string_including
(
'License'
))
}
end
stages
=
{
'add worktree for squash'
=>
'worktree'
,
'configure sparse checkout'
=>
'config'
,
...
...
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