Unverified Commit b4d58574 authored by Orta Therox's avatar Orta Therox Committed by Samuel Giddins

[GH Inspector] Initial work on integrating gh-issues-inspector

Update to use the latest GHInspector

Fix the API urls for the gh-inspector
parent a3af2554
......@@ -107,8 +107,14 @@ PATH
cocoapods-try (>= 1.0.0, < 2.0)
colored (~> 1.2)
escape (~> 0.0.4)
<<<<<<< HEAD
fourflusher (~> 1.0.1)
=======
fourflusher (~> 0.3.0)
gh_inspector (~> 1.0)
>>>>>>> e3c6df0... Update to use the latest GHInspector
molinillo (~> 0.5.0)
gh-issues-inspector (~> 0.5.0)
nap (~> 1.0)
xcodeproj (>= 1.1.0, < 2.0)
......@@ -151,6 +157,7 @@ GEM
ffi (1.9.6)
fourflusher (1.0.1)
fuzzy_match (2.0.4)
gh_inspector (1.0.2)
git (1.3.0)
i18n (0.7.0)
inch (0.7.0)
......
......@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'colored', '~> 1.2'
s.add_runtime_dependency 'escape', '~> 0.0.4'
s.add_runtime_dependency 'fourflusher', '~> 1.0.1'
s.add_runtime_dependency 'gh_inspector', '~> 1.0'
s.add_runtime_dependency 'nap', '~> 1.0'
s.add_development_dependency 'bacon', '~> 1.1'
......
......@@ -62,6 +62,7 @@ module Pod
else
if ENV['COCOA_PODS_ENV'] != 'development'
puts UI::ErrorReport.report(exception)
UI::ErrorReport.search_for_exceptions(exception)
exit 1
else
raise exception
......
require 'cocoapods/user_interface/error_report'
require 'cocoapods/user_interface/inspector_reporter'
module Pod
# Provides support for UI output. It provides support for nested sections of
......
......@@ -2,6 +2,7 @@
require 'rbconfig'
require 'cgi'
require 'gh_inspector'
module Pod
module UserInterface
......@@ -112,6 +113,12 @@ EOS
EOS
end
def search_for_exceptions(exception)
inspector = GhInspector::Inspector.new "cocoapods", "cocoapods"
message_delegate = UserInterface::InspectorReporter.new
inspector.search_exception exception, message_delegate
end
private
def `(other)
......
require 'uri'
module Pod
module UserInterface
# Redirects GH-issues delegate callbacks to CocoaPods UI methods.
#
class InspectorReporter
# Called just as the investigation has begun.
def inspector_started_query(query, inspector)
UI.puts "Looking for related issues on #{inspector.repo_owner}/#{inspector.repo_name}..."
end
# Called once the inspector has recieved a report with more than one issue.
def inspector_successfully_recieved_report(report, inspector)
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
# Called once the report has been recieved, but when there are no issues found.
def inspector_recieved_empty_report(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
# Called when there have been networking issues in creating the report.
def inspector_could_not_create_report(error, query, inspector)
safe_query = 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
private
def print_issue_full(issue)
safe_url = 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
# Taken from http://stackoverflow.com/questions/195740/how-do-you-do-relative-time-in-rails
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
end
end
end
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,7 +3,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Command::Install do
it 'tells the user that no Podfile or podspec was found in the project dir' do
exception = lambda { run_command('install', '--no-repo-update') }.should.raise Informative
exception = lambda { run_command('install') }.should.raise Informative
exception.message.should.include "No `Podfile' found in the project directory."
end
......
......@@ -110,6 +110,37 @@ EOS
message = remove_color(message)
message.should == '[!] at -'
end
it "handles inspector_successfully_recieved_report" do
time = Time.new(2016, 5, 13)
Time.stubs(:now).returns(time)
url = 'https://api.github.com/search/issues?q=Testing+repo:cocoapods/cocoapods'
fixture_json_text = File.read SpecHelper.fixture("github_search_response.json")
GhInspector::Sidekick.any_instance.expects(:get_api_results).with(url).returns(JSON.parse(fixture_json_text))
error = NameError.new("Testing", "orta")
@report.search_for_exceptions error
result = <<-EOS
Looking for related issues on cocoapods/cocoapods...
- Travis CI with Ruby 1.9.x fails for recent pull requests
https://github.com/CocoaPods/CocoaPods/issues/646 [closed] [8 comments]
14 Nov 2012
- pod search --full chokes on cocos2d.podspec:14
https://github.com/CocoaPods/CocoaPods/issues/657 [closed] [1 comment]
20 Nov 2012
- about pod
https://github.com/CocoaPods/CocoaPods/issues/4345 [closed] [21 comments]
2 weeks ago
and 30 more at:
https://github.com/cocoapods/cocoapods/search?q=Testing&type=Issues&utf8=✓
EOS
UI.output.should == result
end
end
end
end
require File.expand_path('../../../spec_helper', __FILE__)
require 'gh_inspector'
# A quiet version of Evidence, so tests don't echo
class SilentEvidence
def inspector_started_query(query, inspector); end
def inspector_is_still_investigating(query, inspector); end
def inspector_successfully_recieved_report(report, inspector); end
def inspector_recieved_empty_report(report, inspector); end
def inspector_could_not_create_report(error, query, inspector); end
end
module Pod
describe UserInterface::InspectorReporter do
it "handles inspector_started_query" do
inspector = GhInspector::Inspector.new "cocoapods", "cocoapods"
reporter = UserInterface::InspectorReporter.new
reporter.inspector_started_query("query", inspector)
UI.output.should.match /Looking for related issues on cocoapods\/cocoapods/
end
it "handles inspector_successfully_recieved_report" do
url = 'https://api.github.com/search/issues?q=Testing+repo:cocoapods/cocoapods'
fixture_json_text = File.read SpecHelper.fixture("github_search_response.json")
GhInspector::Sidekick.any_instance.expects(:get_api_results).with(url).returns(JSON.parse(fixture_json_text))
inspector = GhInspector::Inspector.new "cocoapods", "cocoapods"
report = inspector.search_query 'Testing', SilentEvidence.new
reporter = UserInterface::InspectorReporter.new
reporter.inspector_successfully_recieved_report(report, inspector)
UI.output.should.match /Travis CI with Ruby 1.9.x fails for recent pull requests/
UI.output.should.match /https:\/\/github.com\/CocoaPods\/CocoaPods\/issues\/646 \[closed\] \[8 comments\]/
UI.output.should.match /pod search --full chokes on cocos2d.podspec/
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment