-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update merge_changelogs to only fetch changelogs of satellite projects
- Loading branch information
Showing
2 changed files
with
40 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,49 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Append release notes from other projects of the larray-project constellation to the current changelog | ||
Fetch release notes from satellite projects of the larray-project constellation to the main project | ||
""" | ||
|
||
import os | ||
import requests | ||
|
||
from releaser import relname2fname | ||
from pathlib import Path | ||
|
||
import requests | ||
from releaser import relname2fname, doechocall, echocall, short, no | ||
|
||
# TODO: add Eurostat project | ||
LARRAY_GITHUB_REP = "https://github.com/larray-project/larray" | ||
EDITOR_GITHUB_REP = "https://github.com/larray-project/larray-editor" | ||
|
||
|
||
def include_changelogs(section_name, release_name, github_rep, rel_changes_dir='/doc/source/changes', | ||
branch='master', reset=False): | ||
changelog_file = relname2fname(release_name) | ||
def fetch_changelog(section_name, release_name, github_rep, rel_changes_dir='/doc/source/changes', branch='master'): | ||
fname = relname2fname(release_name) | ||
|
||
# get changelog file content from github repository | ||
url = github_rep.replace('github.com', 'raw.githubusercontent.com') \ | ||
+ '/{}/{}/'.format(branch, rel_changes_dir) + changelog_file | ||
url = github_rep.replace('github.com', 'raw.githubusercontent.com') + f'/{branch}/{rel_changes_dir}/{fname}' | ||
req = requests.get(url) | ||
if req.status_code != requests.codes.ok: | ||
raise ValueError("Content at URL {} could not been found.".format(url)) | ||
github_changelog = req.text | ||
|
||
# append to local changelog file | ||
changelog_file = os.path.abspath(os.path.join('.', 'changes', changelog_file)) | ||
with open(changelog_file) as f: | ||
content = f.read() if not reset else '' | ||
with open(changelog_file, 'w', encoding="utf-8") as f: | ||
new_section = """ | ||
raise ValueError(f"Content at URL {url} could not be found.") | ||
# save in local directory | ||
fpath = Path('.') / 'changes' / section_name / fname | ||
fpath.write_text(req.text, encoding="utf-8") | ||
|
||
{section_name} | ||
{underline} | ||
doechocall('Adding', ['git', 'add', str(fpath)]) | ||
doechocall('Committing', | ||
['git', 'commit', '-m', f'fetched {section_name} changelog for {short(release_name)}', str(fpath)]) | ||
|
||
""".format(section_name=section_name.upper(), underline='-' * len(section_name)) | ||
content += new_section | ||
content += github_changelog | ||
f.write(content) | ||
|
||
def fetch_changelogs(release_name): | ||
fetch_changelog('editor', release_name, EDITOR_GITHUB_REP) | ||
|
||
def merge_changelogs(release_name): | ||
include_changelogs('CORE', release_name, LARRAY_GITHUB_REP, reset=True) | ||
include_changelogs('EDITOR', release_name, EDITOR_GITHUB_REP) | ||
print(echocall(['git', 'log', 'upstream/master..HEAD'])) | ||
if no('Are the above commits ready to be pushed?'): | ||
doechocall('Pushing changes to GitHub', | ||
['git', 'push', 'upstream', 'master', '--follow-tags']) | ||
|
||
|
||
if __name__ == '__main__': | ||
import sys | ||
|
||
argv = sys.argv | ||
if len(argv) < 2: | ||
print("Usage: {} release_name".format(argv[0])) | ||
print(f"Usage: {argv[0]} release_name") | ||
sys.exit() | ||
|
||
release_name = argv[1] | ||
merge_changelogs(release_name) | ||
fetch_changelogs(argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters