Commit 476cf23f authored by Felipe Artur's avatar Felipe Artur

Allow to close invalid merge request

parent 4d04e918
......@@ -150,13 +150,11 @@ class Commit
end
def hook_attrs(with_changed_files: false)
path_with_namespace = project.path_with_namespace
data = {
id: id,
message: safe_message,
timestamp: committed_date.xmlschema,
url: "#{Gitlab.config.gitlab.url}/#{path_with_namespace}/commit/#{id}",
url: commit_url,
author: {
name: author_name,
email: author_email
......@@ -170,6 +168,10 @@ class Commit
data
end
def commit_url
project.present? ? "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/commit/#{id}" : ""
end
# Discover issues should be closed when this commit is pushed to a project's
# default branch.
def closes_issues(current_user = self.committer)
......
......@@ -213,6 +213,8 @@ class MergeRequest < ActiveRecord::Base
end
def validate_branches
return if allow_broken
if target_project == source_project && target_branch == source_branch
errors.add :branch_conflict, "You can not use same project/branch for source and target"
end
......@@ -344,9 +346,12 @@ class MergeRequest < ActiveRecord::Base
end
def hook_attrs
source_hook_attrs = source_project.hook_attrs if source_project.present?
target_hook_attrs = target_project.hook_attrs if target_project.present?
attrs = {
source: source_project.hook_attrs,
target: target_project.hook_attrs,
source: source_hook_attrs,
target: target_hook_attrs,
last_commit: nil,
work_in_progress: work_in_progress?
}
......
......@@ -157,6 +157,35 @@ describe Projects::MergeRequestsController do
end
end
describe 'PUT #update' do
context 'there is no source project' do
let(:project) { create(:project) }
let(:fork_project) { create(:forked_project_with_submodules) }
let(:merge_request) { create(:merge_request_with_diffs, source_project: fork_project, source_branch: 'add-submodule-version-bump', target_branch: 'master', target_project: project) }
before do
fork_project.build_forked_project_link(forked_to_project_id: fork_project.id, forked_from_project_id: project.id)
fork_project.save
merge_request.reload
end
it 'closes MR without errors' do
fork_project.destroy
post :update,
namespace_id: project.namespace.path,
project_id: project.path,
id: merge_request.iid,
merge_request: {
state_event: 'close'
}
expect(response).to redirect_to([merge_request.target_project.namespace.becomes(Namespace), merge_request.target_project, merge_request])
expect(merge_request.reload.closed?).to be_truthy
end
end
end
describe "DELETE #destroy" do
it "denies access to users unless they're admin or project owner" do
delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: merge_request.iid
......
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