Execute project hooks when issue or merge request created
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
25951b9146
commit
cfcf24dce5
|
@ -1,14 +1,14 @@
|
|||
class IssueObserver < BaseObserver
|
||||
def after_create(issue)
|
||||
notification.new_issue(issue, current_user)
|
||||
|
||||
issue.create_cross_references!(issue.project, current_user)
|
||||
execute_hooks(issue)
|
||||
end
|
||||
|
||||
def after_close(issue, transition)
|
||||
notification.close_issue(issue, current_user)
|
||||
|
||||
create_note(issue)
|
||||
execute_hooks(issue)
|
||||
end
|
||||
|
||||
def after_reopen(issue, transition)
|
||||
|
@ -29,4 +29,8 @@ class IssueObserver < BaseObserver
|
|||
def create_note(issue)
|
||||
Note.create_status_change_note(issue, issue.project, current_user, issue.state, current_commit)
|
||||
end
|
||||
|
||||
def execute_hooks(issue)
|
||||
issue.project.execute_hooks(issue.to_hook_data, :issue_hooks)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,15 +7,15 @@ class MergeRequestObserver < ActivityObserver
|
|||
end
|
||||
|
||||
notification.new_merge_request(merge_request, current_user)
|
||||
|
||||
merge_request.create_cross_references!(merge_request.project, current_user)
|
||||
execute_hooks(merge_request)
|
||||
end
|
||||
|
||||
def after_close(merge_request, transition)
|
||||
create_event(merge_request, Event::CLOSED)
|
||||
Note.create_status_change_note(merge_request, merge_request.target_project, current_user, merge_request.state, nil)
|
||||
|
||||
notification.close_mr(merge_request, current_user)
|
||||
create_note(merge_request)
|
||||
execute_hooks(merge_request)
|
||||
end
|
||||
|
||||
def after_merge(merge_request, transition)
|
||||
|
@ -31,11 +31,13 @@ class MergeRequestObserver < ActivityObserver
|
|||
action: Event::MERGED,
|
||||
author_id: merge_request.author_id_of_changes
|
||||
)
|
||||
|
||||
execute_hooks(merge_request)
|
||||
end
|
||||
|
||||
def after_reopen(merge_request, transition)
|
||||
create_event(merge_request, Event::REOPENED)
|
||||
Note.create_status_change_note(merge_request, merge_request.target_project, current_user, merge_request.state, nil)
|
||||
create_note(merge_request)
|
||||
end
|
||||
|
||||
def after_update(merge_request)
|
||||
|
@ -53,4 +55,15 @@ class MergeRequestObserver < ActivityObserver
|
|||
author_id: current_user.id
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Create merge request note with service comment like 'Status changed to closed'
|
||||
def create_note(merge_request)
|
||||
Note.create_status_change_note(merge_request, merge_request.target_project, current_user, merge_request.state, nil)
|
||||
end
|
||||
|
||||
def execute_hooks(merge_request)
|
||||
merge_request.project.execute_hooks(merge_request.to_hook_data, :merge_request_hooks)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ class GitPushService
|
|||
end
|
||||
|
||||
if push_to_branch?(ref)
|
||||
project.execute_hooks(@push_data.dup)
|
||||
project.execute_hooks(@push_data.dup, :push_hooks)
|
||||
project.execute_services(@push_data.dup)
|
||||
end
|
||||
|
||||
|
|
|
@ -74,38 +74,19 @@ describe GitPushService do
|
|||
end
|
||||
|
||||
describe "Web Hooks" do
|
||||
context "with web hooks" do
|
||||
before do
|
||||
@project_hook = create(:project_hook)
|
||||
@project_hook_2 = create(:project_hook)
|
||||
project.hooks << [@project_hook, @project_hook_2]
|
||||
|
||||
stub_request(:post, @project_hook.url)
|
||||
stub_request(:post, @project_hook_2.url)
|
||||
end
|
||||
|
||||
it "executes multiple web hook" do
|
||||
@project_hook.should_receive(:async_execute).once
|
||||
@project_hook_2.should_receive(:async_execute).once
|
||||
|
||||
service.execute(project, user, @oldrev, @newrev, @ref)
|
||||
end
|
||||
end
|
||||
|
||||
context "execute web hooks" do
|
||||
before do
|
||||
@project_hook = create(:project_hook)
|
||||
project.hooks << [@project_hook]
|
||||
stub_request(:post, @project_hook.url)
|
||||
end
|
||||
|
||||
it "when pushing a branch for the first time" do
|
||||
@project_hook.should_receive(:async_execute)
|
||||
project.should_receive(:execute_hooks)
|
||||
service.execute(project, user, @blankrev, 'newrev', 'refs/heads/master')
|
||||
end
|
||||
|
||||
it "when pushing new commits to existing branch" do
|
||||
project.should_receive(:execute_hooks)
|
||||
service.execute(project, user, 'oldrev', 'newrev', 'refs/heads/master')
|
||||
end
|
||||
|
||||
it "when pushing tags" do
|
||||
@project_hook.should_not_receive(:async_execute)
|
||||
project.should_not_receive(:execute_hooks)
|
||||
service.execute(project, user, 'newrev', 'newrev', 'refs/tags/v1.0.0')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue