-
Notifications
You must be signed in to change notification settings - Fork 4
/
changelog_url_finder.rb
43 lines (37 loc) · 966 Bytes
/
changelog_url_finder.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
module LockDiff
module Github
class ChangelogUrlFinder
CHANGE_LOG_CANDIDATES = %w(
changelog
changes
history
releases
releasenote
news
)
def initialize(repository:, repository_url:, ref:)
@repository = repository
@repository_url = repository_url
@ref = ref
end
def call
find_change_log_url || find_release_url
end
private
def find_change_log_url
Github.client.contents(@repository, ref: @ref).
select(&:file?).
find { |content|
name = content.name.downcase.delete('_')
CHANGE_LOG_CANDIDATES.any? { |candidate| name.start_with? candidate }
}&.html_url
end
def find_release_url
return unless @repository_url
unless Github.client.exist_releases?(@repository)
@repository_url + "/releases"
end
end
end
end
end