#34: revert some changes, created UrlHelper
This commit is contained in:
parent
994f400af0
commit
72b2b637d1
|
@ -431,7 +431,7 @@ class BuildList < ActiveRecord::Base
|
||||||
urpmi_list(nil, nil, false, save_to_repository.name)["#{build_for_platform.name}"]["#{arch.name}"]
|
urpmi_list(nil, nil, false, save_to_repository.name)["#{build_for_platform.name}"]["#{arch.name}"]
|
||||||
end
|
end
|
||||||
|
|
||||||
git_project_address = project.git_url user
|
git_project_address = project.git_project_address user
|
||||||
# git_project_address.gsub!(/^http:\/\/(0\.0\.0\.0|localhost)\:[\d]+/, 'https://abf.rosalinux.ru') unless Rails.env.production?
|
# git_project_address.gsub!(/^http:\/\/(0\.0\.0\.0|localhost)\:[\d]+/, 'https://abf.rosalinux.ru') unless Rails.env.production?
|
||||||
{
|
{
|
||||||
:id => id,
|
:id => id,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
class Hook < ActiveRecord::Base
|
class Hook < ActiveRecord::Base
|
||||||
include Modules::Models::WebHooks
|
include Modules::Models::WebHooks
|
||||||
|
include Modules::Models::UrlHelper
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
before_validation :cleanup_data
|
before_validation :cleanup_data
|
||||||
|
@ -15,6 +17,7 @@ class Hook < ActiveRecord::Base
|
||||||
def receive_issues(issue, action)
|
def receive_issues(issue, action)
|
||||||
pull = issue.pull_request
|
pull = issue.pull_request
|
||||||
return if action.to_sym == :create && pull
|
return if action.to_sym == :create && pull
|
||||||
|
default_url_options
|
||||||
|
|
||||||
payload = meta(issue.project, issue.user)
|
payload = meta(issue.project, issue.user)
|
||||||
base_params = {
|
base_params = {
|
||||||
|
@ -34,7 +37,7 @@ class Hook < ActiveRecord::Base
|
||||||
:commits => total_commits,
|
:commits => total_commits,
|
||||||
:head => {:label => "#{pull.from_project.owner.uname}:#{pull.from_ref}"},
|
:head => {:label => "#{pull.from_project.owner.uname}:#{pull.from_ref}"},
|
||||||
:base => {:label => "#{repo_owner}:#{pull.to_ref}"},
|
:base => {:label => "#{repo_owner}:#{pull.to_ref}"},
|
||||||
:html_url => "#{issue.project.html_url}/pull_requests/#{pull.serial_id}"
|
:html_url => project_pull_request_url(pull.to_project, pull)
|
||||||
)
|
)
|
||||||
).to_json
|
).to_json
|
||||||
}
|
}
|
||||||
|
@ -43,7 +46,7 @@ class Hook < ActiveRecord::Base
|
||||||
:payload => payload.merge(
|
:payload => payload.merge(
|
||||||
:action => (issue.closed? ? 'closed' : 'opened'),
|
:action => (issue.closed? ? 'closed' : 'opened'),
|
||||||
:issue => base_params.merge(
|
:issue => base_params.merge(
|
||||||
:html_url => "#{issue.project.html_url}/issues/#{issue.serial_id}"
|
:html_url => project_issue_url(issue.project, issue)
|
||||||
)
|
)
|
||||||
).to_json
|
).to_json
|
||||||
}
|
}
|
||||||
|
@ -52,6 +55,7 @@ class Hook < ActiveRecord::Base
|
||||||
later :receive_issues, :queue => :notification
|
later :receive_issues, :queue => :notification
|
||||||
|
|
||||||
def receive_push(git_hook)
|
def receive_push(git_hook)
|
||||||
|
default_url_options
|
||||||
project = Project.find(git_hook['project']['project']['id'])
|
project = Project.find(git_hook['project']['project']['id'])
|
||||||
user = User.find(git_hook['user']['user']['id'])
|
user = User.find(git_hook['user']['user']['id'])
|
||||||
payload = meta(project, user)
|
payload = meta(project, user)
|
||||||
|
@ -61,7 +65,7 @@ class Hook < ActiveRecord::Base
|
||||||
payload.merge!(:before => oldrev, :after => newrev)
|
payload.merge!(:before => oldrev, :after => newrev)
|
||||||
if %w(delete create).exclude? change_type
|
if %w(delete create).exclude? change_type
|
||||||
payload.merge!(
|
payload.merge!(
|
||||||
:compare => "#{project.html_url}/diff/#{oldrev[0..6]}...#{newrev[0..6]}"
|
:compare => diff_url(project, "#{oldrev[0..6]}...#{newrev[0..6]}")
|
||||||
)
|
)
|
||||||
if oldrev == newrev
|
if oldrev == newrev
|
||||||
commits = [project.repo.commit(newrev)]
|
commits = [project.repo.commit(newrev)]
|
||||||
|
@ -80,7 +84,7 @@ class Hook < ActiveRecord::Base
|
||||||
:id => commit.id,
|
:id => commit.id,
|
||||||
:message => commit.message,
|
:message => commit.message,
|
||||||
:distinct => true,
|
:distinct => true,
|
||||||
:url => "#{project.html_url}/commit/#{commit.id}",
|
:url => commit_url(project, commit),
|
||||||
:removed => files[:removed],
|
:removed => files[:removed],
|
||||||
:added => files[:added],
|
:added => files[:added],
|
||||||
:modified => files[:modified],
|
:modified => files[:modified],
|
||||||
|
@ -106,7 +110,7 @@ class Hook < ActiveRecord::Base
|
||||||
{
|
{
|
||||||
:repository => {
|
:repository => {
|
||||||
:name => project.name,
|
:name => project.name,
|
||||||
:url => project.html_url,
|
:url => project_url(project),
|
||||||
:owner => { :login => project.owner.uname }
|
:owner => { :login => project.owner.uname }
|
||||||
},
|
},
|
||||||
:sender => {:login => user.uname},
|
:sender => {:login => user.uname},
|
||||||
|
|
|
@ -80,6 +80,7 @@ class Project < ActiveRecord::Base
|
||||||
include Modules::Models::Owner
|
include Modules::Models::Owner
|
||||||
include Modules::Models::Git
|
include Modules::Models::Git
|
||||||
include Modules::Models::Wiki
|
include Modules::Models::Wiki
|
||||||
|
include Modules::Models::UrlHelper
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def find_by_owner_and_name(owner_name, project_name)
|
def find_by_owner_and_name(owner_name, project_name)
|
||||||
|
@ -138,20 +139,13 @@ class Project < ActiveRecord::Base
|
||||||
owner == user
|
owner == user
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_url(auth_user = nil)
|
def git_project_address auth_user
|
||||||
host ||= EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host]
|
opts = default_url_options
|
||||||
protocol = APP_CONFIG['mailer_https_url'] ? "https" : "http" rescue "http"
|
opts.merge!({:user => auth_user.authentication_token, :password => ''}) unless self.public?
|
||||||
opts = {:host => host, :protocol => protocol}
|
Rails.application.routes.url_helpers.project_url(self.owner.uname, self.name, opts) + '.git'
|
||||||
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)
|
|
||||||
#path #share by NFS
|
#path #share by NFS
|
||||||
end
|
end
|
||||||
|
|
||||||
def git_url(auth_user)
|
|
||||||
html_url(auth_user) + '.git'
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def build_for(platform, repository_id, user, arch = Arch.find_by_name('i586'), auto_publish = false, mass_build_id = nil, priority = 0)
|
def build_for(platform, repository_id, user, arch = Arch.find_by_name('i586'), auto_publish = false, mass_build_id = nil, priority = 0)
|
||||||
# Select main and project platform repository(contrib, non-free and etc)
|
# Select main and project platform repository(contrib, non-free and etc)
|
||||||
# If main does not exist, will connect only project platform repository
|
# If main does not exist, will connect only project platform repository
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
# -*- encoding : utf-8 -*-
|
||||||
|
module Modules::Models::UrlHelper
|
||||||
|
def default_url_options
|
||||||
|
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'
|
||||||
|
{:host => host, :protocol => protocol}
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue