Commit f9fb7667 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #8603 from jubianchi/hook-merge-request-action

Add action property to merge request hook
parents 0af2a161 4ffdb83e
...@@ -42,7 +42,7 @@ v 7.8.0 ...@@ -42,7 +42,7 @@ v 7.8.0
- -
- -
- -
- - Add action property to merge request hook (Julien Bianchi)
- -
- -
- -
......
...@@ -5,9 +5,12 @@ module MergeRequests ...@@ -5,9 +5,12 @@ module MergeRequests
Note.create_status_change_note(merge_request, merge_request.target_project, current_user, merge_request.state, nil) Note.create_status_change_note(merge_request, merge_request.target_project, current_user, merge_request.state, nil)
end end
def execute_hooks(merge_request) def execute_hooks(merge_request, action = 'open')
if merge_request.project if merge_request.project
hook_data = merge_request.to_hook_data(current_user) hook_data = merge_request.to_hook_data(current_user)
merge_request_url = Gitlab::UrlBuilder.new(:merge_request).build(merge_request.id)
hook_data[:object_attributes][:url] = merge_request_url
hook_data[:object_attributes][:action] = action
merge_request.project.execute_hooks(hook_data, :merge_request_hooks) merge_request.project.execute_hooks(hook_data, :merge_request_hooks)
end end
end end
......
...@@ -9,7 +9,7 @@ module MergeRequests ...@@ -9,7 +9,7 @@ module MergeRequests
event_service.close_mr(merge_request, current_user) event_service.close_mr(merge_request, current_user)
notification_service.close_mr(merge_request, current_user) notification_service.close_mr(merge_request, current_user)
create_note(merge_request) create_note(merge_request)
execute_hooks(merge_request) execute_hooks(merge_request, 'close')
end end
merge_request merge_request
......
...@@ -12,7 +12,7 @@ module MergeRequests ...@@ -12,7 +12,7 @@ module MergeRequests
notification_service.merge_mr(merge_request, current_user) notification_service.merge_mr(merge_request, current_user)
create_merge_event(merge_request, current_user) create_merge_event(merge_request, current_user)
create_note(merge_request) create_note(merge_request)
execute_hooks(merge_request) execute_hooks(merge_request, 'merge')
true true
rescue rescue
......
...@@ -5,7 +5,7 @@ module MergeRequests ...@@ -5,7 +5,7 @@ module MergeRequests
event_service.reopen_mr(merge_request, current_user) event_service.reopen_mr(merge_request, current_user)
notification_service.reopen_mr(merge_request, current_user) notification_service.reopen_mr(merge_request, current_user)
create_note(merge_request) create_note(merge_request)
execute_hooks(merge_request) execute_hooks(merge_request, 'reopen')
merge_request.reload_code merge_request.reload_code
merge_request.mark_as_unchecked merge_request.mark_as_unchecked
end end
......
...@@ -38,7 +38,7 @@ module MergeRequests ...@@ -38,7 +38,7 @@ module MergeRequests
end end
merge_request.notice_added_references(merge_request.project, current_user) merge_request.notice_added_references(merge_request.project, current_user)
execute_hooks(merge_request) execute_hooks(merge_request, 'update')
end end
merge_request merge_request
......
...@@ -166,7 +166,9 @@ Triggered when a new merge request is created or an existing merge request was u ...@@ -166,7 +166,9 @@ Triggered when a new merge request is created or an existing merge request was u
"name": "GitLab dev user", "name": "GitLab dev user",
"email": "gitlabdev@dv6700.(none)" "email": "gitlabdev@dv6700.(none)"
} }
} },
"url": "http://example.com/diaspora/merge_requests/1",
"action": "open"
} }
} }
``` ```
......
...@@ -12,14 +12,23 @@ describe MergeRequests::CloseService do ...@@ -12,14 +12,23 @@ describe MergeRequests::CloseService do
end end
describe :execute do describe :execute do
context "valid params" do context 'valid params' do
let(:service) { MergeRequests::CloseService.new(project, user, {}) }
before do before do
@merge_request = MergeRequests::CloseService.new(project, user, {}).execute(merge_request) service.stub(:execute_hooks)
@merge_request = service.execute(merge_request)
end end
it { @merge_request.should be_valid } it { @merge_request.should be_valid }
it { @merge_request.should be_closed } it { @merge_request.should be_closed }
it 'should execute hooks with close action' do
expect(service).to have_received(:execute_hooks).
with(@merge_request, 'close')
end
it 'should send email to user2 about assign of new merge_request' do it 'should send email to user2 about assign of new merge_request' do
email = ActionMailer::Base.deliveries.last email = ActionMailer::Base.deliveries.last
email.to.first.should == user2.email email.to.first.should == user2.email
...@@ -28,7 +37,7 @@ describe MergeRequests::CloseService do ...@@ -28,7 +37,7 @@ describe MergeRequests::CloseService do
it 'should create system note about merge_request reassign' do it 'should create system note about merge_request reassign' do
note = @merge_request.notes.last note = @merge_request.notes.last
note.note.should include "Status changed to closed" note.note.should include 'Status changed to closed'
end end
end end
end end
......
...@@ -5,21 +5,30 @@ describe MergeRequests::CreateService do ...@@ -5,21 +5,30 @@ describe MergeRequests::CreateService do
let(:user) { create(:user) } let(:user) { create(:user) }
describe :execute do describe :execute do
context "valid params" do context 'valid params' do
before do let(:opts) do
project.team << [user, :master] {
opts = {
title: 'Awesome merge_request', title: 'Awesome merge_request',
description: 'please fix', description: 'please fix',
source_branch: 'stable', source_branch: 'stable',
target_branch: 'master' target_branch: 'master'
} }
end
let(:service) { MergeRequests::CreateService.new(project, user, opts) }
before do
project.team << [user, :master]
service.stub(:execute_hooks)
@merge_request = MergeRequests::CreateService.new(project, user, opts).execute @merge_request = service.execute
end end
it { @merge_request.should be_valid } it { @merge_request.should be_valid }
it { @merge_request.title.should == 'Awesome merge_request' } it { @merge_request.title.should == 'Awesome merge_request' }
it 'should execute hooks with default action' do
expect(service).to have_received(:execute_hooks).with(@merge_request)
end
end end
end end
end end
require 'spec_helper'
describe MergeRequests::MergeService do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:merge_request) { create(:merge_request, assignee: user2) }
let(:project) { merge_request.project }
before do
project.team << [user, :master]
project.team << [user2, :developer]
end
describe :execute do
context 'valid params' do
let(:service) { MergeRequests::MergeService.new(project, user, {}) }
before do
service.stub(:execute_hooks)
service.execute(merge_request, 'Awesome message')
end
it { merge_request.should be_valid }
it { merge_request.should be_merged }
it 'should execute hooks with merge action' do
expect(service).to have_received(:execute_hooks).
with(merge_request, 'merge')
end
it 'should send email to user2 about merge of new merge_request' do
email = ActionMailer::Base.deliveries.last
email.to.first.should == user2.email
email.subject.should include(merge_request.title)
end
it 'should create system note about merge_request merge' do
note = merge_request.notes.last
note.note.should include 'Status changed to merged'
end
end
end
end
require 'spec_helper'
describe MergeRequests::ReopenService do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:merge_request) { create(:merge_request, assignee: user2) }
let(:project) { merge_request.project }
before do
project.team << [user, :master]
project.team << [user2, :developer]
end
describe :execute do
context 'valid params' do
let(:service) { MergeRequests::ReopenService.new(project, user, {}) }
before do
service.stub(:execute_hooks)
merge_request.state = :closed
service.execute(merge_request)
end
it { merge_request.should be_valid }
it { merge_request.should be_reopened }
it 'should execute hooks with reopen action' do
expect(service).to have_received(:execute_hooks).
with(merge_request, 'reopen')
end
it 'should send email to user2 about reopen of merge_request' do
email = ActionMailer::Base.deliveries.last
email.to.first.should == user2.email
email.subject.should include(merge_request.title)
end
it 'should create system note about merge_request reopen' do
note = merge_request.notes.last
note.note.should include 'Status changed to reopened'
end
end
end
end
...@@ -12,16 +12,21 @@ describe MergeRequests::UpdateService do ...@@ -12,16 +12,21 @@ describe MergeRequests::UpdateService do
end end
describe :execute do describe :execute do
context "valid params" do context 'valid params' do
before do let(:opts) do
opts = { {
title: 'New title', title: 'New title',
description: 'Also please fix', description: 'Also please fix',
assignee_id: user2.id, assignee_id: user2.id,
state_event: 'close' state_event: 'close'
} }
end
let(:service) { MergeRequests::UpdateService.new(project, user, opts) }
before do
service.stub(:execute_hooks)
@merge_request = MergeRequests::UpdateService.new(project, user, opts).execute(merge_request) @merge_request = service.execute(merge_request)
end end
it { @merge_request.should be_valid } it { @merge_request.should be_valid }
...@@ -29,6 +34,11 @@ describe MergeRequests::UpdateService do ...@@ -29,6 +34,11 @@ describe MergeRequests::UpdateService do
it { @merge_request.assignee.should == user2 } it { @merge_request.assignee.should == user2 }
it { @merge_request.should be_closed } it { @merge_request.should be_closed }
it 'should execute hooks with update action' do
expect(service).to have_received(:execute_hooks).
with(@merge_request, 'update')
end
it 'should send email to user2 about assign of new merge_request' do it 'should send email to user2 about assign of new merge_request' do
email = ActionMailer::Base.deliveries.last email = ActionMailer::Base.deliveries.last
email.to.first.should == user2.email email.to.first.should == user2.email
......
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