Commit 478116f0 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '20061-emailsonpushworker-fails-on-new-branch-pushes' into 'master'

Fix emails on push for new and deleted branches

## What does this MR do?

Fix EmailsOnPushWorker when the push is either a new branch or a deleted branch.

## Are there points in the code the reviewer needs to double check?

Don't think so.

## Why was this MR needed? / What are the relevant issue numbers?

Closes #20061.

## Does this MR meet the acceptance criteria?

- ~~[CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added~~ (regression)
- ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~
- ~~API support added~~
- Tests
  - [x] Added for this feature/bug
  - [ ] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)


See merge request !5390
parent b6968355
...@@ -28,12 +28,12 @@ class EmailsOnPushWorker ...@@ -28,12 +28,12 @@ class EmailsOnPushWorker
:push :push
end end
merge_base_sha = project.merge_base_commit(before_sha, after_sha).try(:sha)
diff_refs = nil diff_refs = nil
compare = nil compare = nil
reverse_compare = false reverse_compare = false
if action == :push if action == :push
merge_base_sha = project.merge_base_commit(before_sha, after_sha).try(:sha)
compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha) compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha)
diff_refs = Gitlab::Diff::DiffRefs.new( diff_refs = Gitlab::Diff::DiffRefs.new(
......
...@@ -12,6 +12,42 @@ describe EmailsOnPushWorker do ...@@ -12,6 +12,42 @@ describe EmailsOnPushWorker do
subject { EmailsOnPushWorker.new } subject { EmailsOnPushWorker.new }
describe "#perform" do describe "#perform" do
context "when push is a new branch" do
let(:email) { ActionMailer::Base.deliveries.last }
before do
data_new_branch = data.stringify_keys.merge("before" => Gitlab::Git::BLANK_SHA)
subject.perform(project.id, recipients, data_new_branch)
end
it "sends a mail with the correct subject" do
expect(email.subject).to include("Pushed new branch")
end
it "sends the mail to the correct recipient" do
expect(email.to).to eq([user.email])
end
end
context "when push is a deleted branch" do
let(:email) { ActionMailer::Base.deliveries.last }
before do
data_deleted_branch = data.stringify_keys.merge("after" => Gitlab::Git::BLANK_SHA)
subject.perform(project.id, recipients, data_deleted_branch)
end
it "sends a mail with the correct subject" do
expect(email.subject).to include("Deleted branch")
end
it "sends the mail to the correct recipient" do
expect(email.to).to eq([user.email])
end
end
context "when there are no errors in sending" do context "when there are no errors in sending" do
let(:email) { ActionMailer::Base.deliveries.last } let(:email) { ActionMailer::Base.deliveries.last }
......
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