Class: CompareLinker
- Inherits:
-
Object
- Object
- CompareLinker
- Defined in:
- lib/compare_linker.rb,
lib/compare_linker/version.rb,
lib/compare_linker/formatter/base.rb,
lib/compare_linker/formatter/text.rb,
lib/compare_linker/gem_dictionary.rb,
lib/compare_linker/webhook_payload.rb,
lib/compare_linker/lockfile_fetcher.rb,
lib/compare_linker/github_tag_finder.rb,
lib/compare_linker/formatter/markdown.rb,
lib/compare_linker/github_link_finder.rb,
lib/compare_linker/lockfile_comparator.rb
Defined Under Namespace
Classes: Formatter, GemDictionary, GithubLinkFinder, GithubTagFinder, LockfileComparator, LockfileFetcher, WebhookPayload
Constant Summary collapse
- VERSION =
"1.4.8"
Instance Attribute Summary collapse
-
#compare_links ⇒ Object
readonly
Returns the value of attribute compare_links.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#pr_number ⇒ Object
readonly
Returns the value of attribute pr_number.
-
#repo_full_name ⇒ Object
readonly
Returns the value of attribute repo_full_name.
Instance Method Summary collapse
- #add_comment(repo_full_name, pr_number, compare_links) ⇒ Object
-
#initialize(repo_full_name, pr_number) ⇒ CompareLinker
constructor
A new instance of CompareLinker.
- #make_compare_links ⇒ Object
- #make_compare_links_from_lockfiles(old_lockfile, new_lockfile) ⇒ Object
Constructor Details
#initialize(repo_full_name, pr_number) ⇒ CompareLinker
Returns a new instance of CompareLinker.
15 16 17 18 19 |
# File 'lib/compare_linker.rb', line 15 def initialize(repo_full_name, pr_number) @repo_full_name = repo_full_name @pr_number = pr_number @formatter = Formatter::Text.new end |
Instance Attribute Details
#compare_links ⇒ Object (readonly)
Returns the value of attribute compare_links.
12 13 14 |
# File 'lib/compare_linker.rb', line 12 def compare_links @compare_links end |
#formatter ⇒ Object
Returns the value of attribute formatter.
13 14 15 |
# File 'lib/compare_linker.rb', line 13 def formatter @formatter end |
#pr_number ⇒ Object (readonly)
Returns the value of attribute pr_number.
12 13 14 |
# File 'lib/compare_linker.rb', line 12 def pr_number @pr_number end |
#repo_full_name ⇒ Object (readonly)
Returns the value of attribute repo_full_name.
12 13 14 |
# File 'lib/compare_linker.rb', line 12 def repo_full_name @repo_full_name end |
Instance Method Details
#add_comment(repo_full_name, pr_number, compare_links) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/compare_linker.rb', line 66 def add_comment(repo_full_name, pr_number, compare_links) res = requested_repository_octokit.add_comment( repo_full_name, pr_number, compare_links ) res[:html_url] end |
#make_compare_links ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/compare_linker.rb', line 21 def make_compare_links if requested_repository_octokit.pull_request_files(repo_full_name, pr_number).find { |resource| resource.filename == "Gemfile.lock" } pull_request = requested_repository_octokit.pull_request(repo_full_name, pr_number) fetcher = LockfileFetcher.new(requested_repository_octokit) old_lockfile = fetcher.fetch(repo_full_name, pull_request.base.sha) new_lockfile = fetcher.fetch(repo_full_name, pull_request.head.sha) make_compare_links_from_lockfiles(old_lockfile, new_lockfile) end end |
#make_compare_links_from_lockfiles(old_lockfile, new_lockfile) ⇒ Object
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 |
# File 'lib/compare_linker.rb', line 33 def make_compare_links_from_lockfiles(old_lockfile, new_lockfile) comparator = LockfileComparator.new comparator.compare(old_lockfile, new_lockfile) @compare_links = comparator.updated_gems.map { |gem_name, gem_info| if gem_info[:owner].nil? finder = GithubLinkFinder.new(octokit, gem_dictionary) finder.find(gem_name) gem_info[:homepage_uri] = finder.homepage_uri if finder.repo_owner.nil? formatter.format(gem_info) else gem_info[:repo_owner] = finder.repo_owner gem_info[:repo_name] = finder.repo_name tag_finder = GithubTagFinder.new(octokit, gem_name, finder.repo_full_name) old_tag = tag_finder.find(gem_info[:old_ver]) new_tag = tag_finder.find(gem_info[:new_ver]) if old_tag && new_tag gem_info[:old_tag] = old_tag.name gem_info[:new_tag] = new_tag.name formatter.format(gem_info) else formatter.format(gem_info) end end else formatter.format(gem_info) end } @compare_links end |