Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 404 while getting pull requests for a repository #4

Merged
merged 2 commits into from
Sep 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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