Skip to content

Commit 166f03b

Browse files
author
s-andy
committed
Fixes for Redmine 3.x: regexp fix and observer removal
git-svn-id: http://svn.s-andy.com/scm-creator@141 ea6535c2-5f70-4292-bc30-dee2014a1bba
1 parent dfb045a commit 166f03b

13 files changed

+66
-58
lines changed

app/models/repository/github.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require_dependency File.expand_path('../../../../lib/adapters/github_adapter', __FILE__)
22

33
class Repository::Github < Repository::Git
4-
validates_format_of :url, :with => %r{^(https://github\.com/|git@github\.com:)[a-z0-9\-_]+/[a-z0-9\-_]+\.git$}i, :allow_blank => true
4+
validates_format_of :url, :with => %r{\A(https://github\.com/|git@github\.com:)[a-z0-9\-_]+/[a-z0-9\-_]+\.git\z}i, :allow_blank => true
55

66
before_save :set_local_url
77
before_save :register_hook
@@ -79,7 +79,7 @@ def extra_boolean_attribute(name)
7979

8080
def set_local_url
8181
if new_record? && url.present? && root_url.blank? && GithubCreator.options && GithubCreator.options['path']
82-
path = url.sub(%r{^.*[@/]github.com[:/]}, '')
82+
path = url.sub(%r{\A.*[@/]github.com[:/]}, '')
8383
if Redmine::Platform.mswin?
8484
self.root_url = "#{GithubCreator.options['path']}\\#{path.gsub(%r{/}, '\\')}"
8585
else

app/models/repository_observer.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

init.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@
1515
require_dependency 'scm_config'
1616
require_dependency 'scm_hook'
1717

18-
require_dependency File.expand_path(File.join(File.dirname(__FILE__), 'app/models/repository_observer'))
19-
2018
Rails.logger.info 'Starting SCM Creator Plugin for Redmine'
2119

22-
ActiveRecord::Base.observers << RepositoryObserver
23-
2420
Redmine::Scm::Base.add('Github')
2521

2622
Rails.configuration.to_prepare do
@@ -41,5 +37,5 @@
4137
author_url 'http://www.andriylesyuk.com/'
4238
description 'Allows creating Subversion, Git, Mercurial, Bazaar and Github repositories within Redmine.'
4339
url 'http://projects.andriylesyuk.com/projects/scm-creator'
44-
version '0.5.0b'
40+
version '0.5.1'
4541
end

lib/adapters/github_adapter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def fetch
2727

2828
def url_with_credentials
2929
if @login.present? && @password.present?
30-
if url =~ %r{^https://}
31-
url.sub(%r{^https://}, "https://#{@login}:#{@password}@")
30+
if url =~ %r{\Ahttps://}
31+
url.sub(%r{\Ahttps://}, "https://#{@login}:#{@password}@")
3232
else
33-
url.sub(%r{^git@}, "#{@login}:#{@password}@")
33+
url.sub(%r{\Agit@}, "#{@login}:#{@password}@")
3434
end
3535
else
3636
url

lib/creator/bazaar_creator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def enabled?
1818
false
1919
end
2020

21-
def external_url(repository, regexp = %r{^(?:sftp|bzr(?:\+[a-z]+)?)://})
21+
def external_url(repository, regexp = %r{\A(?:sftp|bzr(?:\+[a-z]+)?)://})
2222
super
2323
end
2424

lib/creator/git_creator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def enabled?
1818
false
1919
end
2020

21-
def external_url(repository, regexp = %r{^(?:https?|git|ssh)://})
21+
def external_url(repository, regexp = %r{\A(?:https?|git|ssh)://})
2222
url = super
23-
if url.present? && repository.root_url =~ %r{\.git$}
23+
if url.present? && repository.root_url =~ %r{\.git\z}
2424
url + '.git'
2525
else
2626
url
@@ -48,7 +48,7 @@ def existing_path(identifier, repository = nil)
4848

4949
def repository_name(path)
5050
base = Redmine::Platform.mswin? ? options['path'].gsub(%r{\\}, "/") : options['path']
51-
matches = Regexp.new("^#{Regexp.escape(base)}/([^/]+?)(\\.git)?/?$").match(path)
51+
matches = Regexp.new("\A#{Regexp.escape(base)}/([^/]+?)(\\.git)?/?\z").match(path)
5252
matches ? matches[1] : nil
5353
end
5454

lib/creator/github_creator.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def local?
3030
def sanitize(attributes)
3131
if attributes.has_key?('url')
3232
url = attributes['url']
33-
if url !~ %r{^(https://github\.com|git@github\.com)}
33+
if url !~ %r{\A(https://github\.com|git@github\.com)}
3434
if url.start_with?(':')
3535
url = 'git@github.com' + url
3636
elsif url.start_with?('/')
@@ -41,7 +41,7 @@ def sanitize(attributes)
4141
url = 'https://github.com/user/' + url
4242
end
4343
end
44-
if url !~ %r{\.git$}
44+
if url !~ %r{\.git\z}
4545
url << '.git' unless url.end_with?('/')
4646
end
4747
attributes['url'] = url unless attributes['url'] == url
@@ -51,8 +51,8 @@ def sanitize(attributes)
5151

5252
# path should be the actual URL at this stage
5353
def access_url(path, repository = nil)
54-
if path !~ %r{^(https://github\.com/|git@github\.com:)} &&
55-
repository.url =~ %r{^(https://github\.com/|git@github\.com:)}
54+
if path !~ %r{\A(https://github\.com/|git@github\.com:)} &&
55+
repository.url =~ %r{\A(https://github\.com/|git@github\.com:)}
5656
repository.url
5757
else
5858
path
@@ -65,7 +65,7 @@ def access_root_url(path, repository = nil)
6565
end
6666

6767
# let Redmine use the repository URL
68-
def external_url(repository, regexp = %r{^(?:https?://|git@)})
68+
def external_url(repository, regexp = %r{\A(?:https?://|git@)})
6969
repository.url
7070
end
7171

@@ -79,7 +79,7 @@ def existing_path(identifier, repository = nil)
7979
end
8080

8181
def repository_name(path)
82-
matches = %r{^(?:.*/)?([^/]+?)(\\.git)?/?$}.match(path)
82+
matches = %r{\A(?:.*/)?([^/]+?)(\\.git)?/?\z}.match(path)
8383
matches ? matches[1] : nil
8484
end
8585

@@ -96,7 +96,7 @@ def create_repository(path, repository = nil)
9696
response = client.create(repository_name(path), create_options)
9797
if response.is_a?(Sawyer::Resource) && response.key?(:clone_url)
9898
repository.merge_extra_info('extra_created_with_scm' => 1)
99-
if repository && repository.url =~ %r{^git@} && repository.login.blank? && response.key?(:ssh_url)
99+
if repository && repository.url =~ %r{\Agit@} && repository.login.blank? && response.key?(:ssh_url)
100100
response[:ssh_url]
101101
else
102102
response[:clone_url]
@@ -121,7 +121,7 @@ def register_hook(repository, login = nil, password = nil)
121121
else
122122
registrar = client
123123
end
124-
github_repository = Octokit::Repository.from_url(repository.url.sub(%r{\.git$}, ''))
124+
github_repository = Octokit::Repository.from_url(repository.url.sub(%r{\.git\z}, ''))
125125
response = client.create_hook(github_repository, 'redmine', {
126126
:address => "#{Setting.protocol}://#{Setting.host_name}",
127127
:project => repository.project.identifier,

lib/creator/mercurial_creator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def enabled?
1818
false
1919
end
2020

21-
def external_url(repository, regexp = %r{^(?:https?|ssh)://})
21+
def external_url(repository, regexp = %r{\A(?:https?|ssh)://})
2222
super
2323
end
2424

lib/creator/scm_creator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def interface(repository)
1919

2020
# returns config id used in scm.yml and ScmConfig
2121
def scm_id
22-
if self.name =~ %r{^(.+)Creator$}
22+
if self.name =~ %r{\A(.+)Creator\z}
2323
$1.downcase
2424
else
2525
nil
@@ -75,7 +75,7 @@ def path(identifier)
7575
end
7676

7777
# returns url which can be used to access the repository externally
78-
def external_url(repository, regexp = %r{^https?://})
78+
def external_url(repository, regexp = %r{\Ahttps?://})
7979
if options['url'] && name = repository_name(repository.root_url)
8080
if options['url'] =~ regexp
8181
url = "#{options['url']}/#{name}"
@@ -104,13 +104,13 @@ def existing_path(identifier, repository = nil)
104104
# extracts repository name from path
105105
def repository_name(path)
106106
base = Redmine::Platform.mswin? ? options['path'].gsub(%r{\\}, "/") : options['path']
107-
matches = Regexp.new("^#{Regexp.escape(base)}/([^/]+)/?$").match(path)
107+
matches = Regexp.new("\A#{Regexp.escape(base)}/([^/]+)/?\z").match(path)
108108
matches ? matches[1] : nil
109109
end
110110

111111
# compares repository names (was created for multiple repositories support)
112112
def belongs_to_project?(name, identifier)
113-
name =~ %r{^#{Regexp.escape(identifier)}(\..+)?$}
113+
name =~ %r{\A#{Regexp.escape(identifier)}(\..+)?\z}
114114
end
115115

116116
# returns format of repository path which is displayed in the form as a default value

lib/creator/subversion_creator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ def access_root_url(path, repository = nil)
3434
'file://' + (Redmine::Platform.mswin? ? '/' + path.gsub(%r{\\}, "/") : path)
3535
end
3636

37-
def external_url(repository, regexp = %r{^(?:file|https?|svn(?:\+[a-z]+)?)://})
37+
def external_url(repository, regexp = %r{\A(?:file|https?|svn(?:\+[a-z]+)?)://})
3838
super
3939
end
4040

4141
def repository_name(path)
4242
base = Redmine::Platform.mswin? ? '/' + options['path'].gsub(%r{\\}, "/") : options['path']
43-
matches = Regexp.new("^file://#{Regexp.escape(base)}/([^/]+)/?$").match(path)
43+
matches = Regexp.new("\Afile://#{Regexp.escape(base)}/([^/]+)/?\z").match(path)
4444
matches ? matches[1] : nil
4545
end
4646

0 commit comments

Comments
 (0)