Añade plugin Redmine Git Hosting 4.0.2
This commit is contained in:
parent
472cb1ea76
commit
bdd66d941f
494 changed files with 36768 additions and 0 deletions
2
plugins/redmine_git_hosting/lib/hrack/init.rb
Normal file
2
plugins/redmine_git_hosting/lib/hrack/init.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
||||
require 'hrack'
|
3
plugins/redmine_git_hosting/lib/hrack/lib/hrack.rb
Normal file
3
plugins/redmine_git_hosting/lib/hrack/lib/hrack.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
module Hrack
|
||||
require 'hrack/bundle'
|
||||
end
|
16
plugins/redmine_git_hosting/lib/hrack/lib/hrack/bundle.rb
Normal file
16
plugins/redmine_git_hosting/lib/hrack/lib/hrack/bundle.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'rack/builder'
|
||||
require 'rack/parser'
|
||||
require 'hrack/server'
|
||||
|
||||
module Hrack
|
||||
module Bundle
|
||||
module_function
|
||||
|
||||
def new(config)
|
||||
Rack::Builder.new do
|
||||
use Rack::Parser
|
||||
run Hrack::Server.new(config)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
142
plugins/redmine_git_hosting/lib/hrack/lib/hrack/server.rb
Normal file
142
plugins/redmine_git_hosting/lib/hrack/lib/hrack/server.rb
Normal file
|
@ -0,0 +1,142 @@
|
|||
require 'digest/sha1'
|
||||
|
||||
module Hrack
|
||||
class Server
|
||||
|
||||
attr_reader :params
|
||||
|
||||
PLAIN_TYPE = { 'Content-Type' => 'text/plain' }
|
||||
|
||||
|
||||
def initialize(config = {})
|
||||
end
|
||||
|
||||
|
||||
def call(env)
|
||||
dup._call(env)
|
||||
end
|
||||
|
||||
|
||||
def _call(env)
|
||||
@env = env
|
||||
@req = Rack::Request.new(env)
|
||||
@params = @req.params.deep_symbolize_keys
|
||||
|
||||
command, @project = match_routing
|
||||
|
||||
return render_404('Command Not Found') if !command
|
||||
return render_404('Project Not Found') if !@project
|
||||
|
||||
self.method(command).call()
|
||||
end
|
||||
|
||||
|
||||
def post_receive_redmine
|
||||
@repository = find_repository
|
||||
return render_404('Repository Not Found') if @repository.nil?
|
||||
return render_403('The hook key provided is not valid. Please let your server admin know about it') if !valid_encoded_time?(params[:clear_time], params[:encoded_time], @repository.gitolite_hook_key)
|
||||
|
||||
@res = Rack::Response.new
|
||||
@res.status = 200
|
||||
@res['Content-Type'] = 'text/plain;'
|
||||
@res.finish do
|
||||
@res.write Repositories::ExecuteHooks.call(@repository, :fetch_changesets)
|
||||
@res.write Repositories::ExecuteHooks.call(@repository, :update_mirrors, payloads)
|
||||
@res.write Repositories::ExecuteHooks.call(@repository, :call_webservices, payloads)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def post_receive_github
|
||||
Projects::ExecuteHooks.call(@project, :github, params)
|
||||
render_200('OK!')
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def payloads
|
||||
@payloads ||= Repositories::BuildPayload.call(@repository, params[:refs])
|
||||
end
|
||||
|
||||
|
||||
def match_routing
|
||||
command = find_command
|
||||
project = find_project
|
||||
return command, project
|
||||
end
|
||||
|
||||
|
||||
def find_command
|
||||
return nil if !path_parameters.has_key?(:type)
|
||||
case path_parameters[:type]
|
||||
when 'redmine'
|
||||
:post_receive_redmine
|
||||
when 'github'
|
||||
:post_receive_github
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def find_project
|
||||
if path_parameters.has_key?(:projectid)
|
||||
Project.find_by_identifier(path_parameters[:projectid])
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Locate that actual repository that is in use here.
|
||||
# Notice that an empty "repositoryid" is assumed to refer to the default repo for a project
|
||||
def find_repository
|
||||
if params[:repositoryid] && !params[:repositoryid].blank?
|
||||
@project.repositories.find_by_identifier(params[:repositoryid])
|
||||
else
|
||||
# return default or first repo with blank identifier
|
||||
@project.repository || @project.repo_blank_ident
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def render_200(message)
|
||||
[200, PLAIN_TYPE, [message]]
|
||||
end
|
||||
|
||||
|
||||
def render_404(message)
|
||||
[404, PLAIN_TYPE, [message]]
|
||||
end
|
||||
|
||||
|
||||
def render_403(message)
|
||||
[403, PLAIN_TYPE, [message]]
|
||||
end
|
||||
|
||||
|
||||
def path_parameters
|
||||
@env['action_dispatch.request.path_parameters']
|
||||
end
|
||||
|
||||
|
||||
def valid_encoded_time?(clear_time, encoded_time, key)
|
||||
cur_time = Time.new.utc.to_i
|
||||
test_time = clear_time.to_i
|
||||
not_to_late?(cur_time, test_time) && encode_key(clear_time, key) == encoded_time.to_s
|
||||
end
|
||||
|
||||
|
||||
def not_to_late?(cur_time, test_time)
|
||||
cur_time - test_time < 5 * 60
|
||||
end
|
||||
|
||||
|
||||
def encode_key(time, key)
|
||||
Digest::SHA1.hexdigest(time.to_s + key.to_s).to_s
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
module Hrack
|
||||
VERSION = '1.0.0'
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue