Skip to content

Commit

Permalink
update merge_changelogs to only fetch changelogs of satellite projects
Browse files Browse the repository at this point in the history
  • Loading branch information
gdementen committed Nov 16, 2019
1 parent 3cf6e66 commit 283bb17
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
55 changes: 22 additions & 33 deletions doc/source/merge_changelogs.py
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])
19 changes: 18 additions & 1 deletion next_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
from releaser import add_release


CHANGELOG_INDEX_TEMPLATE = """{title}
{underline}
In development.
CORE
----
.. include:: ./changes/{fname}
EDITOR
------
.. include:: ./changes/editor/{fname}
"""

if __name__ == '__main__':
import sys

Expand All @@ -15,4 +31,5 @@
sys.exit()

local_repository = abspath(dirname(__file__))
add_release(local_repository, PACKAGE_NAME, SRC_CODE, release_name=argv[1], src_documentation=SRC_DOC)
add_release(local_repository, PACKAGE_NAME, SRC_CODE, release_name=argv[1], src_documentation=SRC_DOC,
changelog_index_template=CHANGELOG_INDEX_TEMPLATE)

0 comments on commit 283bb17

Please sign in to comment.