Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/overrides/repositories/navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
insert_before: 'erb[loud]:contains("label_statistics")',
original: '88f120e99075ba3246901c6e970ca671d7166855',
text: '<%= call_hook(:view_repositories_navigation, repository: @repository) %>'

module Repositories
module Navigation
end
end
5 changes: 5 additions & 0 deletions app/overrides/repositories/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
insert_before: 'erb[silent]:contains("html_title")',
original: '2a0a09659d76066b896016c72527d479c69463ec',
partial: 'hooks/show_repositories_sidebar'

module Repositories
module Show
end
end
3 changes: 3 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

require 'redmine'

$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/lib"

require 'redmine_git_hosting'

Redmine::Plugin.register :redmine_git_hosting do
Expand Down
1 change: 0 additions & 1 deletion lib/hrack/lib/hrack/bundle.rb → lib/hrack/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'rack/builder'
require 'rack/parser'
require 'hrack/server'

module Hrack
module Bundle
Expand Down
4 changes: 0 additions & 4 deletions lib/hrack/init.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/hrack/lib/hrack.rb

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions lib/hrack/lib/hrack/version.rb → lib/hrack/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

module Hrack
module Version
end
VERSION = '1.0.0'
end
3 changes: 3 additions & 0 deletions lib/load_gitolite_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@
].each do |file|
require_dependency file if File.exist? file
end

module LoadGitoliteHooks
end
2 changes: 1 addition & 1 deletion lib/redmine_git_hosting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ def additionals_help_items
# Redmine SCM adapter
require_dependency 'redmine/scm/adapters/xitolite_adapter'

require 'hrack/init'
require 'hrack/bundle'
end
104 changes: 53 additions & 51 deletions lib/redmine_git_hosting/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,72 @@
require 'github/markup'

module RedmineGitHosting
class GitHostingHookListener < Redmine::Hook::ViewListener
render_on :view_repository_edit_top, partial: 'repositories/edit_top'
render_on :view_repositories_show_contextual, partial: 'repositories/show_top'
render_on :view_repository_edit_bottom, partial: 'repositories/edit_bottom'
render_on :view_repositories_show_sidebar, partial: 'repositories/git_hosting_sidebar'
render_on :view_repositories_navigation, partial: 'repositories/git_hosting_navigation'
render_on :view_layouts_base_html_head, partial: 'common/git_hosting_html_head'

def view_my_account_contextual(context)
user = context[:user]
link_to(l(:label_my_public_keys), public_keys_path, class: 'icon icon-passwd') if user.allowed_to_create_ssh_keys?
end
module Hooks
class GitHostingHookListener < Redmine::Hook::ViewListener
render_on :view_repository_edit_top, partial: 'repositories/edit_top'
render_on :view_repositories_show_contextual, partial: 'repositories/show_top'
render_on :view_repository_edit_bottom, partial: 'repositories/edit_bottom'
render_on :view_repositories_show_sidebar, partial: 'repositories/git_hosting_sidebar'
render_on :view_repositories_navigation, partial: 'repositories/git_hosting_navigation'
render_on :view_layouts_base_html_head, partial: 'common/git_hosting_html_head'

def view_my_account_contextual(context)
user = context[:user]
link_to(l(:label_my_public_keys), public_keys_path, class: 'icon icon-passwd') if user.allowed_to_create_ssh_keys?
end

def self.default_url_options
{ script_name: Redmine::Utils.relative_url_root }
end
def self.default_url_options
{ script_name: Redmine::Utils.relative_url_root }
end

def view_repositories_show_bottom(context)
path = get_path context
rev = get_rev context
repository = context[:repository]
readme_file = find_readme_file repository, path, rev
def view_repositories_show_bottom(context)
path = get_path context
rev = get_rev context
repository = context[:repository]
readme_file = find_readme_file repository, path, rev

return '' if readme_file.nil?
return '' if readme_file.nil?

content = get_formatted_text repository, readme_file, rev
content = get_formatted_text repository, readme_file, rev

context[:controller].send :render_to_string, partial: 'repositories/readme', locals: { html: content }
end

private
context[:controller].send :render_to_string, partial: 'repositories/readme', locals: { html: content }
end

def get_path(context)
context[:request].params['path'] || ''
end
private

def get_rev(context)
rev = context[:request].params['rev']
rev.presence
end
def get_path(context)
context[:request].params['path'] || ''
end

def find_readme_file(repository, path, rev)
(repository.entries(path, rev) || []).find { |f| f.name =~ /README((\.).*)?/i }
end
def get_rev(context)
rev = context[:request].params['rev']
rev.presence
end

def get_formatted_text(repository, file, rev)
raw_readme_text = Redmine::CodesetUtil.to_utf8_by_setting repository.cat(file.path, rev)
def find_readme_file(repository, path, rev)
(repository.entries(path, rev) || []).find { |f| f.name =~ /README((\.).*)?/i }
end

if redmine_file? file
formatter_name = Redmine::WikiFormatting.format_names.find { |name| name =~ /markdown/i }
Redmine::WikiFormatting.formatter_for(formatter_name).new(raw_readme_text).to_html
elsif github_file? file
RedmineGitHosting::MarkdownRenderer.to_html raw_readme_text
else
GitHub::Markup.render(file.path, raw_readme_text).gsub("\n", '<br/>')
def get_formatted_text(repository, file, rev)
raw_readme_text = Redmine::CodesetUtil.to_utf8_by_setting repository.cat(file.path, rev)

if redmine_file? file
formatter_name = Redmine::WikiFormatting.format_names.find { |name| name =~ /markdown/i }
Redmine::WikiFormatting.formatter_for(formatter_name).new(raw_readme_text).to_html
elsif github_file? file
RedmineGitHosting::MarkdownRenderer.to_html raw_readme_text
else
GitHub::Markup.render(file.path, raw_readme_text).gsub("\n", '<br/>')
end
end
end

def redmine_file?(file)
%w[.txt].include? File.extname(file.path)
end
def redmine_file?(file)
%w[.txt].include? File.extname(file.path)
end

def github_file?(file)
%w[.markdown .mdown .mkdn .md].include? File.extname(file.path)
def github_file?(file)
%w[.markdown .mdown .mkdn .md].include? File.extname(file.path)
end
end
end
end
3 changes: 3 additions & 0 deletions lib/redmine_git_hosting/journal_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ def msg2str(msg)
end
end
end
else
module JournalLogger
end
end
end