|
1 | 1 | #!/usr/bin/env python3
|
2 |
| -# -*- coding: utf-8 -*- |
3 | 2 | """
|
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 |
5 | 4 | """
|
6 | 5 |
|
7 |
| -import os |
8 |
| -import requests |
9 |
| - |
10 |
| -from releaser import relname2fname |
| 6 | +from pathlib import Path |
11 | 7 |
|
| 8 | +import requests |
| 9 | +from releaser import relname2fname, doechocall, echocall, short, no |
12 | 10 |
|
13 | 11 | # TODO: add Eurostat project
|
14 |
| -LARRAY_GITHUB_REP = "https://github.com/larray-project/larray" |
15 | 12 | EDITOR_GITHUB_REP = "https://github.com/larray-project/larray-editor"
|
16 | 13 |
|
17 | 14 |
|
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) |
21 | 17 |
|
22 | 18 | # 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}' |
25 | 20 | req = requests.get(url)
|
26 | 21 | 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") |
36 | 26 |
|
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)]) |
39 | 30 |
|
40 |
| -""".format(section_name=section_name.upper(), underline='-' * len(section_name)) |
41 |
| - content += new_section |
42 |
| - content += github_changelog |
43 |
| - f.write(content) |
44 | 31 |
|
| 32 | +def fetch_changelogs(release_name): |
| 33 | + fetch_changelog('editor', release_name, EDITOR_GITHUB_REP) |
45 | 34 |
|
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']) |
49 | 39 |
|
50 | 40 |
|
51 | 41 | if __name__ == '__main__':
|
52 | 42 | import sys
|
53 | 43 |
|
54 | 44 | argv = sys.argv
|
55 | 45 | if len(argv) < 2:
|
56 |
| - print("Usage: {} release_name".format(argv[0])) |
| 46 | + print(f"Usage: {argv[0]} release_name") |
57 | 47 | sys.exit()
|
58 | 48 |
|
59 |
| - release_name = argv[1] |
60 |
| - merge_changelogs(release_name) |
| 49 | + fetch_changelogs(argv[1]) |
0 commit comments