Skip to content

Commit

Permalink
Merge pull request octokit#1324 from yykamei/path-diff-too-large
Browse files Browse the repository at this point in the history
Add a new error: PathDiffTooLarge
  • Loading branch information
tarebyte authored Feb 9, 2021
2 parents 6610c3e + 5ba84a2 commit d5ad4cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/octokit/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def self.error_for_404(body)
def self.error_for_422(body)
if body =~ /PullRequestReviewComment/i && body =~ /(commit_id|end_commit_oid) is not part of the pull request/i
Octokit::CommitIsNotPartOfPullRequest
elsif body =~ /Path diff too large/i
Octokit::PathDiffTooLarge
else
Octokit::UnprocessableEntity
end
Expand Down Expand Up @@ -314,6 +316,10 @@ class UnprocessableEntity < ClientError; end
# and body matches 'PullRequestReviewComment' and 'commit_id (or end_commit_oid) is not part of the pull request'
class CommitIsNotPartOfPullRequest < UnprocessableEntity; end

# Raised when GitHub returns a 422 HTTP status code and body matches 'Path diff too large'.
# It could occur when attempting to post review comments on a "too large" file.
class PathDiffTooLarge < UnprocessableEntity; end

# Raised when GitHub returns a 451 HTTP status code
class UnavailableForLegalReasons < ClientError; end

Expand Down
16 changes: 16 additions & 0 deletions spec/octokit/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,22 @@
]
}.to_json
expect { Octokit.post('/repositories/123456789/pulls/1/comments') }.to raise_error Octokit::CommitIsNotPartOfPullRequest

stub_post('/repositories/123456789/pulls/21/comments').to_return \
:status => 422,
:headers => {
:content_type => 'application/json',
},
:body => {
:message => 'Validation Failed',
:errors => [
:message => 'path diff too large',
:resource => 'PullRequestReviewComment',
:field => 'path',
:code => 'custom'
]
}.to_json
expect { Octokit.post('/repositories/123456789/pulls/21/comments') }.to raise_error Octokit::PathDiffTooLarge
end

it "raises on unknown client errors" do
Expand Down

0 comments on commit d5ad4cc

Please sign in to comment.