#34: added support of hooks for issues.

This commit is contained in:
Vokhmin Alexey V 2013-04-15 21:51:19 +04:00
parent f12ad1e3f4
commit 30ab1396af
3 changed files with 42 additions and 2 deletions

View File

@ -41,8 +41,8 @@ class ActivityFeedObserver < ActiveRecord::Observer
:project_id => record.project.id, :issue_title => record.title, :project_name => record.project.name, :project_owner => record.project.owner.uname}
)
end
record.project.hooks.each{ |h| h.issue_hook(record) }
Comment.create_link_on_issues_from_item(record)
when 'Comment'
return if record.automatic
if record.issue_comment?
@ -146,6 +146,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
:project_id => record.project.id, :project_name => record.project.name, :project_owner => record.project.owner.uname}
)
end
record.project.hooks.each{ |h| h.issue_hook(record) } if record.status_changed?
# dont remove outdated issues link
Comment.create_link_on_issues_from_item(record)
when 'BuildList'

View File

@ -12,8 +12,43 @@ class Hook < ActiveRecord::Base
scope :for_name, lambda {|name| where(:name => name) if name.present? }
def issue_hook(issue)
params = {
'data' => data.to_json,
'payload' => meta(issue.project, issue.user).merge(
:action => (issue.closed? ? 'closed' : 'opened'),
:issue => {
:number => issue.serial_id,
:state => issue.status,
:title => issue.title,
:body => issue.body,
:user => {:login => issue.user.uname},
:html_url => "#{issue.project.html_url}/issues/#{issue.serial_id}"
}
).to_json
}
uri = URI "http://127.0.0.1:8080/#{name}/issues"
begin
res = Net::HTTP.post_form(uri, params)
rescue # Dont care about it
end
end
later :issue_hook, :queue => :clone_build
protected
def meta(project, user)
{
:repository => {
:name => project.name,
:url => project.html_url,
:owner => { :login => project.owner.uname }
},
:sender => {:login => user.uname}
}
end
def cleanup_data
if self.name.present? && fields = SCHEMA[self.name.to_sym]
new_data = {}

View File

@ -128,7 +128,7 @@ class Project < ActiveRecord::Base
host ||= EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host]
protocol = APP_CONFIG['mailer_https_url'] ? "https" : "http" rescue "http"
opts = {:host => host, :protocol => protocol}
opts.merge!({:user => auth_user.authentication_token, :password => ''}) unless self.public?
opts.merge!({:user => auth_user.authentication_token, :password => ''}) if auth_user && !self.public?
Rails.application.routes.url_helpers.project_url(self.owner.uname, self.name, opts) + ".git"
#path #share by NFS
end
@ -228,6 +228,10 @@ class Project < ActiveRecord::Base
@archive ||= create_archive treeish, format
end
def html_url
git_project_address(nil).gsub(/.git$/, '')
end
protected
def create_archive(treeish, format)