Class: CompareLinker

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Returns the value of attribute compare_links.



12
13
14
# File 'lib/compare_linker.rb', line 12

def compare_links
  @compare_links
end

#formatterObject

Returns the value of attribute formatter.



13
14
15
# File 'lib/compare_linker.rb', line 13

def formatter
  @formatter
end

#pr_numberObject (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_nameObject (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


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


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