Añade el plugin Redmine Git Hosting 5.0.0
This commit is contained in:
parent
cfa0d58b18
commit
a3bddad233
458 changed files with 30396 additions and 1 deletions
|
@ -0,0 +1,29 @@
|
|||
module Repositories
|
||||
class Base
|
||||
include RedmineGitHosting::GitoliteAccessor::Methods
|
||||
|
||||
attr_reader :repository, :options, :project
|
||||
|
||||
def initialize(repository, opts = {})
|
||||
@repository = repository
|
||||
@options = opts
|
||||
@project = repository.project
|
||||
end
|
||||
|
||||
class << self
|
||||
def call(repository, opts = {})
|
||||
new(repository, opts).call
|
||||
end
|
||||
end
|
||||
|
||||
def call
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def logger
|
||||
RedmineGitHosting.logger
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,83 @@
|
|||
module Repositories
|
||||
class BuildPayload < Base
|
||||
def initialize(*args)
|
||||
super
|
||||
@payloads = []
|
||||
end
|
||||
|
||||
def call
|
||||
build_payloads
|
||||
end
|
||||
|
||||
def refs
|
||||
options
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns an array of GitHub post-receive hook style hashes
|
||||
# http://help.github.com/post-receive-hooks/
|
||||
#
|
||||
def build_payloads
|
||||
refs.each do |ref|
|
||||
# Get revisions range
|
||||
range = get_revisions_from_ref(ref)
|
||||
next if range.nil?
|
||||
|
||||
@payloads << build_payload(ref, range)
|
||||
end
|
||||
@payloads
|
||||
end
|
||||
|
||||
def get_revisions_from_ref(ref)
|
||||
oldhead, newhead, refname = ref.split ','
|
||||
|
||||
# Only pay attention to branch updates
|
||||
return nil if !refname.match(/refs\/heads\//)
|
||||
|
||||
# Get branch name
|
||||
branch_name = refname.gsub('refs/heads/', '')
|
||||
|
||||
if newhead.match(/\A0{40}\z/)
|
||||
# Deleting a branch
|
||||
logger.info("Deleting branch '#{branch_name}'")
|
||||
range = nil
|
||||
elsif oldhead.match(/\A0{40}\z/)
|
||||
# Creating a branch
|
||||
logger.info("Creating branch '#{branch_name}'")
|
||||
range = newhead
|
||||
else
|
||||
range = "#{oldhead}..#{newhead}"
|
||||
end
|
||||
|
||||
range
|
||||
end
|
||||
|
||||
def build_payload(ref, range)
|
||||
revisions_in_range = get_revisions_in_range(range)
|
||||
logger.debug("Revisions in range : #{revisions_in_range.join(' ')}")
|
||||
|
||||
# Get refs
|
||||
oldhead, newhead, refname = ref.split ','
|
||||
|
||||
# Build payload hash
|
||||
repository.github_payload
|
||||
.merge({ before: oldhead, after: newhead, ref: refname, commits: build_commits_list(revisions_in_range) })
|
||||
end
|
||||
|
||||
def build_commits_list(revisions_in_range)
|
||||
commits_list = []
|
||||
revisions_in_range.each do |rev|
|
||||
changeset = repository.find_changeset_by_name(rev)
|
||||
next if changeset.nil?
|
||||
|
||||
commits_list << changeset.github_payload
|
||||
end
|
||||
commits_list
|
||||
end
|
||||
|
||||
def get_revisions_in_range(range)
|
||||
repository.rev_list(range, ['--reverse'])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,61 @@
|
|||
module Repositories
|
||||
class Create < Base
|
||||
def call
|
||||
set_repository_extra
|
||||
create_repository
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_repository_extra
|
||||
extra = repository.build_extra(default_extra_options)
|
||||
extra.save!
|
||||
end
|
||||
|
||||
def default_extra_options
|
||||
enable_git_annex? ? git_annex_repository_options : standard_repository_options
|
||||
end
|
||||
|
||||
def enable_git_annex?
|
||||
options[:enable_git_annex]
|
||||
end
|
||||
|
||||
def standard_repository_options
|
||||
{
|
||||
git_daemon: RedmineGitHosting::Config.gitolite_daemon_by_default?,
|
||||
git_notify: RedmineGitHosting::Config.gitolite_notify_by_default?,
|
||||
git_annex: false,
|
||||
default_branch: 'master',
|
||||
key: RedmineGitHosting::Utils::Crypto.generate_secret(64)
|
||||
}.merge(smart_http_options)
|
||||
end
|
||||
|
||||
def smart_http_options
|
||||
case RedmineGitHosting::Config.gitolite_http_by_default?
|
||||
when '1' # HTTPS only
|
||||
{ git_https: true }
|
||||
when '2' # HTTPS and HTTP
|
||||
{ git_http: true, git_https: true }
|
||||
when '3' # HTTP only
|
||||
{ git_http: true }
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
def git_annex_repository_options
|
||||
{
|
||||
git_http: 0,
|
||||
git_daemon: false,
|
||||
git_notify: false,
|
||||
git_annex: true,
|
||||
default_branch: 'git-annex',
|
||||
key: RedmineGitHosting::Utils::Crypto.generate_secret(64)
|
||||
}
|
||||
end
|
||||
|
||||
def create_repository
|
||||
gitolite_accessor.create_repository(repository, options)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,78 @@
|
|||
module Repositories
|
||||
class DownloadRevision
|
||||
attr_reader :repository, :revision, :format, :gitolite_repository_path, :commit_id, :content_type, :filename
|
||||
|
||||
def initialize(repository, revision, format)
|
||||
@repository = repository
|
||||
@revision = revision
|
||||
@format = format
|
||||
@gitolite_repository_path = repository.gitolite_repository_path
|
||||
|
||||
@valid_commit = false
|
||||
@commit_id = nil
|
||||
@content_type = ''
|
||||
@filename = ''
|
||||
|
||||
validate_revision
|
||||
fill_data
|
||||
end
|
||||
|
||||
def content
|
||||
repository.archive(commit_id, format)
|
||||
end
|
||||
|
||||
def valid_commit?
|
||||
@valid_commit
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_revision
|
||||
commit = nil
|
||||
|
||||
# is the revision a branch?
|
||||
repository.branches.each do |x|
|
||||
if x.to_s == revision
|
||||
commit = x.revision
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# is the revision a tag?
|
||||
if commit.nil?
|
||||
repository.tags.each do |x|
|
||||
if x == revision
|
||||
commit = repository.rev_list(revision).first
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# well, let check if this is a valid commit
|
||||
commit = revision if commit.nil?
|
||||
commit = repository.rev_parse(commit)
|
||||
|
||||
if commit == ''
|
||||
@valid_commit = false
|
||||
else
|
||||
@valid_commit = true
|
||||
@commit_id = commit
|
||||
end
|
||||
end
|
||||
|
||||
def fill_data
|
||||
case format
|
||||
when 'tar.gz'
|
||||
extension = 'tar.gz'
|
||||
@content_type = 'application/x-gzip'
|
||||
when 'zip'
|
||||
extension = 'zip'
|
||||
@content_type = 'application/x-zip'
|
||||
else
|
||||
extension = 'tar'
|
||||
@content_type = 'application/x-tar'
|
||||
end
|
||||
@filename = "#{repository.redmine_name}-#{revision}.#{extension}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,65 @@
|
|||
module Repositories
|
||||
class ExecuteHooks
|
||||
attr_reader :repository, :hook_type, :payloads
|
||||
|
||||
def initialize(repository, hook_type, payloads = {})
|
||||
@repository = repository
|
||||
@hook_type = hook_type
|
||||
@payloads = payloads
|
||||
end
|
||||
|
||||
class << self
|
||||
def call(repository, hook_type, payloads = {})
|
||||
new(repository, hook_type, payloads).call
|
||||
end
|
||||
end
|
||||
|
||||
def call
|
||||
send("execute_#{hook_type}_hook")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def logger
|
||||
RedmineGitHosting.logger
|
||||
end
|
||||
|
||||
def execute_fetch_changesets_hook
|
||||
RedmineHooks::FetchChangesets.call(repository)
|
||||
end
|
||||
|
||||
def execute_update_mirrors_hook
|
||||
message = 'Notifying mirrors about changes to this repository:'
|
||||
y = ''
|
||||
|
||||
## Post to each post-receive URL
|
||||
if repository.mirrors.active.any?
|
||||
logger.info(message)
|
||||
y << "\n#{message}\n"
|
||||
|
||||
repository.mirrors.active.each do |mirror|
|
||||
y << RedmineHooks::UpdateMirrors.call(mirror, payloads)
|
||||
end
|
||||
end
|
||||
|
||||
y
|
||||
end
|
||||
|
||||
def execute_call_webservices_hook
|
||||
message = 'Notifying post receive urls about changes to this repository:'
|
||||
y = ''
|
||||
|
||||
## Post to each post-receive URL
|
||||
if repository.post_receive_urls.active.any?
|
||||
logger.info(message)
|
||||
y << "\n#{message}\n"
|
||||
|
||||
repository.post_receive_urls.active.each do |post_receive_url|
|
||||
y << RedmineHooks::CallWebservices.call(post_receive_url, payloads)
|
||||
end
|
||||
end
|
||||
|
||||
y
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue