Skip to content

Commit d0d886b

Browse files
committed
Add remote-changelog option
1 parent 7df7954 commit d0d886b

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Nothing right now.
1212
## [1.3.0] - 2020-09-07
1313

1414
- Added a `--limit` option to only sync recent versions by default in a GitHub Action
15+
- Added a `--remote-changelog` option so you don't have to have the CHANGELOG file (or cloned repo) to use changerelease
1516

1617
## [1.2.0] - 2020-09-06
1718

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ inputs:
1414
limit:
1515
description: 'Limit syncing to the latest X versions'
1616
default: 5
17+
remote_changelog:
18+
description: 'Get the CHANGELOG using the GitHub API (does not require a cloned repo)'
19+
default: true
1720
runs:
1821
using: docker
1922
image: Dockerfile
@@ -22,4 +25,5 @@ runs:
2225
CR_TAG_PREFIX: ${{ inputs.tag_prefix }}
2326
CR_NO_TAG_PREFIX: ${{ inputs.tag_prefix == '' }}
2427
CR_LIMIT: ${{ inputs.limit }}
28+
CR_REMOTE_CHANGELOG: ${{ inputs.remote_changelog }}
2529
GITHUB_TOKEN: ${{ inputs.github_token }}

changerelease/changelog.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66

77
class Changelog:
8-
def __init__(self, path):
8+
def __init__(self, path, contents):
99
self.path = path
10-
with open(self.path, "r") as f:
11-
self.contents = f.read()
12-
10+
self.contents = contents
1311
self.versions = self.parse_versions()
1412

1513
def parse_versions(self):

changerelease/cli.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import base64
34

45
import requests
56
import click
@@ -18,10 +19,10 @@ def cli():
1819
@click.option(
1920
"--changelog",
2021
default="CHANGELOG.md",
21-
type=click.Path(exists=True, file_okay=True, dir_okay=False),
2222
show_default=True,
2323
envvar="CR_CHANGELOG",
2424
)
25+
@click.option("--remote-changelog", is_flag=True, envvar="CR_REMOTE_CHANGELOG")
2526
@click.option("--tag-prefix", default="v", show_default=True, envvar="CR_TAG_PREFIX")
2627
@click.option("--no-tag-prefix", default=False, is_flag=True, envvar="CR_NO_TAG_PREFIX")
2728
@click.option("--repo", envvar="GITHUB_REPOSITORY", required=True)
@@ -32,7 +33,9 @@ def cli():
3233
)
3334
@click.option("--limit", default=-1, envvar="CR_LIMIT")
3435
@click.option("--token", envvar="GITHUB_TOKEN", required=True)
35-
def sync(changelog, tag_prefix, no_tag_prefix, repo, api_url, limit, token):
36+
def sync(
37+
changelog, remote_changelog, tag_prefix, no_tag_prefix, repo, api_url, limit, token
38+
):
3639
if no_tag_prefix:
3740
tag_prefix = ""
3841

@@ -44,7 +47,18 @@ def sync(changelog, tag_prefix, no_tag_prefix, repo, api_url, limit, token):
4447
}
4548
)
4649

47-
cl = Changelog(changelog)
50+
if remote_changelog:
51+
click.echo(f"Fetching current {changelog} from the {repo} repo")
52+
response = requests_session.get(f"/repos/{repo}/contents/{changelog}")
53+
response.raise_for_status()
54+
changelog_contents = base64.b64decode(response.json()["content"]).decode(
55+
"utf-8"
56+
)
57+
else:
58+
with open(changelog, "r") as f:
59+
changelog_contents = f.read()
60+
61+
cl = Changelog(changelog, changelog_contents)
4862

4963
outline = "-" * 80
5064

0 commit comments

Comments
 (0)