Class: Auditor

Inherits:
Object
  • Object
show all
Defined in:
lib/carthage_audit.rb

Defined Under Namespace

Classes: Dependency

Instance Method Summary collapse

Instance Method Details

#get_list_items_from_html(html) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/carthage_audit.rb', line 34

def get_list_items_from_html(html)
  update_info = []

  d = Oga.parse_html(html)
  _ = d.css(".markdown-body").each do |n|
    n.css("ul li").each do |l|
      update_info << l.text
    end
  end

  update_info
end

#get_repo(name) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/carthage_audit.rb', line 12

def get_repo(name)
  File.open("Cartfile", "r") do |f|
    f.each_line do |line|
      next unless matches = line.match(/^github "(.*#{Regexp.quote(name)})"/)

      repo = matches[1]
      return repo
    end
  end

  "#{name}/#{name}" # repo assumed to `github.com/repo_name/repo_name`
end

#make_request(url) ⇒ Object


25
26
27
28
29
30
31
32
# File 'lib/carthage_audit.rb', line 25

def make_request(url)
  uri = URI(url)

  _ = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
    req = Net::HTTP::Get.new(uri.request_uri)
    http.request(req)
  end
end

#runObject


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/carthage_audit.rb', line 47

def run
  # TODO: replace w/ actual call to carthage outdated
  IO.popen("cat carthage_output.txt", "r") do |output|
    output.readlines.each do |line|
      next unless matches = line.match(/^(.*?) "(.*?)".*Latest: "(.*?)"/)

      name = matches[1]
      current_version = matches[2]
      new_version = matches[3]

      dep = Dependency.new(name, current_version, new_version, nil)

      next if current_version == new_version

      repo = get_repo(name)
      url = "https://github.com/#{repo}/releases/tag/#{new_version}"
      resp = make_request(url)

      next unless resp.code == "200"

      update_info_list = get_list_items_from_html(resp.body)
      dep.update_info_list = update_info_list

      yield dep
    end
  end
end