Skip to content

Commit 47ec699

Browse files
committed
Fixed error handling in request create
1 parent 5bee5d5 commit 47ec699

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

git_repo/services/ext/github.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ def request_create(self, user, repo, local_branch, remote_branch, title, descrip
149149
repository = self.gh.repository(user, repo)
150150
if not repository:
151151
raise ResourceNotFoundError('Could not find repository `{}/{}`!'.format(user, repo))
152-
if not local_branch:
153-
remote_branch = self.repository.active_branch.name or self.repository.active_branch.name
154152
if not remote_branch:
153+
remote_branch = self.repository.active_branch.name
154+
if not local_branch:
155155
local_branch = repository.master_branch or 'master'
156156
try:
157157
request = repository.create_pull(title,
@@ -160,15 +160,12 @@ def request_create(self, user, repo, local_branch, remote_branch, title, descrip
160160
body=description)
161161
except github3.models.GitHubError as err:
162162
if err.code == 422:
163-
for error in err.errors:
164-
if 'message' in error:
165-
if 'No commits' in error['message']:
163+
if err.message == 'Validation Failed':
164+
for error in err.errors:
165+
if 'message' in error:
166166
raise ResourceError(error['message'])
167-
else:
168-
if 'message' in error:
169-
raise ResourceError(error['message'])
170-
raise ResourceError("Unhandled formatting error: {}".format(err.errors))
171-
167+
raise ResourceError("Unhandled formatting error: {}".format(err.errors))
168+
raise ResourceError(err.message)
172169

173170
return {'local': local_branch, 'remote': remote_branch, 'ref': request.number}
174171

0 commit comments

Comments
 (0)