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

Added Support For Private Repositories #6

Merged
merged 3 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
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
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()