Skip to content
Snippets Groups Projects
Commit 476cf23f authored by Felipe Artur's avatar Felipe Artur
Browse files

Allow to close invalid merge request

parent 4d04e918
No related branches found
No related tags found
1 merge request!3664Allow to close invalid merge request
Pipeline #
Loading
@@ -150,13 +150,11 @@ class Commit
Loading
@@ -150,13 +150,11 @@ class Commit
end end
   
def hook_attrs(with_changed_files: false) def hook_attrs(with_changed_files: false)
path_with_namespace = project.path_with_namespace
data = { data = {
id: id, id: id,
message: safe_message, message: safe_message,
timestamp: committed_date.xmlschema, timestamp: committed_date.xmlschema,
url: "#{Gitlab.config.gitlab.url}/#{path_with_namespace}/commit/#{id}", url: commit_url,
author: { author: {
name: author_name, name: author_name,
email: author_email email: author_email
Loading
@@ -170,6 +168,10 @@ class Commit
Loading
@@ -170,6 +168,10 @@ class Commit
data data
end 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 # Discover issues should be closed when this commit is pushed to a project's
# default branch. # default branch.
def closes_issues(current_user = self.committer) def closes_issues(current_user = self.committer)
Loading
Loading
Loading
@@ -213,6 +213,8 @@ class MergeRequest < ActiveRecord::Base
Loading
@@ -213,6 +213,8 @@ class MergeRequest < ActiveRecord::Base
end end
   
def validate_branches def validate_branches
return if allow_broken
if target_project == source_project && target_branch == source_branch if target_project == source_project && target_branch == source_branch
errors.add :branch_conflict, "You can not use same project/branch for source and target" errors.add :branch_conflict, "You can not use same project/branch for source and target"
end end
Loading
@@ -344,9 +346,12 @@ class MergeRequest < ActiveRecord::Base
Loading
@@ -344,9 +346,12 @@ class MergeRequest < ActiveRecord::Base
end end
   
def hook_attrs 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 = { attrs = {
source: source_project.hook_attrs, source: source_hook_attrs,
target: target_project.hook_attrs, target: target_hook_attrs,
last_commit: nil, last_commit: nil,
work_in_progress: work_in_progress? work_in_progress: work_in_progress?
} }
Loading
Loading
Loading
@@ -157,6 +157,35 @@ describe Projects::MergeRequestsController do
Loading
@@ -157,6 +157,35 @@ describe Projects::MergeRequestsController do
end end
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 describe "DELETE #destroy" do
it "denies access to users unless they're admin or project owner" 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 delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: merge_request.iid
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment