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
275d7b38
Commit
275d7b38
authored
Jun 21, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce namespace license checks for rebase before merge
parent
051fbfb8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
114 additions
and
15 deletions
+114
-15
app/controllers/ee/projects/merge_requests_controller.rb
app/controllers/ee/projects/merge_requests_controller.rb
+2
-1
app/models/ee/merge_request.rb
app/models/ee/merge_request.rb
+3
-1
app/models/license.rb
app/models/license.rb
+7
-3
app/views/projects/ee/_merge_request_settings.html.haml
app/views/projects/ee/_merge_request_settings.html.haml
+8
-6
changelogs/unreleased-ee/2570-namespace-rebase-before-merge.yml
...logs/unreleased-ee/2570-namespace-rebase-before-merge.yml
+4
-0
spec/controllers/projects/merge_requests_controller_ee_spec.rb
...controllers/projects/merge_requests_controller_ee_spec.rb
+63
-3
spec/models/ee/merge_request_spec.rb
spec/models/ee/merge_request_spec.rb
+27
-1
No files found.
app/controllers/ee/projects/merge_requests_controller.rb
View file @
275d7b38
...
...
@@ -4,12 +4,13 @@ module EE
extend
ActiveSupport
::
Concern
prepended
do
# This module is prepended to `Projects::MergeRequstController`, which
# This module is prepended to `Projects::MergeRequ
e
stController`, which
# already calls `before_action :merge_request, only: [...]`. Calling it
# again here would *replace* the restriction, rather than extending it.
before_action
(
only:
[
:approve
,
:approvals
,
:unapprove
,
:rebase
])
{
merge_request
}
before_action
:set_suggested_approvers
,
only:
[
:new
,
:new_diffs
,
:edit
]
before_action
:check_merge_request_rebase_available!
,
only:
[
:rebase
]
end
def
rebase
...
...
app/models/ee/merge_request.rb
View file @
275d7b38
...
...
@@ -5,7 +5,9 @@ module EE
end
def
should_be_rebased?
self
.
project
.
ff_merge_must_be_possible?
&&
!
ff_merge_possible?
project
.
feature_available?
(
:merge_request_rebase
)
&&
project
.
ff_merge_must_be_possible?
&&
!
ff_merge_possible?
end
def
rebase_dir_path
...
...
app/models/license.rb
View file @
275d7b38
...
...
@@ -10,6 +10,7 @@ class License < ActiveRecord::Base
ELASTIC_SEARCH_FEATURE
=
'GitLab_ElasticSearch'
.
freeze
RELATED_ISSUES_FEATURE
=
'RelatedIssues'
.
freeze
EXPORT_ISSUES_FEATURE
=
'GitLab_ExportIssues'
.
freeze
MERGE_REQUEST_REBASE_FEATURE
=
'GitLab_MergeRequestRebase'
.
freeze
FEATURE_CODES
=
{
geo:
GEO_FEATURE
,
...
...
@@ -21,7 +22,8 @@ class License < ActiveRecord::Base
# Features that make sense to Namespace:
deploy_board:
DEPLOY_BOARD_FEATURE
,
file_lock:
FILE_LOCK_FEATURE
,
export_issues:
EXPORT_ISSUES_FEATURE
export_issues:
EXPORT_ISSUES_FEATURE
,
merge_request_rebase:
MERGE_REQUEST_REBASE_FEATURE
}.
freeze
STARTER_PLAN
=
'starter'
.
freeze
...
...
@@ -32,7 +34,8 @@ class License < ActiveRecord::Base
EES_FEATURES
=
[
{
ELASTIC_SEARCH_FEATURE
=>
1
},
{
RELATED_ISSUES_FEATURE
=>
1
},
{
EXPORT_ISSUES_FEATURE
=>
1
}
{
EXPORT_ISSUES_FEATURE
=>
1
},
{
MERGE_REQUEST_REBASE_FEATURE
=>
1
}
].
freeze
EEP_FEATURES
=
[
...
...
@@ -65,7 +68,8 @@ class License < ActiveRecord::Base
{
AUDITOR_USER_FEATURE
=>
1
},
{
SERVICE_DESK_FEATURE
=>
1
},
{
OBJECT_STORAGE_FEATURE
=>
1
},
{
EXPORT_ISSUES_FEATURE
=>
1
}
{
EXPORT_ISSUES_FEATURE
=>
1
},
{
MERGE_REQUEST_REBASE_FEATURE
=>
1
}
].
freeze
FEATURES_BY_PLAN
=
{
...
...
app/views/projects/ee/_merge_request_settings.html.haml
View file @
275d7b38
...
...
@@ -20,9 +20,10 @@
%span
.descr
A merge commit is created for every merge, but merging is only allowed if fast-forward merge is possible.
This way you could make sure that if this merge request would build, after merging to target branch it would also build.
%br
%span
.descr
When fast-forward merge is not possible, the user is given the option to rebase.
-
if
project
.
feature_available?
(
:merge_request_rebase
)
%br
%span
.descr
When fast-forward merge is not possible, the user is given the option to rebase.
.radio
=
label_tag
:project_merge_method_ff
do
...
...
@@ -31,9 +32,10 @@
%br
%span
.descr
No merge commits are created and all merges are fast-forwarded, which means that merging is only allowed if the branch could be fast-forwarded.
%br
%span
.descr
When fast-forward merge is not possible, the user is given the option to rebase.
-
if
project
.
feature_available?
(
:merge_request_rebase
)
%br
%span
.descr
When fast-forward merge is not possible, the user is given the option to rebase.
.form-group
=
form
.
label
:merge_requests_template
,
class:
'label-light'
do
...
...
changelogs/unreleased-ee/2570-namespace-rebase-before-merge.yml
0 → 100644
View file @
275d7b38
---
title
:
Introduce namespace license checks for rebase before merge
merge_request
:
2200
author
:
spec/controllers/projects/merge_requests_controller_ee_spec.rb
View file @
275d7b38
require
'spec_helper'
describe
Projects
::
MergeRequestsController
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
project
.
owner
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:merge_request
)
{
create
(
:merge_request_with_diffs
,
target_project:
project
,
source_project:
project
)
}
let
(
:user
)
{
project
.
owner
}
let
(
:viewer
)
{
user
}
before
do
sign_in
(
us
er
)
sign_in
(
view
er
)
end
describe
'POST #create'
do
...
...
@@ -347,4 +348,63 @@ describe Projects::MergeRequestsController do
end
end
end
describe
'POST #rebase'
do
def
post_rebase
post
:rebase
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
merge_request
end
def
expect_rebase_worker
expect
(
RebaseWorker
).
to
receive
(
:perform_async
).
with
(
merge_request
.
id
,
viewer
.
id
)
end
context
'successfully'
do
it
'enqeues a RebaseWorker'
do
expect_rebase_worker
post_rebase
expect
(
response
.
status
).
to
eq
(
200
)
end
end
context
'approvals pending'
do
let
(
:project
)
{
create
(
:project
,
approvals_before_merge:
1
)
}
it
'returns 404'
do
expect_rebase_worker
.
never
post_rebase
expect
(
response
.
status
).
to
eq
(
404
)
end
end
context
'user cannot merge'
do
let
(
:viewer
)
{
create
(
:user
)
}
before
do
project
.
add_reporter
(
viewer
)
end
it
'returns 404'
do
expect_rebase_worker
.
never
post_rebase
expect
(
response
.
status
).
to
eq
(
404
)
end
end
context
'rebase unavailable in license'
do
it
'returns 404'
do
stub_licensed_features
(
merge_request_rebase:
false
)
expect_rebase_worker
.
never
post_rebase
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
end
spec/models/ee/merge_request_spec.rb
View file @
275d7b38
require
'spec_helper'
describe
MergeRequest
,
models:
true
do
subject
{
create
(
:merge_request
)
}
let
(
:project
)
{
create
(
:project
)
}
subject
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
describe
'#should_be_rebased?'
do
subject
{
merge_request
.
should_be_rebased?
}
context
'project forbids rebase'
do
it
{
is_expected
.
to
be_falsy
}
end
context
'project allows rebase'
do
let
(
:project
)
{
create
(
:project
,
merge_requests_rebase_enabled:
true
)
}
it
'returns false when the project feature is unavailable'
do
expect
(
merge_request
.
target_project
).
to
receive
(
:feature_available?
).
with
(
:merge_request_rebase
).
and_return
(
false
)
is_expected
.
to
be_falsy
end
it
'returns true when the project feature is available'
do
expect
(
merge_request
.
target_project
).
to
receive
(
:feature_available?
).
with
(
:merge_request_rebase
).
and_return
(
true
)
is_expected
.
to
be_truthy
end
end
end
describe
'#rebase_in_progress?'
do
it
'returns true when there is a current rebase directory'
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