diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-10 06:10:01 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-10 06:10:01 +0300 |
commit | 9c03c1c545d1afeaf12d8ee1c204936cdf8c55e1 (patch) | |
tree | dd54368461117b3a32f48855402ba3d40ac909fe /app | |
parent | bc95576e2cbbd2def7a6fce1bde2d0263a3d7da1 (diff) |
Make automerge via satellite
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/merge_request.js.coffee | 13 | ||||
-rw-r--r-- | app/controllers/projects/merge_requests_controller.rb | 7 | ||||
-rw-r--r-- | app/views/projects/merge_requests/_show.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/merge_requests/automerge.js.haml | 3 | ||||
-rw-r--r-- | app/workers/auto_merge_worker.rb | 13 |
5 files changed, 32 insertions, 6 deletions
diff --git a/app/assets/javascripts/merge_request.js.coffee b/app/assets/javascripts/merge_request.js.coffee index 9e3ca45ce04..5bcbd56852d 100644 --- a/app/assets/javascripts/merge_request.js.coffee +++ b/app/assets/javascripts/merge_request.js.coffee @@ -135,3 +135,16 @@ class @MergeRequest this.$('.automerge_widget').hide() this.$('.merge-in-progress').hide() this.$('.automerge_widget.already_cannot_be_merged').show() + + mergeInProgress: -> + $.ajax + type: 'GET' + url: $('.merge-request').data('url') + success: (data) => + switch data.state + when 'merged' + location.reload() + else + setTimeout(merge_request.mergeInProgress, 3000) + dataType: 'json' + diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index d23461821d7..3f702b0af97 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -27,6 +27,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController respond_to do |format| format.html + format.json { render json: @merge_request } format.diff { render text: @merge_request.to_diff(current_user) } format.patch { render text: @merge_request.to_patch(current_user) } end @@ -104,15 +105,15 @@ class Projects::MergeRequestsController < Projects::ApplicationController if @merge_request.unchecked? @merge_request.check_if_can_be_merged end - render json: {merge_status: @merge_request.merge_status_name} + + render json: { merge_status: @merge_request.merge_status_name } end def automerge return access_denied! unless allowed_to_merge? if @merge_request.open? && @merge_request.can_be_merged? - @merge_request.should_remove_source_branch = params[:should_remove_source_branch] - @merge_request.automerge!(current_user, params[:commit_message]) + AutoMergeWorker.perform_async(@merge_request.id, current_user.id, params) @status = true else @status = false diff --git a/app/views/projects/merge_requests/_show.html.haml b/app/views/projects/merge_requests/_show.html.haml index f8d2673335a..8e31a7e3fe4 100644 --- a/app/views/projects/merge_requests/_show.html.haml +++ b/app/views/projects/merge_requests/_show.html.haml @@ -1,4 +1,4 @@ -.merge-request +.merge-request{'data-url' => project_merge_request_path(@project, @merge_request)} = render "projects/merge_requests/show/mr_title" %hr = render "projects/merge_requests/show/mr_box" diff --git a/app/views/projects/merge_requests/automerge.js.haml b/app/views/projects/merge_requests/automerge.js.haml index e01ff662e7d..a53cbb150a4 100644 --- a/app/views/projects/merge_requests/automerge.js.haml +++ b/app/views/projects/merge_requests/automerge.js.haml @@ -1,7 +1,6 @@ -if @status :plain - location.reload(); + merge_request.mergeInProgress(); -else :plain merge_request.alreadyOrCannotBeMerged() - diff --git a/app/workers/auto_merge_worker.rb b/app/workers/auto_merge_worker.rb new file mode 100644 index 00000000000..a6dd73eee5f --- /dev/null +++ b/app/workers/auto_merge_worker.rb @@ -0,0 +1,13 @@ +class AutoMergeWorker + include Sidekiq::Worker + + sidekiq_options queue: :default + + def perform(merge_request_id, current_user_id, params) + params = params.with_indifferent_access + current_user = User.find(current_user_id) + merge_request = MergeRequest.find(merge_request_id) + merge_request.should_remove_source_branch = params[:should_remove_source_branch] + merge_request.automerge!(current_user, params[:commit_message]) + end +end |