Commit 3ae31798 authored by Jan Provaznik's avatar Jan Provaznik

removed rebase from EE

parent 71280599
<script>
import simplePoll from '~/lib/utils/simple_poll';
import eventHub from '~/vue_merge_request_widget/event_hub';
import statusIcon from '~/vue_merge_request_widget/components/mr_widget_status_icon';
import loadingIcon from '~/vue_shared/components/loading_icon.vue';
import Flash from '~/flash';
export default {
props: {
mr: {
type: Object,
required: true,
},
service: {
type: Object,
required: true,
},
},
components: {
statusIcon,
loadingIcon,
},
data() {
return {
isMakingRequest: false,
rebasingError: null,
};
},
computed: {
status() {
if (this.mr.rebaseInProgress || this.isMakingRequest) {
return 'loading';
}
if (!this.mr.canPushToSourceBranch && !this.mr.rebaseInProgress) {
return 'warning';
}
return 'success';
},
showDisabledButton() {
return ['failed', 'loading'].includes(this.status);
},
},
methods: {
rebase() {
this.isMakingRequest = true;
this.rebasingError = null;
this.service.rebase()
.then(() => {
simplePoll(this.checkRebaseStatus);
})
.catch((error) => {
this.rebasingError = error.merge_error;
this.isMakingRequest = false;
Flash('Something went wrong. Please try again.');
});
},
checkRebaseStatus(continuePolling, stopPolling) {
this.service.poll()
.then(res => res.data)
.then((res) => {
if (res.rebase_in_progress) {
continuePolling();
} else {
this.isMakingRequest = false;
if (res.merge_error && res.merge_error.length) {
this.rebasingError = res.merge_error;
Flash('Something went wrong. Please try again.');
}
eventHub.$emit('MRWidgetUpdateRequested');
stopPolling();
}
})
.catch(() => {
this.isMakingRequest = false;
Flash('Something went wrong. Please try again.');
stopPolling();
});
},
},
};
</script>
<template>
<div class="mr-widget-body media">
<status-icon
:status="status"
:show-disabled-button="showDisabledButton"
/>
<div class="rebase-state-find-class-convention media media-body space-children">
<template v-if="mr.rebaseInProgress || isMakingRequest">
<span class="bold">
Rebase in progress
</span>
</template>
<template v-if="!mr.rebaseInProgress && !mr.canPushToSourceBranch">
<span class="bold">
Fast-forward merge is not possible.
Rebase the source branch onto
<span class="label-branch">{{mr.targetBranch}}</span>
to allow this merge request to be merged.
</span>
</template>
<template v-if="!mr.rebaseInProgress && mr.canPushToSourceBranch && !isMakingRequest">
<div class="accept-merge-holder clearfix js-toggle-container accept-action media space-children">
<button
type="button"
class="btn btn-sm btn-reopen btn-success"
:disabled="isMakingRequest"
@click="rebase">
<loading-icon v-if="isMakingRequest" />
Rebase
</button>
<span
v-if="!rebasingError"
class="bold">
Fast-forward merge is not possible.
Rebase the source branch onto the target branch or merge target
branch into source branch to allow this merge request to be merged.
</span>
<span
v-else
class="bold danger">
{{rebasingError}}
</span>
</div>
</template>
</div>
</div>
</template>
......@@ -2,7 +2,6 @@ import { n__, s__, sprintf } from '~/locale';
import CEWidgetOptions from '~/vue_merge_request_widget/mr_widget_options';
import WidgetApprovals from './components/approvals/mr_widget_approvals';
import GeoSecondaryNode from './components/states/mr_widget_secondary_geo_node';
import RebaseState from './components/states/mr_widget_rebase.vue';
import collapsibleSection from './components/mr_widget_report_collapsible_section.vue';
export default {
......@@ -10,7 +9,6 @@ export default {
components: {
'mr-widget-approvals': WidgetApprovals,
'mr-widget-geo-secondary-node': GeoSecondaryNode,
'mr-widget-rebase': RebaseState,
collapsibleSection,
},
data() {
......
......@@ -7,7 +7,6 @@ export default class MRWidgetService extends CEWidgetService {
super(mr);
this.approvalsPath = mr.approvalsPath;
this.rebasePath = mr.rebasePath;
}
fetchApprovals() {
......@@ -25,10 +24,6 @@ export default class MRWidgetService extends CEWidgetService {
.then(res => res.data);
}
rebase() {
return axios.post(this.rebasePath);
}
fetchReport(endpoint) { // eslint-disable-line
return axios.get(endpoint)
.then(res => res.data);
......
......@@ -5,10 +5,6 @@ export default function (data) {
return 'geoSecondaryNode';
}
if (this.shouldBeRebased) {
return 'rebase';
}
return CEGetStateKey.call(this, data);
}
......@@ -12,7 +12,6 @@ export default class MergeRequestStore extends CEMergeRequestStore {
setData(data) {
this.initGeo(data);
this.initSquashBeforeMerge(data);
this.initRebase(data);
this.initApprovals(data);
super.setData(data);
......@@ -25,13 +24,6 @@ export default class MergeRequestStore extends CEMergeRequestStore {
|| data.enable_squash_before_merge;
}
initRebase(data) {
this.canPushToSourceBranch = data.can_push_to_source_branch;
this.rebaseInProgress = data.rebase_in_progress;
this.approvalsLeft = !data.approved;
this.rebasePath = data.rebase_path;
}
initGeo(data) {
this.isGeoSecondaryNode = this.isGeoSecondaryNode || data.is_geo_secondary_node;
this.geoSecondaryHelpPath = this.geoSecondaryHelpPath || data.geo_secondary_help_path;
......
import stateMaps from '~/vue_merge_request_widget/stores/state_maps';
stateMaps.stateToComponentMap.geoSecondaryNode = 'mr-widget-geo-secondary-node';
stateMaps.stateToComponentMap.rebase = 'mr-widget-rebase';
stateMaps.statesToShowHelpWidget.push('rebase');
export default {
stateToComponentMap: stateMaps.stateToComponentMap,
......
......@@ -3,17 +3,6 @@ module EE
module MergeRequestsController
extend ActiveSupport::Concern
prepended do
before_action :check_merge_request_rebase_available!, only: [:rebase]
before_action :check_user_can_push_to_source_branch!, only: [:rebase]
end
def rebase
RebaseWorker.perform_async(merge_request.id, current_user.id)
render nothing: true, status: 200
end
def approve
unless merge_request.can_approve?(current_user)
return render_404
......@@ -63,16 +52,6 @@ module EE
attrs
end
def check_user_can_push_to_source_branch!
return access_denied! unless merge_request.source_branch_exists?
access_check = ::Gitlab::UserAccess
.new(current_user, project: merge_request.source_project)
.can_push_to_branch?(merge_request.source_branch)
access_denied! unless access_check
end
end
end
end
......@@ -19,13 +19,6 @@ module EE
delegate :sha, to: :base_pipeline, prefix: :base_pipeline, allow_nil: true
end
def rebase_in_progress?
# The source project can be deleted
return false unless source_project
source_project.repository.rebase_in_progress?(id)
end
def squash_in_progress?
# The source project can be deleted
return false unless source_project
......
......@@ -419,11 +419,6 @@ module EE
super unless mirror?
end
def merge_requests_rebase_enabled
super && feature_available?(:merge_request_rebase)
end
alias_method :merge_requests_rebase_enabled?, :merge_requests_rebase_enabled
def merge_requests_ff_only_enabled
super
end
......
......@@ -31,13 +31,6 @@ module EE
refs.map { |sha| commit(sha.strip) }
end
def rebase(user, merge_request)
raw.rebase(user, merge_request.id, branch: merge_request.source_branch,
branch_sha: merge_request.source_branch_sha,
remote_repository: merge_request.target_project.repository.raw,
remote_branch: merge_request.target_branch)
end
def squash(user, merge_request)
raw.squash(user, merge_request.id, branch: merge_request.target_branch,
start_sha: merge_request.diff_start_sha,
......
......@@ -19,7 +19,6 @@ class License < ActiveRecord::Base
jenkins_integration
ldap_group_sync
merge_request_approvers
merge_request_rebase
merge_request_squash
multiple_ldap_servers
multiple_issue_assignees
......@@ -79,7 +78,6 @@ class License < ActiveRecord::Base
issue_weights
jenkins_integration
merge_request_approvers
merge_request_rebase
merge_request_squash
multiple_issue_assignees
multiple_issue_boards
......
module MergeRequests
class RebaseService < MergeRequests::WorkingCopyBaseService
def execute(merge_request)
@merge_request = merge_request
if rebase
success
else
error('Failed to rebase. Should be done manually')
end
end
def rebase
if merge_request.rebase_in_progress?
log_error('Rebase task canceled: Another rebase is already in progress', save_message_on_model: true)
return false
end
rebase_sha = repository.rebase(current_user, merge_request)
merge_request.update_attributes(rebase_commit_sha: rebase_sha)
true
rescue => e
log_error('Failed to rebase branch:')
log_error(e.message, save_message_on_model: true)
false
end
end
end
module MergeRequests
class WorkingCopyBaseService < MergeRequests::BaseService
attr_reader :merge_request
def source_project
@source_project ||= merge_request.source_project
end
def target_project
@target_project ||= merge_request.target_project
end
def log_error(message, save_message_on_model: false)
Gitlab::GitLogger.error("#{self.class.name} error (#{merge_request.to_reference(full: true)}): #{message}")
merge_request.update(merge_error: message) if save_message_on_model
end
# Don't try to print expensive instance variables.
def inspect
"#<#{self.class} #{merge_request.to_reference(full: true)}>"
end
end
end
- form = local_assigns.fetch(:form)
- project = local_assigns.fetch(:project)
.radio
= label_tag :project_merge_method_ff do
= form.radio_button :merge_method, :ff, class: "js-merge-method-radio"
%strong Fast-forward merge
%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.
- 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 = local_assigns.fetch(:form)
.radio
= label_tag :project_merge_method_rebase_merge do
= form.radio_button :merge_method, :rebase_merge, class: "js-merge-method-radio"
%strong Merge commit with semi-linear history
%br
%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.
......@@ -11,9 +11,9 @@
%span.descr
A merge commit is created for every merge, and merging is allowed as long as there are no conflicts.
= render 'projects/ee/merge_request_rebase_settings', form: form
= render 'projects/merge_request_rebase_settings', form: form
= render 'projects/ee/merge_request_fast_forward_settings', project: @project, form: form
= render 'projects/merge_request_fast_forward_settings', project: @project, form: form
- if @project.feature_available?(:issuable_default_templates)
......
class RebaseWorker
include ApplicationWorker
def perform(merge_request_id, current_user_id)
current_user = User.find(current_user_id)
merge_request = MergeRequest.find(merge_request_id)
MergeRequests::RebaseService
.new(merge_request.source_project, current_user)
.execute(merge_request)
end
end
......@@ -367,16 +367,6 @@ describe Projects::MergeRequestsController do
expect(RebaseWorker).to receive(:perform_async).with(merge_request.id, user.id)
end
context 'successfully' do
it 'enqeues a RebaseWorker' do
expect_rebase_worker_for(viewer)
post_rebase
expect(response.status).to eq(200)
end
end
context 'approvals pending' do
let(:project) { create(:project, :repository, approvals_before_merge: 1) }
......@@ -399,43 +389,6 @@ describe Projects::MergeRequestsController do
end
it_behaves_like 'approvals'
context 'user cannot push to source branch' do
it 'returns 404' do
expect_rebase_worker_for(viewer).never
post_rebase
expect(response.status).to eq(404)
end
end
context 'user can push to source branch' do
before do
project.add_reporter(fork_owner)
sign_in(fork_owner)
end
it 'returns 200' do
expect_rebase_worker_for(fork_owner)
post_rebase
expect(response.status).to eq(200)
end
end
end
context 'rebase unavailable in license' do
it 'returns 404' do
stub_licensed_features(merge_request_rebase: false)
expect_rebase_worker_for(viewer).never
post_rebase
expect(response.status).to eq(404)
end
end
end
end
......@@ -13,66 +13,6 @@ describe MergeRequest do
it { is_expected.to have_many(:approver_groups).dependent(:delete_all) }
end
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, :repository, 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).at_least(:once).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).at_least(:once).and_return(true)
is_expected.to be_truthy
end
end
end
describe '#rebase_in_progress?' do
# Create merge request and project before we stub file calls
before do
subject
end
it 'returns true when there is a current rebase directory' do
allow(File).to receive(:exist?).and_return(true)
allow(File).to receive(:mtime).and_return(Time.now)
expect(subject.rebase_in_progress?).to be_truthy
end
it 'returns false when there is no rebase directory' do
allow(File).to receive(:exist?).and_return(false)
expect(subject.rebase_in_progress?).to be_falsey
end
it 'returns false when the rebase directory has expired' do
allow(File).to receive(:exist?).and_return(true)
allow(File).to receive(:mtime).and_return(20.minutes.ago)
expect(subject.rebase_in_progress?).to be_falsey
end
it 'returns false when the source project has been removed' do
allow(subject).to receive(:source_project).and_return(nil)
allow(File).to receive(:exist?).and_return(true)
allow(File).to receive(:mtime).and_return(Time.now)
expect(File).not_to have_received(:exist?)
expect(subject.rebase_in_progress?).to be_falsey
end
end
describe '#squash_in_progress?' do
# Create merge request and project before we stub file calls
before do
......
......@@ -1066,31 +1066,6 @@ describe Project do
end
end
describe '#merge_method' do
where(:ff, :rebase, :rebase_licensed, :method) do
true | true | true | :ff
true | true | false | :ff
true | false | true | :ff
true | false | false | :ff
false | true | true | :rebase_merge
false | true | false | :merge
false | false | true | :merge
false | false | false | :merge
end
with_them do
let(:project) { build(:project, merge_requests_rebase_enabled: rebase, merge_requests_ff_only_enabled: ff) }
subject { project.merge_method }
before do
stub_licensed_features(merge_request_rebase: rebase_licensed)
end
it { is_expected.to eq(method) }
end
end
describe '#rename_repo' do
context 'when running on a primary node' do
set(:primary) { create(:geo_node, :primary) }
......
......@@ -456,14 +456,21 @@ describe Project do
end
describe '#merge_method' do
it 'returns "ff" merge_method when ff is enabled' do
project = build(:project, merge_requests_ff_only_enabled: true)
expect(project.merge_method).to be :ff
using RSpec::Parameterized::TableSyntax
where(:ff, :rebase, :method) do
true | true | :ff
true | false | :ff
false | true | :rebase_merge
false | false | :merge
end
it 'returns "merge" merge_method when ff is disabled' do
project = build(:project, merge_requests_ff_only_enabled: false)
expect(project.merge_method).to be :merge
with_them do
let(:project) { build(:project, merge_requests_rebase_enabled: rebase, merge_requests_ff_only_enabled: ff) }
subject { project.merge_method }
it { is_expected.to eq(method) }
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment