diff --git a/CHANGELOG.md b/CHANGELOG.md index d0a70162..02c229a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Changes * [#193](https://github.com/mmozuras/pronto/issues/193): rename `pronto run --index` option to `--unstaged`. +* [#49](https://github.com/mmozuras/pronto/issues/49): Handle non-existance of GitHub pull requests gracefully ## 0.8.2 diff --git a/lib/pronto.rb b/lib/pronto.rb index 91e1afb1..eda645ac 100644 --- a/lib/pronto.rb +++ b/lib/pronto.rb @@ -5,6 +5,8 @@ require 'httparty' require 'rainbow' +require 'pronto/error' + require 'pronto/gem_names' require 'pronto/logger' diff --git a/lib/pronto/cli.rb b/lib/pronto/cli.rb index dc16f74b..39318a66 100644 --- a/lib/pronto/cli.rb +++ b/lib/pronto/cli.rb @@ -66,6 +66,8 @@ def run(path = nil) end rescue Rugged::RepositoryError puts '"pronto" should be run from a git repository' + rescue Pronto::Error => e + $stderr.puts "Pronto errored: #{e.message}" end desc 'list', 'Lists pronto runners that are available to be used' diff --git a/lib/pronto/error.rb b/lib/pronto/error.rb new file mode 100644 index 00000000..d6a7cb5a --- /dev/null +++ b/lib/pronto/error.rb @@ -0,0 +1,3 @@ +module Pronto + class Error < StandardError; end +end diff --git a/lib/pronto/github.rb b/lib/pronto/github.rb index c1138381..e7352b61 100644 --- a/lib/pronto/github.rb +++ b/lib/pronto/github.rb @@ -7,6 +7,10 @@ def pull_comments(sha) comment.position || comment.original_position) end end + rescue Octokit::NotFound => e + @config.logger.log("Error raised and rescued: #{e}") + msg = "Pull request for sha #{sha} with id #{pull_id} was not found." + raise Pronto::Error, msg end def commit_comments(sha) diff --git a/spec/pronto/github_spec.rb b/spec/pronto/github_spec.rb index e6d45486..afe4af4d 100644 --- a/spec/pronto/github_spec.rb +++ b/spec/pronto/github_spec.rb @@ -66,6 +66,16 @@ module Pronto subject end end + + context 'pull request does not exist' do + specify do + Octokit::Client.any_instance + .should_receive(:pull_comments) + .and_raise(Octokit::NotFound) + + -> { subject }.should raise_error(Pronto::Error) + end + end end describe '#create_commit_status' do