Merge pull request #7013 from jvanbaarsen/better-webhook-information

Return a little more information in Issue webhook
This commit is contained in:
Dmitriy Zaporozhets 2014-06-24 10:37:15 +03:00
commit aadef92f1d
7 changed files with 45 additions and 6 deletions

View file

@ -7,8 +7,11 @@ module Issues
Note.create_assignee_change_note(issue, issue.project, current_user, issue.assignee)
end
def execute_hooks(issue)
issue.project.execute_hooks(issue.to_hook_data, :issue_hooks)
def execute_hooks(issue, action = 'open')
issue_data = issue.to_hook_data
issue_url = Gitlab::UrlBuilder.new(:issue).build(issue.id)
issue_data[:object_attributes].merge!(url: issue_url, action: action)
issue.project.execute_hooks(issue_data, :issue_hooks)
end
def create_milestone_note(issue)

View file

@ -5,7 +5,7 @@ module Issues
notification_service.close_issue(issue, current_user)
event_service.close_issue(issue, current_user)
create_note(issue, commit)
execute_hooks(issue)
execute_hooks(issue, 'close')
end
issue

View file

@ -8,7 +8,7 @@ module Issues
notification_service.new_issue(issue, current_user)
event_service.open_issue(issue, current_user)
issue.create_cross_references!(issue.project, current_user)
execute_hooks(issue)
execute_hooks(issue, 'open')
end
issue

View file

@ -4,7 +4,7 @@ module Issues
if issue.reopen
event_service.reopen_issue(issue, current_user)
create_note(issue)
execute_hooks(issue)
execute_hooks(issue, 'reopen')
end
issue

View file

@ -23,7 +23,7 @@ module Issues
end
issue.notice_added_references(issue.project, current_user)
execute_hooks(issue)
execute_hooks(issue, 'update')
end
issue

25
lib/gitlab/url_builder.rb Normal file
View file

@ -0,0 +1,25 @@
module Gitlab
class UrlBuilder
include Rails.application.routes.url_helpers
def initialize(type)
@type = type
end
def build(id)
case @type
when :issue
issue_url(id)
end
end
private
def issue_url(id)
issue = Issue.find(id)
project_issue_url(id: issue.iid,
project_id: issue.project,
host: Settings.gitlab['url'])
end
end
end

View file

@ -0,0 +1,11 @@
require 'spec_helper'
describe Gitlab::UrlBuilder do
describe 'When asking for an issue' do
it 'returns the issue url' do
issue = create(:issue)
url = Gitlab::UrlBuilder.new(:issue).build(issue.id)
expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.to_param}/issues/#{issue.iid}"
end
end
end