Skip to content

Commit

Permalink
Merge pull request #6 from saadmk11/private-repo-support
Browse files Browse the repository at this point in the history
Added Support For Private Repositories
  • Loading branch information
saadmk11 authored Sep 3, 2020
2 parents b7f722a + c48ad54 commit 977627c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Put this inside your ``.github/workflows/workflow.yml`` file:
# you can use secrets for it as well
USERNAME: 'test'
EMAIL: '[email protected]'
# optional only required for ``private`` repositories
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
```
Expand Down
26 changes: 22 additions & 4 deletions scripts/changelog-ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@

class ChangelogCI:

def __init__(self, repository, event_path, filename='CHANGELOG.md'):
def __init__(
self, repository,
event_path, filename='CHANGELOG.md',
token=None
):
self.repository = repository
self.event_path = event_path
self.filename = filename
self.token = token

def _pull_request_title(self):
title = ''
Expand All @@ -23,14 +28,26 @@ def _pull_request_title(self):

return title

def _get_request_headers(self):
headers = {
'Accept': 'application/vnd.github.v3+json'
}

if self.token:
headers.update({
'authorization': 'Bearer {token}'.format(token=self.token)
})

return headers

def _get_latest_release_date(self):
url = (
'https://api.github.com/repos/{repo_name}/releases/latest'
).format(repo_name=self.repository)

published_date = ''

response = requests.get(url)
response = requests.get(url, headers=self._get_request_headers())

if response.status_code == 200:
response_data = response.json()
Expand Down Expand Up @@ -87,7 +104,7 @@ def _get_pull_requests_after_last_release(self):
merged_date_filter=merged_date_filter
)

response = requests.get(url)
response = requests.get(url, headers=self._get_request_headers())

if response.status_code == 200:
response_data = response.json()
Expand Down Expand Up @@ -160,6 +177,7 @@ def write_changelog(self):
event_path = os.environ['GITHUB_EVENT_PATH']
repository = os.environ['GITHUB_REPOSITORY']
filename = os.environ['INPUT_CHANGELOG_FILENAME']
token = os.environ.get('GITHUB_TOKEN')

ci = ChangelogCI(repository, event_path, filename=filename)
ci = ChangelogCI(repository, event_path, filename=filename, token=token)
ci.write_changelog()

0 comments on commit 977627c

Please sign in to comment.