Skip to content

Commit

Permalink
Merge pull request #2 from saadmk11/fix-release-date
Browse files Browse the repository at this point in the history
Handle release not found issue
  • Loading branch information
saadmk11 authored Sep 3, 2020
2 parents 48f9f5f + f535a92 commit 6ebed89
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions scripts/changelog-ci.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import json
import logging
import os

import requests


logger = logging.getLogger(__name__)


class ChangelogCI:

def __init__(self, repository, event_path, filename='CHANGELOG.md'):
Expand All @@ -24,11 +28,18 @@ def _get_latest_release_date(self):
'https://api.github.com/repos/{repo_name}/releases/latest'
).format(repo_name=self.repository)

response = requests.get(url)
published_date = ''

response_data = response.json()
response = requests.get(url)

published_date = response_data['published_at']
if response.status_code == 200:
response_data = response.json()
published_date = response_data['published_at']
else:
logger.warning(
'Could not find any release for %s, status code: %s',
self.repository, response.status_code
)

return published_date

Expand Down Expand Up @@ -56,17 +67,24 @@ def _get_pull_requests_after_last_release(self):

previous_release_date = self._get_latest_release_date()

if previous_release_date:
merged_date_filter = 'merged:>=' + previous_release_date
else:
# if there is no release for the repo then
# do not filter by merged date
merged_date_filter = ''

url = (
'https://api.github.com/search/issues'
'?q=repo:{repo_name}'
'+is:pr+'
'?q=repo:{repo_name}+'
'is:pr+'
'is:merged+'
'sort:author-date-asc+'
'merged:>={date}'
'{merged_date_filter}'
'&sort=merged'
).format(
repo_name=self.repository,
date=previous_release_date
merged_date_filter=merged_date_filter
)

response = requests.get(url)
Expand Down

0 comments on commit 6ebed89

Please sign in to comment.