Skip to content

Commit 13be841

Browse files
committed
[IMP] ocabot merge : check line in migration issue
1 parent dfc9b05 commit 13be841

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

newsfragments/192.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Automaticaly check line in Migration issue when merging the according Pull Request.

src/oca_github_bot/tasks/merge_bot.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
from ..utils import hide_secrets
2828
from ..version_branch import make_merge_bot_branch, parse_merge_bot_branch
2929
from .main_branch_bot import main_branch_bot_actions
30+
from .migration_issue_bot import (
31+
_check_line_issue,
32+
_create_or_find_branch_milestone,
33+
_find_issue,
34+
)
3035

3136
_logger = getLogger(__name__)
3237

@@ -186,6 +191,7 @@ def _merge_bot_merge_pr(org, repo, merge_bot_branch, cwd, dry_run=False):
186191
_git_delete_branch("origin", merge_bot_branch, cwd=cwd)
187192
with github.login() as gh:
188193
gh_pr = gh.pull_request(org, repo, pr)
194+
gh_repo = gh.repository(org, repo)
189195
merge_sha = github.git_get_head_sha(cwd=cwd)
190196
github.gh_call(
191197
gh_pr.create_comment,
@@ -200,6 +206,13 @@ def _merge_bot_merge_pr(org, repo, merge_bot_branch, cwd, dry_run=False):
200206
_logger.info(f"add {LABEL_MERGED} label to PR {gh_pr.url}")
201207
github.gh_call(gh_issue.add_labels, LABEL_MERGED)
202208
github.gh_call(gh_pr.close)
209+
210+
# Check line in migration issue if required
211+
milestone = _create_or_find_branch_milestone(gh_repo, target_branch)
212+
migration_issue = _find_issue(gh_repo, milestone, target_branch)
213+
if migration_issue:
214+
new_body = _check_line_issue(gh_pr.number, migration_issue.body)
215+
migration_issue.edit(body=new_body)
203216
return True
204217

205218

src/oca_github_bot/tasks/migration_issue_bot.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ def _find_issue(gh_repo, milestone, target_branch):
2929
return issue
3030

3131

32+
def _check_line_issue(gh_pr_number, issue_body):
33+
lines = []
34+
regex = r"\#%s\b" % gh_pr_number
35+
for line in issue_body.split("\n"):
36+
if re.findall(regex, line):
37+
lines.append(line[:3] + "x" + line[4:])
38+
continue
39+
lines.append(line)
40+
return "\n".join(lines)
41+
42+
3243
def _set_lines_issue(gh_pr_user_login, gh_pr_number, issue_body, module):
3344
lines = []
3445
added = False

tests/test_migration_issue_bot.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from oca_github_bot.tasks.migration_issue_bot import (
7+
_check_line_issue,
78
_create_or_find_branch_milestone,
89
_find_issue,
910
_set_lines_issue,
@@ -70,3 +71,25 @@ def test_set_lines_issue(gh):
7071
for (old_body, new_body_expected) in body_transformation:
7172
new_body, _ = _set_lines_issue(gh_pr_user_login, gh_pr_number, old_body, module)
7273
assert new_body == new_body_expected
74+
75+
76+
@pytest.mark.vcr()
77+
def test_check_line_issue(gh):
78+
module = "mis_builder"
79+
gh_pr_user_login = "sbidoul"
80+
gh_pr_number = 11
81+
82+
old_body = (
83+
f"Issue with list containing the module\n"
84+
f"- [ ] a_module_1 - By @legalsylvain - #1\n"
85+
f"- [ ] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
86+
f"- [ ] z_module_1 - By @pedrobaeza - #2"
87+
)
88+
new_body_expected = (
89+
f"Issue with list containing the module\n"
90+
f"- [ ] a_module_1 - By @legalsylvain - #1\n"
91+
f"- [x] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
92+
f"- [ ] z_module_1 - By @pedrobaeza - #2"
93+
)
94+
new_body = _check_line_issue(gh_pr_number, old_body)
95+
assert new_body == new_body_expected

0 commit comments

Comments
 (0)