Skip to content

Commit 283bb17

Browse files
committed
update merge_changelogs to only fetch changelogs of satellite projects
1 parent 3cf6e66 commit 283bb17

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

doc/source/merge_changelogs.py

+22-33
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,49 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
"""
4-
Append release notes from other projects of the larray-project constellation to the current changelog
3+
Fetch release notes from satellite projects of the larray-project constellation to the main project
54
"""
65

7-
import os
8-
import requests
9-
10-
from releaser import relname2fname
6+
from pathlib import Path
117

8+
import requests
9+
from releaser import relname2fname, doechocall, echocall, short, no
1210

1311
# TODO: add Eurostat project
14-
LARRAY_GITHUB_REP = "https://github.com/larray-project/larray"
1512
EDITOR_GITHUB_REP = "https://github.com/larray-project/larray-editor"
1613

1714

18-
def include_changelogs(section_name, release_name, github_rep, rel_changes_dir='/doc/source/changes',
19-
branch='master', reset=False):
20-
changelog_file = relname2fname(release_name)
15+
def fetch_changelog(section_name, release_name, github_rep, rel_changes_dir='/doc/source/changes', branch='master'):
16+
fname = relname2fname(release_name)
2117

2218
# get changelog file content from github repository
23-
url = github_rep.replace('github.com', 'raw.githubusercontent.com') \
24-
+ '/{}/{}/'.format(branch, rel_changes_dir) + changelog_file
19+
url = github_rep.replace('github.com', 'raw.githubusercontent.com') + f'/{branch}/{rel_changes_dir}/{fname}'
2520
req = requests.get(url)
2621
if req.status_code != requests.codes.ok:
27-
raise ValueError("Content at URL {} could not been found.".format(url))
28-
github_changelog = req.text
29-
30-
# append to local changelog file
31-
changelog_file = os.path.abspath(os.path.join('.', 'changes', changelog_file))
32-
with open(changelog_file) as f:
33-
content = f.read() if not reset else ''
34-
with open(changelog_file, 'w', encoding="utf-8") as f:
35-
new_section = """
22+
raise ValueError(f"Content at URL {url} could not be found.")
23+
# save in local directory
24+
fpath = Path('.') / 'changes' / section_name / fname
25+
fpath.write_text(req.text, encoding="utf-8")
3626

37-
{section_name}
38-
{underline}
27+
doechocall('Adding', ['git', 'add', str(fpath)])
28+
doechocall('Committing',
29+
['git', 'commit', '-m', f'fetched {section_name} changelog for {short(release_name)}', str(fpath)])
3930

40-
""".format(section_name=section_name.upper(), underline='-' * len(section_name))
41-
content += new_section
42-
content += github_changelog
43-
f.write(content)
4431

32+
def fetch_changelogs(release_name):
33+
fetch_changelog('editor', release_name, EDITOR_GITHUB_REP)
4534

46-
def merge_changelogs(release_name):
47-
include_changelogs('CORE', release_name, LARRAY_GITHUB_REP, reset=True)
48-
include_changelogs('EDITOR', release_name, EDITOR_GITHUB_REP)
35+
print(echocall(['git', 'log', 'upstream/master..HEAD']))
36+
if no('Are the above commits ready to be pushed?'):
37+
doechocall('Pushing changes to GitHub',
38+
['git', 'push', 'upstream', 'master', '--follow-tags'])
4939

5040

5141
if __name__ == '__main__':
5242
import sys
5343

5444
argv = sys.argv
5545
if len(argv) < 2:
56-
print("Usage: {} release_name".format(argv[0]))
46+
print(f"Usage: {argv[0]} release_name")
5747
sys.exit()
5848

59-
release_name = argv[1]
60-
merge_changelogs(release_name)
49+
fetch_changelogs(argv[1])

next_release.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
from releaser import add_release
77

88

9+
CHANGELOG_INDEX_TEMPLATE = """{title}
10+
{underline}
11+
12+
In development.
13+
14+
CORE
15+
----
16+
.. include:: ./changes/{fname}
17+
18+
EDITOR
19+
------
20+
.. include:: ./changes/editor/{fname}
21+
22+
23+
"""
24+
925
if __name__ == '__main__':
1026
import sys
1127

@@ -15,4 +31,5 @@
1531
sys.exit()
1632

1733
local_repository = abspath(dirname(__file__))
18-
add_release(local_repository, PACKAGE_NAME, SRC_CODE, release_name=argv[1], src_documentation=SRC_DOC)
34+
add_release(local_repository, PACKAGE_NAME, SRC_CODE, release_name=argv[1], src_documentation=SRC_DOC,
35+
changelog_index_template=CHANGELOG_INDEX_TEMPLATE)

0 commit comments

Comments
 (0)