librariesio-url-parser 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df16d2958656fa866177551cb6c6275e6b8303c40d41d3baeb639aff567aad07
4
- data.tar.gz: ec4443d5e407716d312746c7157d698a21b9c10eaeea208f42101b42688f4b47
3
+ metadata.gz: 39533f7a7c92f1b4bcccd5a9a46b3c2ae5d14f04da87b0d643339be188184dfc
4
+ data.tar.gz: bcf4fd5128de3343a11f46b25fadf2cf0f0daf479a9f37824f2d0ac93534753b
5
5
  SHA512:
6
- metadata.gz: 8ca1db0935515b6fe9d0f2dc5c27e8af36bb8cd4b652dc70d4f5194a27edd1cd4257144bd83b4b9c7fb4ae6dc333a37789021e852a1bc34cdf4000a61a27b86f
7
- data.tar.gz: f253083f04c93d8eff970002d9bcc02ce0ffb362167149371a6a5576dd4ed1ee9dbe2c760841695873487749cab40d121447fdf48f74d429b46be930322db683
6
+ metadata.gz: 27401dad229d48fd32ec999b91ddf171a708b847fdbfbbb21b283cf6b72e1f8280731ccd2f51a012bdfcf7d73f9087a7c00ab8b8db3109b55913a434be70dba1
7
+ data.tar.gz: ed74167bc7f4b712209ecf9e0fddbafe7c5c9f77dcda9fcfb883b658d8e99ee8283d89a70f4ddecd2fd3a62912c5cb04c72358804dbedb44932e0adafae75594
data/Gemfile CHANGED
@@ -3,5 +3,3 @@ ruby "2.6.5"
3
3
 
4
4
  # Specify your gem's dependencies in librariesio-url-parser.gemspec
5
5
  gemspec
