diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-10-24 18:01:44 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-11-07 16:27:55 +0100 |
commit | 6fbdc5ed5224154b89cf351e11a8f9db48e6d7f0 (patch) | |
tree | dd2ccecd4b1100d4b83f91292b96ec988eecde6d /spec | |
parent | 6d8810a64f944ff96af54e5c759f866bb68a7453 (diff) | |
download | gitlab-ce-6fbdc5ed5224154b89cf351e11a8f9db48e6d7f0.tar.gz |
Apply patches when creating MR via email
This allows users to add patches as attachments to merge request
created via email.
When an email to create a merge request is sent, all the attachments
ending in `.patch` will be applied to the branch specified in the
subject of the email. If the branch did not exist, it will be created
from the HEAD of the repository.
When the patches could not be applied, the error message will be
replied to the user.
The patches can have a maximum combined size of 2MB for now.
Diffstat (limited to 'spec')
14 files changed, 773 insertions, 0 deletions
diff --git a/spec/fixtures/emails/merge_request_multiple_patches.eml b/spec/fixtures/emails/merge_request_multiple_patches.eml new file mode 100644 index 00000000000..311b99a525d --- /dev/null +++ b/spec/fixtures/emails/merge_request_multiple_patches.eml @@ -0,0 +1,181 @@ +From: "Jake the Dog" <jake@adventuretime.ooo> +To: incoming+gitlabhq/gitlabhq+merge-request+auth_token@appmail.adventuretime.ooo +Subject: new-branch-with-a-patch +Date: Wed, 31 Oct 2018 17:27:52 +0100 +X-Mailer: MailMate (1.12r5523) +Message-ID: <7BE7C2E6-F0D9-4C85-9F55-B2A4BA01BFEC@gitlab.com> +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_=" + + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= + +This applies nicely to a branch freshly created from the root-ref + +The other attachments in this email are ignored + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= +Content-Disposition: attachment; + filename=0002-This-does-not-apply-to-the-feature-branch.patch +Content-Transfer-Encoding: quoted-printable + +=46rom 00c68c2b4f954370ce82a1162bc29c13f524897e Mon Sep 17 00:00:00 2001 +From: Patch user <patchuser@gitlab.org> +Date: Mon, 22 Oct 2018 11:05:48 +0200 +Subject: [PATCH] This does not apply to the `feature` branch + +--- + files/ruby/feature.rb | 5 +++++ + 1 file changed, 5 insertions(+) + create mode 100644 files/ruby/feature.rb + +diff --git a/files/ruby/feature.rb b/files/ruby/feature.rb +new file mode 100644 +index 0000000..fef26e4 +--- /dev/null ++++ b/files/ruby/feature.rb +@@ -0,0 +1,5 @@ ++class Feature ++ def bar ++ puts 'foo' ++ end ++end +-- = + +2.19.1 + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= +Content-Disposition: attachment; filename=0001-A-commit-from-a-patch.patch +Content-Transfer-Encoding: quoted-printable + +=46rom 3fee0042e610fb3563e4379e316704cb1210f3de Mon Sep 17 00:00:00 2001 +From: Patch user <patchuser@gitlab.org> +Date: Thu, 18 Oct 2018 13:40:35 +0200 +Subject: [PATCH] A commit from a patch + +--- + README | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/README b/README +index 3742e48..e40a3b9 100644 +--- a/README ++++ b/README +@@ -1 +1,3 @@ + Sample repo for testing gitlab features ++ ++This was applied in a patch! +-- = + +2.19.1 + + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= +Content-Disposition: attachment; filename=really-not-a-patch.png +Content-Type: image/png +Content-Transfer-Encoding: base64 + +iVBORw0KGgoAAAANSUhEUgAAAjMAAAAfCAYAAAASo0ymAAABfGlDQ1BJQ0MgUHJvZmlsZQAAKJFj +YGAqSSwoyGFhYGDIzSspCnJ3UoiIjFJgv8PAzcDDIMRgxSCemFxc4BgQ4MOAE3y7xsAIoi/rgsxK +8/x506a1fP4WNq+ZclYlOrj1gQF3SmpxMgMDIweQnZxSnJwLZOcA2TrJBUUlQPYMIFu3vKQAxD4B +ZIsUAR0IZN8BsdMh7A8gdhKYzcQCVhMS5AxkSwDZAkkQt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/emails/merge_request_with_conflicting_patch.eml b/spec/fixtures/emails/merge_request_with_conflicting_patch.eml new file mode 100644 index 00000000000..ddfdfe9e24a --- /dev/null +++ b/spec/fixtures/emails/merge_request_with_conflicting_patch.eml @@ -0,0 +1,45 @@ +From: "Jake the Dog" <jake@adventuretime.ooo> +To: incoming+gitlabhq/gitlabhq+merge-request+auth_token@appmail.adventuretime.ooo +Subject: feature +Date: Wed, 31 Oct 2018 17:27:52 +0100 +X-Mailer: MailMate (1.12r5523) +Message-ID: <7BE7C2E6-F0D9-4C85-9F55-B2A4BA01BFEC@gitlab.com> +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_=" + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= + +This does not apply + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= +Content-Disposition: attachment; + filename=0002-This-does-not-apply-to-the-feature-branch.patch +Content-Transfer-Encoding: quoted-printable + +=46rom 00c68c2b4f954370ce82a1162bc29c13f524897e Mon Sep 17 00:00:00 2001 +From: Patch user <patchuser@gitlab.org> +Date: Mon, 22 Oct 2018 11:05:48 +0200 +Subject: [PATCH] This does not apply to the `feature` branch + +--- + files/ruby/feature.rb | 5 +++++ + 1 file changed, 5 insertions(+) + create mode 100644 files/ruby/feature.rb + +diff --git a/files/ruby/feature.rb b/files/ruby/feature.rb +new file mode 100644 +index 0000000..fef26e4 +--- /dev/null ++++ b/files/ruby/feature.rb +@@ -0,0 +1,5 @@ ++class Feature ++ def bar ++ puts 'foo' ++ end ++end +-- = + +2.19.1 + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_=-- diff --git a/spec/fixtures/emails/merge_request_with_patch_and_target_branch.eml b/spec/fixtures/emails/merge_request_with_patch_and_target_branch.eml new file mode 100644 index 00000000000..965658721cd --- /dev/null +++ b/spec/fixtures/emails/merge_request_with_patch_and_target_branch.eml @@ -0,0 +1,44 @@ +From: "Jake the Dog" <jake@adventuretime.ooo> +To: incoming+gitlabhq/gitlabhq+merge-request+auth_token@appmail.adventuretime.ooo +Subject: new-branch-with-a-patch +Date: Wed, 24 Oct 2018 16:39:49 +0200 +X-Mailer: MailMate (1.12r5523) +Message-ID: <F1F36291-728D-4E8F-AFEB-C398B8D9BB4E@gitlab.com> +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_=" + + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= + +This applies nicely to a branch freshly created from the root-ref + +The other attachments in this email are ignored + +/target_branch with-codeowners + + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= +Content-Disposition: attachment; filename=0001-A-commit-from-a-patch.patch +Content-Transfer-Encoding: quoted-printable + +=46rom 3fee0042e610fb3563e4379e316704cb1210f3de Mon Sep 17 00:00:00 2001 +From: Patch user <patchuser@gitlab.org> +Date: Thu, 18 Oct 2018 13:40:35 +0200 +Subject: [PATCH] A commit from a patch + +--- + README | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/README b/README +index 3742e48..e40a3b9 100644 +--- a/README ++++ b/README +@@ -1 +1,3 @@ + Sample repo for testing gitlab features ++ ++This was applied in a patch! +-- = + +2.19.1 diff --git a/spec/fixtures/emails/valid_merge_request_with_patch.eml b/spec/fixtures/emails/valid_merge_request_with_patch.eml new file mode 100644 index 00000000000..143fa77d1fa --- /dev/null +++ b/spec/fixtures/emails/valid_merge_request_with_patch.eml @@ -0,0 +1,151 @@ +From: "Jake the Dog" <jake@adventuretime.ooo> +To: incoming+gitlabhq/gitlabhq+merge-request+auth_token@appmail.adventuretime.ooo +Subject: new-branch-with-a-patch +Date: Wed, 24 Oct 2018 16:39:49 +0200 +X-Mailer: MailMate (1.12r5523) +Message-ID: <F1F36291-728D-4E8F-AFEB-C398B8D9BB4E@gitlab.com> +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_=" + + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= + +This applies nicely to a branch freshly created from the root-ref + +The other attachments in this email are ignored + + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= +Content-Disposition: attachment; filename=0001-A-commit-from-a-patch.patch +Content-Transfer-Encoding: quoted-printable + +=46rom 3fee0042e610fb3563e4379e316704cb1210f3de Mon Sep 17 00:00:00 2001 +From: Patch user <patchuser@gitlab.org> +Date: Thu, 18 Oct 2018 13:40:35 +0200 +Subject: [PATCH] A commit from a patch + +--- + README | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/README b/README +index 3742e48..e40a3b9 100644 +--- a/README ++++ b/README +@@ -1 +1,3 @@ + Sample repo for testing gitlab features ++ ++This was applied in a patch! +-- = + +2.19.1 + + +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_= +Content-Disposition: attachment; filename=really-not-a-patch.png +Content-Type: image/png +Content-Transfer-Encoding: base64 + +iVBORw0KGgoAAAANSUhEUgAAAjMAAAAfCAYAAAASo0ymAAABfGlDQ1BJQ0MgUHJvZmlsZQAAKJFj +YGAqSSwoyGFhYGDIzSspCnJ3UoiIjFJgv8PAzcDDIMRgxSCemFxc4BgQ4MOAE3y7xsAIoi/rgsxK +8/x506a1fP4WNq+ZclYlOrj1gQF3SmpxMgMDIweQnZxSnJwLZOcA2TrJBUUlQPYMIFu3vKQAxD4B +ZIsUAR0IZN8BsdMh7A8gdhKYzcQCVhMS5AxkSwDZAkkQtgaInQ5hW4DYyRmJKUC2B8guiBvAgNPD +RcHcwFLXkYC7SQa5OaUwO0ChxZOaFxoMcgcQyzB4MLgwKDCYMxgwWDLoMjiWpFaUgBQ65xdUFmWm +Z5QoOAJDNlXBOT+3oLQktUhHwTMvWU9HwcjA0ACkDhRnEKM/B4FNZxQ7jxDLX8jAYKnMwMDcgx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yDVcEmrMnc +iV1fbG5THhqDaU887Nxmv26w1YdTMOOKXvxY/bWbZcTwKSkoyBRiPh4TnnyknbXs8gLDhWayI2nu +Msy4uw4FdM3aVUkmmkORQcmMsLDGAWu5IMfVq6usVztx5kJMOruIHnjy8GXZUMxOFrqKtC7KfrC2 +N1b72OuNzQ9Wfqz3Lc32Ob6kLSQzkarzG9l8ci/10KW6G39339nU7D645l4i0Ns2WCy36UuoNljv +BcFkivCSSOltR0fppcze0kTdb9T3Rf/Ce5p8fHrQysOKxkZ7b4zR5J/Oqu1vY8UOA5Z+thRx5EvT +PRvN+aC30IRrZLtFP71y0VZLI+gNfhho+NJIyR119AV40d8PS2Oj+GhgECbKeWQXYJd0Es/qB3vc +E+uGJqpcA4KDDAj3CKfj2q9O2GRiWPyVFVdd1VueqkJNBVjjgLWcJuWdurC+9aY/P//tiwj3fwqJ +UIWdNJnp1NHFjfNAwJ7MAG9mvgvpzVAPxfguToAT4AQ4AU7ASUCvZIZ9mMmpmq9wAu0J3Gu1z9Bk +famovQS+hxPgBDgBToAT8I0A75nxjRs/y42ApaEGV24Go08CfYzP7Rjf5AQ4AU6AE+AEPBHQq2fG +YzLjSSHfxwlwApwAJ8AJcAKcQGck8IvOaBS3iRPgBDgBToAT4AQ4AVYCPJlhJcXLcQKcACfACXAC +nECnJMCTmU5ZLdwoToAT4AQ4AU6AE2AlwJMZVlK8HCfACXACnAAnwAl0SgI8memU1cKN4gQ4AU6A +E+AEOAFWAv8PxvdR0yK8jugAAAAASUVORK5CYII= +--=_MailMate_D2C4B06A-4F8D-4AAB-B247-C507E35AAED6_=-- diff --git a/spec/fixtures/patchfiles/0001-A-commit-from-a-patch.patch b/spec/fixtures/patchfiles/0001-A-commit-from-a-patch.patch new file mode 100644 index 00000000000..cc38682a0ab --- /dev/null +++ b/spec/fixtures/patchfiles/0001-A-commit-from-a-patch.patch @@ -0,0 +1,19 @@ +From 3fee0042e610fb3563e4379e316704cb1210f3de Mon Sep 17 00:00:00 2001 +From: Patch User <patchuser@gitlab.org> +Date: Thu, 18 Oct 2018 13:40:35 +0200 +Subject: [PATCH] A commit from a patch + +--- + README | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/README b/README +index 3742e48..e40a3b9 100644 +--- a/README ++++ b/README +@@ -1 +1,3 @@ + Sample repo for testing gitlab features ++ ++This was applied in a patch! +-- +2.19.1 diff --git a/spec/fixtures/patchfiles/0001-This-does-not-apply-to-the-feature-branch.patch b/spec/fixtures/patchfiles/0001-This-does-not-apply-to-the-feature-branch.patch new file mode 100644 index 00000000000..905002ae898 --- /dev/null +++ b/spec/fixtures/patchfiles/0001-This-does-not-apply-to-the-feature-branch.patch @@ -0,0 +1,23 @@ +From 00c68c2b4f954370ce82a1162bc29c13f524897e Mon Sep 17 00:00:00 2001 +From: Patch User <patchuser@gitlab.org> +Date: Mon, 22 Oct 2018 11:05:48 +0200 +Subject: [PATCH] This does not apply to the `feature` branch + +--- + files/ruby/feature.rb | 5 +++++ + 1 file changed, 5 insertions(+) + create mode 100644 files/ruby/feature.rb + +diff --git a/files/ruby/feature.rb b/files/ruby/feature.rb +new file mode 100644 +index 0000000..fef26e4 +--- /dev/null ++++ b/files/ruby/feature.rb +@@ -0,0 +1,5 @@ ++class Feature ++ def bar ++ puts 'foo' ++ end ++end +-- +2.19.1 diff --git a/spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb b/spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb index ace3104f36f..f276f1a8ddf 100644 --- a/spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb @@ -93,5 +93,74 @@ describe Gitlab::Email::Handler::CreateMergeRequestHandler do end end end + + context 'when the email contains patch attachments' do + let(:email_raw) { fixture_file("emails/valid_merge_request_with_patch.eml") } + + it 'creates the source branch and applies the patches' do + receiver.execute + + branch = project.repository.find_branch('new-branch-with-a-patch') + + expect(branch).not_to be_nil + expect(branch.dereferenced_target.message).to include('A commit from a patch') + end + + it 'creates the merge request' do + expect { receiver.execute } + .to change { project.merge_requests.where(source_branch: 'new-branch-with-a-patch').size }.by(1) + end + + it 'does not mention the patches in the created merge request' do + receiver.execute + + merge_request = project.merge_requests.find_by!(source_branch: 'new-branch-with-a-patch') + + expect(merge_request.description).not_to include('0001-A-commit-from-a-patch.patch') + end + + context 'when the patch could not be applied' do + let(:email_raw) { fixture_file("emails/merge_request_with_conflicting_patch.eml") } + + it 'raises an error' do + expect { receiver.execute }.to raise_error(Gitlab::Email::InvalidAttachment) + end + end + + context 'when specifying the target branch using quick actions' do + let(:email_raw) { fixture_file('emails/merge_request_with_patch_and_target_branch.eml') } + + it 'creates the merge request with the correct target branch' do + receiver.execute + + merge_request = project.merge_requests.find_by!(source_branch: 'new-branch-with-a-patch') + + expect(merge_request.target_branch).to eq('with-codeowners') + end + + it 'based the merge request of the target_branch' do + receiver.execute + + merge_request = project.merge_requests.find_by!(source_branch: 'new-branch-with-a-patch') + + expect(merge_request.diff_base_commit).to eq(project.repository.commit('with-codeowners')) + end + end + end + end + + describe '#patch_attachments' do + let(:email_raw) { fixture_file('emails/merge_request_multiple_patches.eml') } + let(:mail) { Mail::Message.new(email_raw) } + subject(:handler) { described_class.new(mail, mail_key) } + + it 'orders attachments ending in `.patch` by name' do + expected_filenames = ["0001-A-commit-from-a-patch.patch", + "0002-This-does-not-apply-to-the-feature-branch.patch"] + + attachments = handler.__send__(:patch_attachments).map(&:filename) + + expect(attachments).to eq(expected_filenames) + end end end diff --git a/spec/lib/gitlab/git/patches/collection_spec.rb b/spec/lib/gitlab/git/patches/collection_spec.rb new file mode 100644 index 00000000000..080be141c59 --- /dev/null +++ b/spec/lib/gitlab/git/patches/collection_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe Gitlab::Git::Patches::Collection do + let(:patches_folder) { Rails.root.join('spec/fixtures/patchfiles') } + let(:patch_content1) do + File.read(File.join(patches_folder, "0001-This-does-not-apply-to-the-feature-branch.patch")) + end + let(:patch_content2) do + File.read(File.join(patches_folder, "0001-A-commit-from-a-patch.patch")) + end + + subject(:collection) { described_class.new([patch_content1, patch_content2]) } + + describe '#size' do + it 'combines the size of the patches' do + expect(collection.size).to eq(549.bytes + 424.bytes) + end + end + + describe '#valid_size?' do + it 'is not valid if the total size is bigger than 2MB' do + expect(collection).to receive(:size).and_return(2500.kilobytes) + + expect(collection).not_to be_valid_size + end + end +end diff --git a/spec/lib/gitlab/git/patches/commit_patches_spec.rb b/spec/lib/gitlab/git/patches/commit_patches_spec.rb new file mode 100644 index 00000000000..760112155ce --- /dev/null +++ b/spec/lib/gitlab/git/patches/commit_patches_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe Gitlab::Git::Patches::CommitPatches do + describe '#commit' do + let(:patches) do + patches_folder = Rails.root.join('spec/fixtures/patchfiles') + content_1 = File.read(File.join(patches_folder, "0001-This-does-not-apply-to-the-feature-branch.patch")) + content_2 = File.read(File.join(patches_folder, "0001-A-commit-from-a-patch.patch")) + + Gitlab::Git::Patches::Collection.new([content_1, content_2]) + end + let(:user) { build(:user) } + let(:branch_name) { 'branch-with-patches' } + let(:repository) { create(:project, :repository).repository } + + subject(:commit_patches) do + described_class.new(user, repository, branch_name, patches) + end + + it 'applies the patches' do + new_rev = commit_patches.commit + + expect(repository.commit(new_rev)).not_to be_nil + end + + it 'updates the branch cache' do + expect(repository).to receive(:after_create_branch) + + commit_patches.commit + end + + context 'when the repository does not exist' do + let(:repository) { create(:project).repository } + + it 'raises the correct error' do + expect { commit_patches.commit }.to raise_error(Gitlab::Git::Repository::NoRepository) + end + end + + context 'when the patch does not apply' do + let(:branch_name) { 'feature' } + + it 'raises the correct error' do + expect { commit_patches.commit }.to raise_error(Gitlab::Git::CommandError) + end + end + end +end diff --git a/spec/lib/gitlab/git/patches/patch_spec.rb b/spec/lib/gitlab/git/patches/patch_spec.rb new file mode 100644 index 00000000000..7466e853b65 --- /dev/null +++ b/spec/lib/gitlab/git/patches/patch_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe Gitlab::Git::Patches::Patch do + let(:patches_folder) { Rails.root.join('spec/fixtures/patchfiles') } + let(:patch_content) do + File.read(File.join(patches_folder, "0001-This-does-not-apply-to-the-feature-branch.patch")) + end + let(:patch) { described_class.new(patch_content) } + + describe '#size' do + it 'is correct' do + expect(patch.size).to eq(549.bytes) + end + end +end diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb index eaf64e3c9b4..b37fe2686b6 100644 --- a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb @@ -335,4 +335,37 @@ describe Gitlab::GitalyClient::OperationService do end end end + + describe '#user_commit_patches' do + let(:patches_folder) { Rails.root.join('spec/fixtures/patchfiles') } + let(:patch_content) do + patch_names.map { |name| File.read(File.join(patches_folder, name)) }.join("\n") + end + let(:patch_names) { %w(0001-This-does-not-apply-to-the-feature-branch.patch) } + let(:branch_name) { 'branch-with-patches' } + + subject(:commit_patches) do + client.user_commit_patches(user, branch_name, patch_content) + end + + it 'applies the patch correctly' do + branch_update = commit_patches + + expect(branch_update).to be_branch_created + + commit = repository.commit(branch_update.newrev) + expect(commit.author_email).to eq('patchuser@gitlab.org') + expect(commit.committer_email).to eq(user.email) + expect(commit.message.chomp).to eq('This does not apply to the `feature` branch') + end + + context 'when the patch could not be applied' do + let(:patch_names) { %w(0001-This-does-not-apply-to-the-feature-branch.patch) } + let(:branch_name) { 'feature' } + + it 'raises the correct error' do + expect { commit_patches }.to raise_error(GRPC::FailedPrecondition) + end + end + end end diff --git a/spec/services/commits/commit_patch_service_spec.rb b/spec/services/commits/commit_patch_service_spec.rb new file mode 100644 index 00000000000..f4fcec2fbc2 --- /dev/null +++ b/spec/services/commits/commit_patch_service_spec.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe Commits::CommitPatchService do + describe '#execute' do + let(:patches) do + patches_folder = Rails.root.join('spec/fixtures/patchfiles') + content_1 = File.read(File.join(patches_folder, "0001-This-does-not-apply-to-the-feature-branch.patch")) + content_2 = File.read(File.join(patches_folder, "0001-A-commit-from-a-patch.patch")) + + [content_1, content_2] + end + let(:user) { project.creator } + let(:branch_name) { 'branch-with-patches' } + let(:project) { create(:project, :repository) } + let(:start_branch) { nil } + let(:params) { { branch_name: branch_name, patches: patches, start_branch: start_branch } } + + subject(:service) do + described_class.new(project, user, params) + end + + it 'returns a successful result' do + result = service.execute + + branch = project.repository.find_branch(branch_name) + + expect(result[:status]).to eq(:success) + expect(result[:result]).to eq(branch.target) + end + + it 'is based off HEAD when no start ref is passed' do + service.execute + + merge_base = project.repository.merge_base(project.repository.root_ref, branch_name) + + expect(merge_base).to eq(project.repository.commit('HEAD').sha) + end + + context 'when specifying a different start branch' do + let(:start_branch) { 'with-codeowners' } + + it 'is based of the correct branch' do + service.execute + + merge_base = project.repository.merge_base(start_branch, branch_name) + + expect(merge_base).to eq(project.repository.commit(start_branch).sha) + end + end + + shared_examples 'an error response' do |expected_message| + it 'returns the correct error' do + result = service.execute + + expect(result[:status]).to eq(:error) + expect(result[:message]).to match(expected_message) + end + end + + context 'when the user does not have access' do + let(:user) { create(:user) } + + it_behaves_like 'an error response', + 'You are not allowed to push into this branch' + end + + context 'when the patches are not valid' do + let(:patches) { "a" * 2.1.megabytes } + + it_behaves_like 'an error response', 'Patches are too big' + end + + context 'when the new branch name is invalid' do + let(:branch_name) { 'HEAD' } + + it_behaves_like 'an error response', 'Branch name is invalid' + end + + context 'when the patches do not apply' do + let(:branch_name) { 'feature' } + + it_behaves_like 'an error response', 'Patch failed at' + end + + context 'when specifying a non existent start branch' do + let(:start_branch) { 'does-not-exist' } + + it_behaves_like 'an error response', 'Invalid reference name' + end + end +end diff --git a/spec/services/merge_requests/build_service_spec.rb b/spec/services/merge_requests/build_service_spec.rb index 9f1da7d9419..c9a668994eb 100644 --- a/spec/services/merge_requests/build_service_spec.rb +++ b/spec/services/merge_requests/build_service_spec.rb @@ -392,5 +392,13 @@ describe MergeRequests::BuildService do expect(merge_request.source_project).to eq(project) end end + + context 'when specifying target branch in the description' do + let(:description) { "A merge request targeting another branch\n\n/target_branch with-codeowners" } + + it 'sets the attribute from the quick actions' do + expect(merge_request.target_branch).to eq('with-codeowners') + end + end end end diff --git a/spec/workers/email_receiver_worker_spec.rb b/spec/workers/email_receiver_worker_spec.rb index e4e77c667b3..045135255d6 100644 --- a/spec/workers/email_receiver_worker_spec.rb +++ b/spec/workers/email_receiver_worker_spec.rb @@ -46,6 +46,21 @@ describe EmailReceiverWorker, :mailer do should_not_email_anyone end end + + context 'when the error is Gitlab::Email::InvalidAttachment' do + let(:error) { Gitlab::Email::InvalidAttachment.new("Could not deal with that") } + + it 'reports the error to the sender' do + perform_enqueued_jobs do + described_class.new.perform(raw_message) + end + + email = ActionMailer::Base.deliveries.last + expect(email).not_to be_nil + expect(email.to).to eq(["jake@adventuretime.ooo"]) + expect(email.body.parts.last.to_s).to include("Could not deal with that") + end + end end end |