BigW Consortium Gitlab

Commit aa934c74 by Jarka Kadlecova Committed by Jarka Kadlecova

refresh merge widget after using /merge command

parent 7ab3dd4b
......@@ -3,6 +3,7 @@
/* global GLForm */
/* global Autosave */
/* global ResolveService */
/* global mrRefreshWidgetUrl */
/*= require autosave */
/*= require autosize */
......@@ -244,6 +245,16 @@
};
Notes.prototype.handleCreateChanges = function(note) {
if (typeof note === 'undefined') {
return;
}
if (note.commands_changes && note.commands_changes.includes('merge')) {
$.get(mrRefreshWidgetUrl);
}
};
/*
Render note in main comments area.
......@@ -429,6 +440,7 @@
*/
Notes.prototype.addNote = function(xhr, note, status) {
this.handleCreateChanges(note);
return this.renderNote(note);
};
......
......@@ -347,6 +347,16 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
end
def merge_widget_refresh
if merge_request.in_progress_merge_commit_sha
@status = :success
elsif merge_request.merge_when_build_succeeds
@status = :merge_when_build_succeeds
end
render 'merge'
end
def branch_from
# This is always source
@source_project = @merge_request.nil? ? @project : @merge_request.source_project
......
......@@ -112,3 +112,5 @@
merge_request = new MergeRequest({
action: "#{controller.action_name}"
});
var mrRefreshWidgetUrl = "#{@merge_request && @merge_request.source_project ? merge_widget_refresh_namespace_project_merge_request_url(@merge_request.source_project.namespace, @merge_request.source_project, @merge_request) : ''}";
......@@ -94,6 +94,7 @@ constraints(ProjectUrlConstrainer.new) do
get :pipelines
get :merge_check
post :merge
get :merge_widget_refresh
post :cancel_merge_when_build_succeeds
get :ci_status
get :ci_environments_status
......
......@@ -1048,4 +1048,56 @@ describe Projects::MergeRequestsController do
end
end
end
describe 'GET merge_widget_refresh' do
let(:params) do
{
namespace_id: project.namespace.path,
project_id: project.path,
id: merge_request.iid,
format: :raw
}
end
before do
project.team << [user, :developer]
xhr :get, :merge_widget_refresh, params
end
context 'when merge in progress' do
let(:merge_request) { create(:merge_request, source_project: project, in_progress_merge_commit_sha: 'sha') }
it 'returns an OK response' do
expect(response).to have_http_status(:ok)
end
it 'returns :success' do
expect(assigns(:status)).to eq(:success)
end
end
context 'when waiting for build' do
let(:merge_request) { create(:merge_request, source_project: project, merge_when_build_succeeds: true, merge_user: user) }
it 'returns an OK response' do
expect(response).to have_http_status(:ok)
end
it 'returns :merge_when_build_succeeds' do
expect(assigns(:status)).to eq(:merge_when_build_succeeds)
end
end
context 'when no special status for MR' do
let(:merge_request) { create(:merge_request, source_project: project) }
it 'returns an OK response' do
expect(response).to have_http_status(:ok)
end
it 'returns nil' do
expect(assigns(:status)).to be_nil
end
end
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