Class: CompareLinker

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins/bundle/update/pr.rb

Defined Under Namespace

Classes: LockfileFetcher

Instance Method Summary collapse

Instance Method Details



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
44
45
46
47
48
49
50
# File 'lib/jenkins/bundle/update/pr.rb', line 9

def make_compare_links
  if octokit.pull_request_files(repo_full_name, pr_number).find do |resource|
    resource.filename == 'config/Gemfile.lock' || resource.filename == 'Gemfile.lock'
  end
    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