From f444f84dfa7f5719bbaf8d06abb9241c0a43e786 Mon Sep 17 00:00:00 2001 From: saad Date: Thu, 3 Sep 2020 18:28:23 +0600 Subject: [PATCH 1/2] Handle search API error --- scripts/changelog-ci.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/scripts/changelog-ci.py b/scripts/changelog-ci.py index f636466..a484058 100644 --- a/scripts/changelog-ci.py +++ b/scripts/changelog-ci.py @@ -89,17 +89,27 @@ 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 @@ -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() From bab9ed1e0f322b114439d8913e1271d158c52f6e Mon Sep 17 00:00:00 2001 From: saad Date: Thu, 3 Sep 2020 18:35:59 +0600 Subject: [PATCH 2/2] use log instead of print --- scripts/changelog-ci.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/changelog-ci.py b/scripts/changelog-ci.py index a484058..0234ccf 100644 --- a/scripts/changelog-ci.py +++ b/scripts/changelog-ci.py @@ -117,7 +117,7 @@ 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 ``'