gem_updater 8.2.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gem_updater/changelog_parser/github_parser.rb +66 -21
- data/lib/gem_updater/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ae0b7516e382a069fe5fea921db87729ff1cd662f55a1f5e835275d82b998f42
|
|
4
|
+
data.tar.gz: f6b283aad770a194f12524fe6b8c243ffd1bab71c49cddab19ee6c91e04d7d69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ae928f0f43ddc59c3be1e76078b6c45ae12068e6c3e9a0409f47122149cc5aae81cac86bf489767fd60dc0185ad181558bc747129bd49af4c954a337f2f3388
|
|
7
|
+
data.tar.gz: 21044a1278e58e97905813cd1dd38185f48c68dc11112567cf16da71b079600b7e5fe86c9973306305143c25856a718cd61d0f7fb0f5e41e30f43abe4fcc1413
|
|
@@ -7,8 +7,8 @@ module GemUpdater
|
|
|
7
7
|
class ChangelogParser
|
|
8
8
|
# ChangelogParser is responsible for parsing a changelog hosted on github.
|
|
9
9
|
class GithubParser
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
MARKDOWN_HEADING_PATTERN = /^#+\s+(.*?)$/
|
|
11
|
+
RDOC_HEADING_PATTERN = /^===\s+(.*?)$/
|
|
12
12
|
|
|
13
13
|
attr_reader :uri, :version
|
|
14
14
|
|
|
@@ -23,33 +23,78 @@ module GemUpdater
|
|
|
23
23
|
#
|
|
24
24
|
# @return [String] the URL of changelog
|
|
25
25
|
def changelog
|
|
26
|
-
|
|
26
|
+
anchor = find_anchor_from_raw_content
|
|
27
|
+
anchor ? "#{uri}##{anchor}" : uri
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
private
|
|
30
31
|
|
|
31
|
-
#
|
|
32
|
+
# Fetches raw markdown/RDoc content and finds anchor for the version
|
|
32
33
|
#
|
|
33
|
-
# @return [
|
|
34
|
-
def
|
|
35
|
-
|
|
34
|
+
# @return [String, nil] anchor if found
|
|
35
|
+
def find_anchor_from_raw_content
|
|
36
|
+
raw_url = raw_content_url
|
|
37
|
+
return unless raw_url
|
|
38
|
+
|
|
39
|
+
begin
|
|
40
|
+
content = URI.parse(raw_url).read
|
|
41
|
+
parse_headings(content)
|
|
42
|
+
rescue OpenURI::HTTPError
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Extracts raw content URL from GitHub's X-Raw-Download response header
|
|
48
|
+
#
|
|
49
|
+
# @return [String] raw content URL
|
|
50
|
+
def raw_content_url
|
|
51
|
+
response = URI.parse(uri).open
|
|
52
|
+
response.meta['x-raw-download']
|
|
36
53
|
end
|
|
37
54
|
|
|
38
|
-
#
|
|
55
|
+
# Parses markdown/RDoc content to find heading matching the version
|
|
39
56
|
#
|
|
40
|
-
# @param
|
|
41
|
-
# @return [String, nil] anchor
|
|
42
|
-
def
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
# @param content [String] raw markdown/RDoc content
|
|
58
|
+
# @return [String, nil] anchor if found
|
|
59
|
+
def parse_headings(content)
|
|
60
|
+
heading_patterns = [MARKDOWN_HEADING_PATTERN, RDOC_HEADING_PATTERN]
|
|
61
|
+
|
|
62
|
+
content.each_line do |line|
|
|
63
|
+
heading_text = heading_patterns.each do |pattern|
|
|
64
|
+
break Regexp.last_match(1).strip if line.match(pattern)
|
|
65
|
+
end
|
|
66
|
+
heading_text = nil if heading_text.is_a?(Array)
|
|
67
|
+
|
|
68
|
+
next unless heading_text&.match?(version)
|
|
69
|
+
|
|
70
|
+
return generate_github_anchor(heading_text)
|
|
71
|
+
end
|
|
72
|
+
nil
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Generates GitHub-style anchor from heading text
|
|
76
|
+
#
|
|
77
|
+
# @param heading_text [String] the heading text
|
|
78
|
+
# @return [String] GitHub-style anchor
|
|
79
|
+
def generate_github_anchor(heading_text)
|
|
80
|
+
# GitHub's anchor generation algorithm:
|
|
81
|
+
# 1. Convert to lowercase
|
|
82
|
+
# 2. Remove dots
|
|
83
|
+
# 3. Replace / with --
|
|
84
|
+
# 4. Replace em dashes with ---
|
|
85
|
+
# 5. Remove special characters except letters (including accented), numbers, hyphens, spaces
|
|
86
|
+
# 6. Replace spaces with hyphens
|
|
87
|
+
# 7. Remove leading/trailing hyphens
|
|
88
|
+
anchor = heading_text
|
|
89
|
+
.downcase
|
|
90
|
+
.delete('.')
|
|
91
|
+
.gsub(%r{\s*/\s*}, '--')
|
|
92
|
+
.gsub(/—/, '---') # Replace em dash with three hyphens
|
|
93
|
+
.gsub(/[^\p{L}0-9\-\s]/, '') # Keep all Unicode letters including accented
|
|
94
|
+
.gsub(/\s+/, '-')
|
|
95
|
+
.sub(/^-|-$/, '')
|
|
96
|
+
|
|
97
|
+
anchor.empty? ? nil : anchor
|
|
53
98
|
end
|
|
54
99
|
end
|
|
55
100
|
end
|
data/lib/gem_updater/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gem_updater
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 9.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maxime Demolin
|
|
@@ -166,14 +166,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
166
166
|
requirements:
|
|
167
167
|
- - ">="
|
|
168
168
|
- !ruby/object:Gem::Version
|
|
169
|
-
version: '3.
|
|
169
|
+
version: '3.3'
|
|
170
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
requirements:
|
|
172
172
|
- - ">="
|
|
173
173
|
- !ruby/object:Gem::Version
|
|
174
174
|
version: '0'
|
|
175
175
|
requirements: []
|
|
176
|
-
rubygems_version: 4.0.
|
|
176
|
+
rubygems_version: 4.0.6
|
|
177
177
|
specification_version: 4
|
|
178
178
|
summary: Update your gems and find their changelogs
|
|
179
179
|
test_files: []
|