6
-
7
- gem "pry", "~> 0.14.1", :group => :development
data/Gemfile.lock CHANGED
@@ -1,17 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- librariesio-url-parser (1.0.1)
4
+ librariesio-url-parser (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- coderay (1.1.3)
10
9
  diff-lcs (1.5.0)
11
- method_source (1.0.0)
12
- pry (0.14.1)
13
- coderay (~> 1.1)
14
- method_source (~> 1.0)
15
10
  rake (12.3.3)
16
11
  rspec (3.11.0)
17
12
  rspec-core (~> 3.11.0)
@@ -34,7 +29,6 @@ PLATFORMS
34
29
 
35
30
  DEPENDENCIES
36
31
  librariesio-url-parser!
37
- pry (~> 0.14.1)
38
32
  rake (~> 12.0)
39
33
  rspec (~> 3.0)
40
34
  rspec_junit_formatter (~> 0.5)
data/README.md CHANGED
@@ -45,6 +45,7 @@ URLParser.try_all("git@bitbucket.org:tildeslash/monit.git") #=> "https://bitbuck
45
45
  - GitHub
46
46
  - GitLab
47
47
  - Bitbucket
48
+ - Apache SVN
48
49
 
49
50
  ## Development
50
51
 
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+ class ApacheSvnUrlParser < URLParser
3
+ SUBDIR_NAMES = %w[trunk tags branches].freeze
4
+ private
5
+
6
+ def full_domain
7
+ 'https://svn.apache.org/viewvc'
8
+ end
9
+
10
+ def tlds
11
+ %w(org)
12
+ end
13
+
14
+ def domain
15
+ 'svn.apache'
16
+ end
17
+
18
+ def domain_regex
19
+ # match only the viewvc endpoint at the domain
20
+ "#{domain.split("/").first}\.(#{tlds.join('|')})\/viewvc"
21
+ end
22
+
23
+ def remove_domain
24
+ # find the matches for any github domain characters in the url string
25
+ # and replace only the first match incase we find a repo with something like github.com as the name
26
+ url.sub!(/(apache\.org\/(viewvc|repos))+?(:|\/)?/i, '')
27
+ end
28
+
29
+ def extractable_early?
30
+ false
31
+ end
32
+
33
+ def remove_extra_segments
34
+ # split the url by / and remove any empty sections
35
+ self.url = url.split('/').reject{ |s| s.strip.empty? }
36
+
37
+ # check to see if any repository subdirectories are included in the segments
38
+ # this parser is parsing SVN projects, so any common folders used for branching should trip this
39
+ # truncate the array of segments to stop once we hit a top level sub directory typically seen in SVN repos
40
+ # and return everything up to that point
41
+ #
42
+ # for example apache.org/viewvnc/myproject/subproject/tags/my-1.0.0-release should stop at myproject/subproject
43
+ # since the tags are just part of that repository
44
+ subdir_index = url.index{ |s| SUBDIR_NAMES.include?(s) }
45
+
46
+ # it looks like the maven/pom directory on the Apache SVN server has a bunch of repositories stored under tags
47
+ # in this special case, grab the directory name under the subdirectory
48
+ # it looks like this is most likely to be the first directory under tags/
49
+ in_maven_pom_dir = url[0..1].join("/").downcase == "maven/pom"
50
+
51
+ if in_maven_pom_dir
52
+ self.url = url[0..subdir_index+1] if subdir_index
53
+ else
54
+ self.url = url[0..subdir_index-1] if subdir_index
55
+ end
56
+ end
57
+
58
+ def format_url
59
+ # if this is an Array then the url has gone through all the clean up steps
60
+ #
61
+ # if this is just a string then the url was not cleaned up and I have no idea how to format it
62
+ return nil unless url.is_a?(Array) && url.length.positive?
63
+
64
+ url.join("/")
65
+ end
66
+ end
@@ -4,7 +4,8 @@ require_relative "url_parser"
4
4
  require_relative "bitbucket_url_parser"
5
5
  require_relative "github_url_parser"
6
6
  require_relative "gitlab_url_parser"
7
+ require_relative "apache_svn_url_parser"
7
8
 
8
9
  module LibrariesioURLParser
9
- VERSION = "1.0.1"
10
+ VERSION = "1.0.2"
10
11
  end
data/lib/url_parser.rb CHANGED
@@ -30,12 +30,13 @@ class URLParser
30
30
  def self.try_all(url)
31
31
  GithubURLParser.parse_to_full_url(url) ||
32
32
  GitlabURLParser.parse_to_full_url(url) ||
33
- BitbucketURLParser.parse_to_full_url(url)
33
+ BitbucketURLParser.parse_to_full_url(url) ||
34
+ ApacheSvnUrlParser.parse_to_full_url(url)
34
35
  end
35
36
 
36
37
  def parse_to_full_url
37
38
  path = parse
38
- return nil unless path.present?
39
+ return nil if path.nil? || path.empty?
39
40
  [full_domain, path].join('/')
40
41
  end
41
42
 
@@ -151,11 +152,11 @@ class URLParser
151
152
  end
152
153
 
153
154
  def remove_scheme
154
- url.gsub!(/(((git\+https|git|ssh|hg|svn|scm|http|https)+?:)+?)/i, '')
155
+ url.gsub!(/(((git\+https|git|ssh|hg|svn|scm|http|https)+?:)(\/\/)?)/i, '')
155
156
  end
156
157
 
157
158
  def remove_subdomain
158
- url.gsub!(/(www|ssh|raw|git|wiki)+?\./i, '')
159
+ url.gsub!(/(www|ssh|raw|git|wiki|svn)+?\./i, '')
159
160
  end
160
161
 
161
162
  def remove_whitespace
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librariesio-url-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Pace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-26 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -65,6 +65,7 @@ files:
65
65
  - Gemfile.lock
66
66
  - README.md
67
67
  - Rakefile
68
+ - lib/apache_svn_url_parser.rb
68
69
  - lib/bitbucket_url_parser.rb
69
70
  - lib/github_url_parser.rb
70
71
  - lib/gitlab_url_parser.rb