Skip to content

Commit

Permalink
Merge pull request #4 from saadmk11/handle-search-api-error
Browse files Browse the repository at this point in the history
Handle 404 while getting pull requests for a repository
  • Loading branch information
saadmk11 authored Sep 3, 2020
2 parents 6ebed89 + bab9ed1 commit b7f722a
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions scripts/changelog-ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,35 @@ def _get_pull_requests_after_last_release(self):

response = requests.get(url)

response_data = response.json()

if response_data['total_count'] > 0:
if response.status_code == 200:
response_data = response.json()

for item in response_data['items']:
data = {
'title': item['title'],
'number': item['number'],
'url': item['html_url']
}
items.append(data)
if response_data['total_count'] > 0:
for item in response_data['items']:
data = {
'title': item['title'],
'number': item['number'],
'url': item['html_url']
}
items.append(data)
else:
logger.warning(
'There was no pull request made on %s after last release.',
self.repository
)
else:
logger.error(
'GitHub API returned error response for %s, status code: %s',
self.repository, response.status_code
)

return items

def write_changelog(self):
version = self._get_version_number()

if not version:
print(
logger.warning(
'The title of the pull request is incorrect. ',
'Please use title like: '
'``release <version_number> <other_text>``'
Expand All @@ -116,8 +126,8 @@ def write_changelog(self):

items = self._get_pull_requests_after_last_release()

# exit the function if there is not pull request found
if not items:
print('There was no pull request made after last release.')
return

file_mode = self._get_file_mode()
Expand Down

0 comments on commit b7f722a

Please sign in to comment.