Skip to content

Commit

Permalink
Handle non-existance of GitHub pull requests gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
mmozuras committed Mar 12, 2017
1 parent a425b5e commit f06f8c2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/pronto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require 'httparty'
require 'rainbow'

require 'pronto/error'

require 'pronto/gem_names'

require 'pronto/logger'
Expand Down
2 changes: 2 additions & 0 deletions lib/pronto/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions lib/pronto/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Pronto
class Error < StandardError; end
end
4 changes: 4 additions & 0 deletions lib/pronto/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions spec/pronto/github_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f06f8c2

Please sign in to comment.