Skip to content

Commit

Permalink
[IMP] ocabot merge : check line in migration issue
Browse files Browse the repository at this point in the history
Co-authored-by: Simone Rubino <[email protected]>
[IMP] Do not create milestone branch when merging PR
Co-authored-by: Stéphane Bidoul <[email protected]>
[pre-commit.ci] auto fixes from pre-commit.com hooks
  • Loading branch information
legalsylvain committed Apr 8, 2023
1 parent 63ffa6c commit 654a78d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions newsfragments/192.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Automaticaly check line in Migration issue when merging the according Pull Request.
8 changes: 8 additions & 0 deletions src/oca_github_bot/tasks/merge_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ..utils import hide_secrets
from ..version_branch import make_merge_bot_branch, parse_merge_bot_branch
from .main_branch_bot import main_branch_bot_actions
from .migration_issue_bot import _check_line_issue, _find_issue

_logger = getLogger(__name__)

Expand Down Expand Up @@ -186,6 +187,7 @@ def _merge_bot_merge_pr(org, repo, merge_bot_branch, cwd, dry_run=False):
_git_delete_branch("origin", merge_bot_branch, cwd=cwd)
with github.login() as gh:
gh_pr = gh.pull_request(org, repo, pr)
gh_repo = gh.repository(org, repo)
merge_sha = github.git_get_head_sha(cwd=cwd)
github.gh_call(
gh_pr.create_comment,
Expand All @@ -200,6 +202,12 @@ def _merge_bot_merge_pr(org, repo, merge_bot_branch, cwd, dry_run=False):
_logger.info(f"add {LABEL_MERGED} label to PR {gh_pr.url}")
github.gh_call(gh_issue.add_labels, LABEL_MERGED)
github.gh_call(gh_pr.close)

# Check line in migration issue if required
migration_issue = _find_issue(gh_repo, target_branch)
if migration_issue:
new_body = _check_line_issue(gh_pr.number, migration_issue.body)
migration_issue.edit(body=new_body)
return True


Expand Down
12 changes: 12 additions & 0 deletions src/oca_github_bot/tasks/migration_issue_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ def _find_issue(gh_repo, milestone, target_branch):
return issue


def _check_line_issue(gh_pr_number, issue_body):
lines = []
regex = r"\#%s\b" % gh_pr_number
for line in issue_body.split("\n"):
if re.findall(regex, line):
checked_line = line.replace("[ ]", "[x]", 1)
lines.append(checked_line)
continue
lines.append(line)
return "\n".join(lines)


def _set_lines_issue(gh_pr_user_login, gh_pr_number, issue_body, module):
lines = []
added = False
Expand Down
23 changes: 23 additions & 0 deletions tests/test_migration_issue_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from oca_github_bot.tasks.migration_issue_bot import (
_check_line_issue,
_create_or_find_branch_milestone,
_find_issue,
_set_lines_issue,
Expand Down Expand Up @@ -70,3 +71,25 @@ def test_set_lines_issue(gh):
for old_body, new_body_expected in body_transformation:
new_body, _ = _set_lines_issue(gh_pr_user_login, gh_pr_number, old_body, module)
assert new_body == new_body_expected


@pytest.mark.vcr()
def test_check_line_issue(gh):
module = "mis_builder"
gh_pr_user_login = "sbidoul"
gh_pr_number = 11

old_body = (
f"Issue with list containing the module\n"
f"- [ ] a_module_1 - By @legalsylvain - #1\n"
f"- [ ] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2"
)
new_body_expected = (
f"Issue with list containing the module\n"
f"- [ ] a_module_1 - By @legalsylvain - #1\n"
f"- [x] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2"
)
new_body = _check_line_issue(gh_pr_number, old_body)
assert new_body == new_body_expected

0 comments on commit 654a78d

Please sign in to comment.