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.3.1"
Instance Attribute Summary collapse
-
#compare_links ⇒ Object
readonly
Returns the value of attribute compare_links.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#gem_dictionary ⇒ Object
readonly
Returns the value of attribute gem_dictionary.
-
#octokit ⇒ Object
Returns the value of attribute octokit.
-
#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
Constructor Details
#initialize(repo_full_name, pr_number) ⇒ CompareLinker
Returns a new instance of CompareLinker.
15 16 17 18 19 20 21 |
# File 'lib/compare_linker.rb', line 15 def initialize(repo_full_name, pr_number) @repo_full_name = repo_full_name @pr_number = pr_number @octokit ||= Octokit::Client.new(access_token: ENV["OCTOKIT_ACCESS_TOKEN"]) @gem_dictionary = GemDictionary.new @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 |
#gem_dictionary ⇒ Object (readonly)
Returns the value of attribute gem_dictionary.
12 13 14 |
# File 'lib/compare_linker.rb', line 12 def gem_dictionary @gem_dictionary end |
#octokit ⇒ Object
Returns the value of attribute octokit.
13 14 15 |
# File 'lib/compare_linker.rb', line 13 def octokit @octokit 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
64 65 66 67 68 69 70 71 |
# File 'lib/compare_linker.rb', line 64 def add_comment(repo_full_name, pr_number, compare_links) res = octokit.add_comment( repo_full_name, pr_number, compare_links ) "https://github.com/#{repo_full_name}/pull/#{pr_number}#issuecomment-#{res.id}" end |
#make_compare_links ⇒ Object
23 24 25 26 27 28 29 30 31 32 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 |
# File 'lib/compare_linker.rb', line 23 def make_compare_links if octokit.pull_request_files(repo_full_name, pr_number).find { |resource| resource.filename == "Gemfile.lock" } pull_request = octokit.pull_request(repo_full_name, pr_number) fetcher = LockfileFetcher.new(octokit) old_lockfile = fetcher.fetch(repo_full_name, pull_request.base.sha) new_lockfile = fetcher.fetch(repo_full_name, pull_request.head.sha) 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 end |