Repository: OCA/oca-github-bot

Issue:
ocabot migration duplicating lines in migration issue?
See for example https://github.com/OCA/server-env/issues/120 where the issue was created correctly but now lines with references to a PR are duplicated.

Discussion:

Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 7bc5bf2..4929ad8 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -2,7 +2,7 @@ default_language_version:
   python: python3
 repos:
 - repo: https://github.com/psf/black
-  rev: 22.10.0
+  rev: 22.8.0
   hooks:
   - id: black
 - repo: https://github.com/pre-commit/pre-commit-hooks
@@ -34,7 +34,7 @@ repos:
     args: [--extend-ignore=F401]  # ignore imported unused in __init__.py
     files: __init__.py
 - repo: https://github.com/asottile/pyupgrade
-  rev: v3.1.0
+  rev: v2.38.2
   hooks:
   - id: pyupgrade
 - repo: https://github.com/asottile/seed-isort-config
diff --git a/setup.py b/setup.py
index 7b54b1c..c7c4210 100644
--- a/setup.py
+++ b/setup.py
@@ -1,9 +1,10 @@
+import io
 import os
 
 from setuptools import find_packages, setup
 
 here = os.path.abspath(os.path.dirname(__file__))
-with open(os.path.join(here, "README.rst"), encoding="utf-8") as f:
+with io.open(os.path.join(here, "README.rst"), encoding="utf-8") as f:
     long_description = f.read()
 
 
diff --git a/src/oca_github_bot/manifest.py b/src/oca_github_bot/manifest.py
index 41b9a1e..77d1c09 100644
--- a/src/oca_github_bot/manifest.py
+++ b/src/oca_github_bot/manifest.py
@@ -92,7 +92,7 @@ def get_manifest(addon_dir):
 
 def set_manifest_version(addon_dir, version):
     manifest_path = get_manifest_path(addon_dir)
-    with open(manifest_path) as f:
+    with open(manifest_path, "r") as f:
         manifest = f.read()
     manifest = MANIFEST_VERSION_RE.sub(r"\g<pre>" + version + r"\g<post>", manifest)
     with open(manifest_path, "w") as f:
diff --git a/src/oca_github_bot/tasks/migration_issue_bot.py b/src/oca_github_bot/tasks/migration_issue_bot.py
index 510c435..b4911a7 100644
--- a/src/oca_github_bot/tasks/migration_issue_bot.py
+++ b/src/oca_github_bot/tasks/migration_issue_bot.py
@@ -39,7 +39,7 @@ def _set_lines_issue(gh_pr_user_login, gh_pr_number, issue_body, module):
         if added:  # Bypass the checks for faster completion
             lines.append(line)
             continue
-        groups = re.match(rf"^- \[( |x)\] {module}( |\r)", line)
+        groups = re.match(rf"^- \[( |x)\] \b{module}\b", line)
         if groups:  # Line found
             # Get the Old PR value
             regex = r"\#(\d*)"


Test patch:
diff --git a/tests/test_migration_issue_bot.py b/tests/test_migration_issue_bot.py
index 1cd703d..5ace8f7 100644
--- a/tests/test_migration_issue_bot.py
+++ b/tests/test_migration_issue_bot.py
@@ -53,6 +53,14 @@ def test_set_lines_issue(gh):
             f"- [x] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
             f"- [ ] z_module_1 - By @pedrobaeza - #2",
         ),
+        (
+            f"Issue with list containing the module with no PR\n"
+            f"- [x] {module}\n"
+            f"- [ ] z_module_1 - By @pedrobaeza - #2",
+            f"Issue with list containing the module with no PR\n"
+            f"- [x] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
+            f"- [ ] z_module_1 - By @pedrobaeza - #2",
+        ),
         (
             "Issue with no list",
             f"Issue with no list\n"