Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a processor for handling deletion of merge requests.
Replacing MergeRequests#destroy with a call to #soft_delete, which posts a message to the MQ. This processor will both delete the ref in the target repository and delete the merge request itself. The ref in the tracking repository is not deleted yet, nor are updates in the backend handled for merge requests that are closed or reopened.
- Loading branch information
Marius Mathiesen
committed
Jul 17, 2009
1 parent
13a5339
commit 75f054d
Showing
7 changed files
with
142 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
# encoding: utf-8 | |||
#-- | |||
# Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) | |||
# | |||
# This program is free software: you can redistribute it and/or modify | |||
# it under the terms of the GNU Affero General Public License as published by | |||
# the Free Software Foundation, either version 3 of the License, or | |||
# (at your option) any later version. | |||
# | |||
# This program is distributed in the hope that it will be useful, | |||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
# GNU Affero General Public License for more details. | |||
# | |||
# You should have received a copy of the GNU Affero General Public License | |||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
#++ | |||
class MergeRequestGitBackendProcessor < ApplicationProcessor | |||
|
|||
subscribes_to :merge_request_backend_updates | |||
|
|||
def on_message(message) | |||
@body = ActiveSupport::JSON.decode(message) | |||
send("do_#{action}") | |||
end | |||
|
|||
def action | |||
@body["action"].to_sym | |||
end | |||
|
|||
def merge_request | |||
@merge_request ||= MergeRequest.find(@body["merge_request_id"]) | |||
end | |||
|
|||
private | |||
def do_delete | |||
logger.info("Deleting tracking branch #{merge_request.merge_branch_name} for merge request in target repository #{merge_request.target_repository.id}") | |||
begin | |||
merge_request.delete_target_repository_ref | |||
rescue Grit::NoSuchPathError => e | |||
logger.error "Could not find Git path. Message is #{e.message}" | |||
end | |||
merge_request.destroy | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
test/unit/processors/merge_request_git_backend_processor_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,75 @@ | |||
# encoding: utf-8 | |||
#-- | |||
# Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) | |||
# | |||
# This program is free software: you can redistribute it and/or modify | |||
# it under the terms of the GNU Affero General Public License as published by | |||
# the Free Software Foundation, either version 3 of the License, or | |||
# (at your option) any later version. | |||
# | |||
# This program is distributed in the hope that it will be useful, | |||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
# GNU Affero General Public License for more details. | |||
# | |||
# You should have received a copy of the GNU Affero General Public License | |||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
#++ | |||
|
|||
|
|||
require File.dirname(__FILE__) + '/../../test_helper' | |||
|
|||
class MergeRequestGitBackendProcessorTest < ActiveSupport::TestCase | |||
|
|||
def setup | |||
@processor = MergeRequestGitBackendProcessor.new | |||
@merge_request = merge_requests(:moes_to_johans) | |||
@repository = @merge_request.target_repository | |||
end | |||
|
|||
def teardown | |||
@processor = nil | |||
end | |||
|
|||
context "Deleting the merge request and its tracking branch" do | |||
setup do | |||
@msg = {:merge_request_id => @merge_request.to_param, :action => "delete"} | |||
@processor.instance_variable_set("@merge_request", @merge_request) | |||
end | |||
|
|||
should "delete the tracking repo and the merge request itself" do | |||
@merge_request.expects(:delete_target_repository_ref).once | |||
@merge_request.expects(:destroy).once | |||
@processor.on_message(@msg.to_json) | |||
end | |||
|
|||
should "handle non-existing target gits" do | |||
@merge_request.expects(:destroy).once | |||
assert_nothing_raised do | |||
@processor.on_message(@msg.to_json) | |||
end | |||
end | |||
end | |||
|
|||
context "Parsing the action" do | |||
should "understand the delete command" do | |||
msg = {:merge_request_id => @merge_request.to_param, :action => "delete"} | |||
@processor.expects(:do_delete).once | |||
@processor.on_message(msg.to_json) | |||
assert_equal :delete, @processor.action | |||
assert_equal @merge_request, @processor.merge_request | |||
end | |||
|
|||
should "understand the close command" do | |||
msg = {:merge_request_id => @merge_request.to_param, :action => "close"} | |||
@processor.expects(:do_close) | |||
@processor.on_message(msg.to_json) | |||
end | |||
|
|||
should "understand the reopen command" do | |||
msg = {:merge_request_id => @merge_request.to_param, :action => "reopen"} | |||
@processor.expects(:do_reopen) | |||
@processor.on_message(msg.to_json) | |||
end | |||
end | |||
end |