From 99e3e527b7f38a3345fd66ba7b05c341fffbf8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Tue, 24 Mar 2020 19:35:34 +0100 Subject: [PATCH] [ADD] merge bot: towncrier support --- Dockerfile | 4 ++- README.rst | 4 +-- environment.sample | 2 +- newsfragments/106.feature | 2 ++ src/oca_github_bot/tasks/merge_bot.py | 37 +++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 newsfragments/106.feature diff --git a/Dockerfile b/Dockerfile index cb8355ce..4d409338 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,11 +21,13 @@ RUN set -x \ RUN set -x \ && python3 -m venv /ocamt \ && /ocamt/bin/pip install wheel +# TODO update sha to get oca-towncrier RUN set -x \ && /ocamt/bin/pip install -e git+https://github.com/OCA/maintainer-tools@5dbc86310d80229ef0f2f5851933414be719308b#egg=oca-maintainers-tools \ && ln -s /ocamt/bin/oca-gen-addons-table /usr/local/bin/ \ && ln -s /ocamt/bin/oca-gen-addon-readme /usr/local/bin/ \ - && ln -s /ocamt/bin/oca-gen-addon-icon /usr/local/bin/ + && ln -s /ocamt/bin/oca-gen-addon-icon /usr/local/bin/ \ + && ln -s /ocamt/bin/oca-towncrier /usr/local/bin/ RUN set -x \ && /ocamt/bin/pip install setuptools-odoo>=2.5.0 \ && ln -s /ocamt/bin/setuptools-odoo-make-default /usr/local/bin/ diff --git a/README.rst b/README.rst index 9b124c64..3ae4a4d2 100644 --- a/README.rst +++ b/README.rst @@ -74,8 +74,8 @@ can be used to ask the bot to the following: * run the main branch operations (see above) on it * optionally bump the version number of the addons modified by the PR * merge when tests on the rebased branch are green -* when the version was bumped, generate a wheel and rsync it to the PEP 503 - simple index +* when the version was bumped, udate the changelog with ``oca-towncrier``, + generate a wheel and rsync it to the PEP 503 simple index TODO (help wanted) ------------------ diff --git a/environment.sample b/environment.sample index 1bf5638c..d90720e0 100644 --- a/environment.sample +++ b/environment.sample @@ -34,7 +34,7 @@ ODOO_PASSWORD= # Available tasks: # delete_branch,tag_approved,tag_ready_to_merge,gen_addons_table, # gen_addons_readme,gen_addons_icon,setuptools_odoo,mention_maintainer, -# merge_bot,tag_needs_review +# merge_bot,merge_bot_towncrier,tag_needs_review #BOT_TASKS=all # Root of the PEP 503 simple index where wheels are published diff --git a/newsfragments/106.feature b/newsfragments/106.feature new file mode 100644 index 00000000..0107126f --- /dev/null +++ b/newsfragments/106.feature @@ -0,0 +1,2 @@ +Make the "ocabot merge" command update ``HISTORY.rst`` from news fragments in +``readme/newsfragments`` using `towncrier `_. diff --git a/src/oca_github_bot/tasks/merge_bot.py b/src/oca_github_bot/tasks/merge_bot.py index bace3ac8..70f43f90 100644 --- a/src/oca_github_bot/tasks/merge_bot.py +++ b/src/oca_github_bot/tasks/merge_bot.py @@ -15,6 +15,8 @@ ) from ..manifest import ( bump_manifest_version, + bump_version, + get_manifest, git_modified_addon_dirs, is_addon_dir, is_maintainer, @@ -55,6 +57,30 @@ def _get_merge_bot_intro_message(): return MERGE_BOT_INTRO_MESSAGES[i] +@switchable("merge_bot_towncrier") +def _merge_bot_towncrier(org, repo, target_branch, addon_dirs, bumpversion_mode, cwd): + for addon_dir in addon_dirs: + # Run oca-towncrier: this updates and git add readme/HISTORY.rst + # if readme/newsfragments contains files and does nothing otherwise. + _logger.info(f"oca-towncrier {org}/{repo}@{target_branch} for {addon_dirs}") + version = bump_version(get_manifest(addon_dir)["version"], bumpversion_mode) + check_call( + [ + "oca-towncrier", + "--org", + org, + "--repo", + repo, + "--addon-dir", + addon_dir, + "--version", + version, + "--commit", + ], + cwd=cwd, + ) + + def _merge_bot_merge_pr(org, repo, merge_bot_branch, cwd, dry_run=False): pr, target_branch, username, bumpversion_mode = parse_merge_bot_branch( merge_bot_branch @@ -103,6 +129,17 @@ def _merge_bot_merge_pr(org, repo, merge_bot_branch, cwd, dry_run=False): d for d in modified_addon_dirs if is_addon_dir(d, installable_only=True) ] + # update HISTORY.rst using towncrier, before generating README.rst + if bumpversion_mode: + _merge_bot_towncrier( + org, + repo, + target_branch, + modified_installable_addon_dirs, + bumpversion_mode, + cwd, + ) + if modified_addon_dirs: # this includes setup.py and README.rst generation main_branch_bot_actions(org, repo, target_branch, cwd=cwd)