Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] integrate with odoo-module-migrator #53

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Installing
$ cd oca-port
$ pipx install .

To automatically apply code patterns with [odoo-module-migrator](https://github.com/OCA/odoo-module-migrator), install library with below syntax:

$ pipx install git+https://github.com/OCA/odoo-module-migrator.git@master

Using
-----

Expand Down
44 changes: 41 additions & 3 deletions oca_port/migrate_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import tempfile
import urllib.parse
import pkg_resources

import click

Expand Down Expand Up @@ -56,6 +57,15 @@
f"\t\t=> {bc.BOLD}" "{new_pr_url}" f"{bc.END}",
]
)
SIMPLIFIED_MIG_TIPS = "\n".join(
[
f"\n{bc.BOLD}{bc.OKCYAN}The next steps are:{bc.END}",
("\t1) Reduce the number of commits " f"('{bc.DIM}OCA Transbot...{bc.END}'):"),
f"\t\t=> {bc.BOLD}{MIG_MERGE_COMMITS_URL}{bc.END}",
"\t2) Create the PR against {from_org}/{repo_name}:",
f"\t\t=> {bc.BOLD}" "{new_pr_url}" f"{bc.END}",
]
)


class MigrateAddon(Output):
Expand Down Expand Up @@ -131,6 +141,7 @@ def run(self):
if self.app.repo.untracked_files:
raise click.ClickException("Untracked files detected, abort")
self._checkout_base_branch()
adapted = False
if self._create_mig_branch():
# Case where the addon shouldn't be ported (blacklisted)
if self.app.storage.dirty:
Expand All @@ -140,11 +151,14 @@ def run(self):
with tempfile.TemporaryDirectory() as patches_dir:
self._generate_patches(patches_dir)
self._apply_patches(patches_dir)
g.run_pre_commit(self.app.repo, self.app.addon)
if pkg_resources.get_distribution("odoo-module-migrator") is None:
g.run_pre_commit(self.app.repo, self.app.addon)
else:
adapted = self._apply_code_pattern()
# Check if the addon has commits that update neighboring addons to
# make it work properly
PortAddonPullRequest(self.app, push_branch=False).run()
self._print_tips()
self._print_tips(adapted=adapted)
return True, None

def _checkout_base_branch(self):
Expand Down Expand Up @@ -204,7 +218,7 @@ def _apply_patches(self, patches_dir):
f"has been migrated."
)

def _print_tips(self, blacklisted=False):
def _print_tips(self, blacklisted=False, adapted=False):
mig_tasks_url = MIG_TASKS_URL.format(version=self.app.target_version)
pr_title_encoded = urllib.parse.quote(
MIG_NEW_PR_TITLE.format(
Expand All @@ -229,6 +243,14 @@ def _print_tips(self, blacklisted=False):
)
print(tips)
return
if adapted:
tips = SIMPLIFIED_MIG_TIPS.format(
from_org=self.app.upstream_org,
repo_name=self.app.repo_name,
new_pr_url=new_pr_url,
)
print(tips)
return
tips = MIG_TIPS.format(
from_org=self.app.upstream_org,
repo_name=self.app.repo_name,
Expand All @@ -240,3 +262,19 @@ def _print_tips(self, blacklisted=False):
new_pr_url=new_pr_url,
)
print(tips)

def _apply_code_pattern(self):
print("Apply code pattern...")
from odoo_module_migrate.migration import Migration

try:
migration = Migration(
self.app.addons_rootdir,
self.app.source_version,
self.app.target_version,
[self.app.addon],
)
migration.run()
return True
except KeyboardInterrupt:
pass
Loading