This repository has been archived by the owner on Oct 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
init.rb
103 lines (83 loc) · 3.42 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'redmine'
require 'dispatcher'
Dispatcher.to_prepare do
# Patches
require_dependency 'checkout/settings_controller_patch'
require_dependency 'checkout/repositories_helper_patch'
require_dependency 'checkout/repository_patch'
require_dependency 'checkout/settings_helper_patch'
require_dependency 'checkout/setting_patch'
end
# Hooks
require 'checkout/repository_hooks'
Redmine::Plugin.register :redmine_checkout do
name 'Redmine Checkout plugin'
url 'http://dev.holgerjust.de/projects/redmine-checkout'
author 'Holger Just'
author_url 'http://meine-er.de'
description 'Add links to the actual repository to the repository view.'
version '0.5'
# required because of the new i18n requirement and changed syntax
requires_redmine :version_or_higher => '1.0.5'
settings_defaults = HashWithIndifferentAccess.new({
'use_zero_clipboard' => '1',
'display_checkout_info' => 'everywhere',
'description_Abstract' => <<-EOF
The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.
Please select the desired protocol below to get the URL.
EOF
})
# this is needed for setting the defaults
require 'checkout/repository_patch'
CheckoutHelper.supported_scm.each do |scm|
klazz = Repository.const_get(scm)
settings_defaults["description_#{scm}"] = ''
settings_defaults["overwrite_description_#{scm}"] = '0'
settings_defaults["display_command_#{scm}"] = '0'
# access can be one of
# read+write => this protocol always allows read/write access
# read-only => this protocol always allows read access only
# permission => Access depends on redmine permissions
settings_defaults["protocols_#{scm}"] = [HashWithIndifferentAccess.new({
:protocol => scm,
:command => klazz.checkout_default_command,
:regex => '',
:regex_replacement => '',
:fixed_url => '',
:access => 'permission',
:append_path => (klazz.allow_subtree_checkout? ? '1' : '0'),
:is_default => '1',
:display_login => '0'
})]
end
settings :default => settings_defaults, :partial => 'settings/redmine_checkout'
Redmine::WikiFormatting::Macros.register do
desc <<-EOF
Creates a checkout link to the actual repository. Example:
use the default checkout protocol !{{repository}}
or use a specific protocol !{{repository(SVN)}}
or use the checkout protocol of a specific specific project: !{{repository(projectname:SVN)}}"
EOF
macro :repository do |obj, args|
proto = args.first
if proto.to_s =~ %r{^([^\:]+)\:(.*)$}
project_identifier, proto = $1, $2
project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier)
else
project = @project
end
if project && project.repository
protocols = project.repository.checkout_protocols.select{|p| p.access_rw(User.current)}
if proto.present?
proto_obj = protocols.find{|p| p.protocol.downcase == proto.downcase}
else
proto_obj = protocols.find(&:default?) || protocols.first
end
end
raise "Checkout protocol #{proto} not found" unless proto_obj
cmd = (project.repository.checkout_display_command? && proto_obj.command.present?) ? proto_obj.command.strip + " " : ""
cmd + link_to(proto_obj.url, proto_obj.url)
end
end
end