Class: Pod::UserInterface::InspectorReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/user_interface/inspector_reporter.rb

Overview

Redirects GH-issues delegate callbacks to CocoaPods UI methods.

Instance Method Summary collapse

Instance Method Details

#inspector_could_not_create_report(error, query, inspector) ⇒ void

This method returns an undefined value.

Called when there have been networking issues in creating the report.

Parameters:

  • error (Error)

    The error returned during networking

  • query (String)

    The original search query

  • inspector (GhInspector::Inspector)

    The current inspector



63
64
65
66
67
68
# File 'lib/cocoapods/user_interface/inspector_reporter.rb', line 63

def inspector_could_not_create_report(error, query, inspector)
  safe_query = Addressable::URI.escape query
  UI.puts 'Could not access the GitHub API, you may have better luck via the website.'
  UI.puts "https://github.com/#{inspector.repo_owner}/#{inspector.repo_name}/search?q=#{safe_query}&type=Issues&utf8=✓"
  UI.puts "Error: #{error.name}"
end

#inspector_received_empty_report(_, inspector) ⇒ void

This method returns an undefined value.

Called once the report has been received, but when there are no issues found.

Parameters:

  • inspector (GhInspector::Inspector)

    The current inspector



45
46
47
48
# File 'lib/cocoapods/user_interface/inspector_reporter.rb', line 45

def inspector_received_empty_report(_, inspector)
  UI.puts 'Found no similar issues. To create a new issue, please visit:'
  UI.puts "https://github.com/#{inspector.repo_owner}/#{inspector.repo_name}/issues/new"
end

#inspector_started_query(_, inspector) ⇒ void

This method returns an undefined value.

Called just as the investigation has begun. Lets the user know that it's looking for an issue.

Parameters:

  • inspector (GhInspector::Inspector)

    The current inspector



17
18
19
# File 'lib/cocoapods/user_interface/inspector_reporter.rb', line 17

def inspector_started_query(_, inspector)
  UI.puts "Looking for related issues on #{inspector.repo_owner}/#{inspector.repo_name}..."
end

#inspector_successfully_received_report(report, _) ⇒ void

This method returns an undefined value.

Called once the inspector has received a report with more than one issue, showing the top 3 issues, and offering a link to see more.

Parameters:

  • report (GhInspector::InspectionReport)

    Report a list of the issues



29
30
31
32
33
34
35
36
# File 'lib/cocoapods/user_interface/inspector_reporter.rb', line 29

def inspector_successfully_received_report(report, _)
  report.issues[0..2].each { |issue| print_issue_full(issue) }

  if report.issues.count > 3
    UI.puts "and #{report.total_results - 3} more at:"
    UI.puts report.url
  end
end

#pretty_date(date_string) ⇒ Object (private)



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/cocoapods/user_interface/inspector_reporter.rb', line 81

def pretty_date(date_string)
  date = Time.parse(date_string)
  a = (Time.now - date).to_i

  case a
  when 0 then 'just now'
  when 1 then 'a second ago'
  when 2..59 then a.to_s + ' seconds ago'
  when 60..119 then 'a minute ago' # 120 = 2 minutes
  when 120..3540 then (a / 60).to_i.to_s + ' minutes ago'
  when 3541..7100 then 'an hour ago' # 3600 = 1 hour
  when 7101..82_800 then ((a + 99) / 3600).to_i.to_s + ' hours ago'
  when 82_801..172_000 then 'a day ago' # 86400 = 1 day
  when 172_001..518_400 then ((a + 800) / (60 * 60 * 24)).to_i.to_s + ' days ago'
  when 518_400..1_036_800 then 'a week ago'
  when 1_036_801..4_147_204 then ((a + 180_000) / (60 * 60 * 24 * 7)).to_i.to_s + ' weeks ago'
  else date.strftime('%d %b %Y')
  end
end


72
73
74
75
76
77
78
# File 'lib/cocoapods/user_interface/inspector_reporter.rb', line 72

def print_issue_full(issue)
  safe_url = Addressable::URI.escape issue.html_url
  UI.puts " - #{issue.title}"
  UI.puts "   #{safe_url} [#{issue.state}] [#{issue.comments} comment#{issue.comments == 1 ? '' : 's'}]"
  UI.puts "   #{pretty_date(issue.updated_at)}"
  UI.puts ''
end