Class: CompareLinkerWrapper::Linker
- Inherits:
-
Object
- Object
- CompareLinkerWrapper::Linker
- Defined in:
- lib/compare_linker_wrapper/linker.rb
Instance Attribute Summary collapse
-
#git_options ⇒ Object
Returns the value of attribute git_options.
-
#git_path ⇒ Object
Returns the value of attribute git_path.
Instance Method Summary collapse
- #access_token ⇒ Object
- #add_formatter(formatter_class) ⇒ Object
- #client ⇒ Object
- #git ⇒ Object
-
#initialize(git_path = '.', git_options = {}) ⇒ Linker
constructor
A new instance of Linker.
- #link(params) ⇒ Object
- #logger ⇒ Object
- #parse(lock_file) ⇒ Object
Constructor Details
#initialize(git_path = '.', git_options = {}) ⇒ Linker
Returns a new instance of Linker.
4 5 6 7 |
# File 'lib/compare_linker_wrapper/linker.rb', line 4 def initialize(git_path = '.', = {}) @git_path = git_path @git_options = end |
Instance Attribute Details
#git_options ⇒ Object
Returns the value of attribute git_options.
3 4 5 |
# File 'lib/compare_linker_wrapper/linker.rb', line 3 def @git_options end |
#git_path ⇒ Object
Returns the value of attribute git_path.
3 4 5 |
# File 'lib/compare_linker_wrapper/linker.rb', line 3 def git_path @git_path end |
Instance Method Details
#access_token ⇒ Object
9 10 11 |
# File 'lib/compare_linker_wrapper/linker.rb', line 9 def access_token ENV['OCTOKIT_ACCESS_TOKEN'] || ENV['GITHUB_ACCESS_TOKEN'] end |
#add_formatter(formatter_class) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/compare_linker_wrapper/linker.rb', line 63 def add_formatter(formatter_class) formatter = Formatter.add_formatter(formatter_class) if formatter_class fail NoFormatterError unless formatter logger.info('use formatter') logger.info(formatter) formatter end |
#client ⇒ Object
13 14 15 |
# File 'lib/compare_linker_wrapper/linker.rb', line 13 def client @client ||= ::Octokit::Client.new(access_token: access_token) end |
#git ⇒ Object
17 18 19 |
# File 'lib/compare_linker_wrapper/linker.rb', line 17 def git @git ||= Git.open(@git_path, @git_options) end |
#link(params) ⇒ Object
21 22 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 |
# File 'lib/compare_linker_wrapper/linker.rb', line 21 def link(params) formatter = add_formatter(params[:formatter]) comments = [] params[:file].each do |gemfile_lock| old_lockfile = parse(git.show(params[:base], gemfile_lock)) new_lockfile = parse(git.show(params[:head], gemfile_lock)) comparator = ::CompareLinker::LockfileComparator.new comparator.compare(old_lockfile, new_lockfile) compare_links = comparator.updated_gems.map do |gem_name, gem_info| if gem_info[:owner].nil? finder = ::CompareLinker::GithubLinkFinder.new(client) finder.find(gem_name) if finder.repo_owner.nil? gem_info[:homepage_uri] = finder.homepage_uri formatter.format(gem_info) else gem_info[:repo_owner] = finder.repo_owner gem_info[:repo_name] = finder.repo_name tag_finder = ::CompareLinker::GithubTagFinder.new(client) old_tag = tag_finder.find(finder.repo_full_name, gem_info[:old_ver]) new_tag = tag_finder.find(finder.repo_full_name, 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 end comments << compare_links end comments end |
#logger ⇒ Object
71 72 73 |
# File 'lib/compare_linker_wrapper/linker.rb', line 71 def logger ::CompareLinkerWrapper.logger end |
#parse(lock_file) ⇒ Object
75 76 77 |
# File 'lib/compare_linker_wrapper/linker.rb', line 75 def parse(lock_file) Bundler::LockfileParser.new(lock_file) end |