11import os
22import re
3+ import base64
34
45import requests
56import 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