From 616a9a1f21ffac9b93e427744581318ea3a658a5 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Fri, 1 Jul 2022 17:18:14 +0200 Subject: [PATCH] [IMP] ocabot merge : check line in migration issue --- src/oca_github_bot/tasks/merge_bot.py | 13 +++++++++++++ src/oca_github_bot/tasks/migration_issue_bot.py | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/src/oca_github_bot/tasks/merge_bot.py b/src/oca_github_bot/tasks/merge_bot.py index 4d1d2f6d..3108b794 100644 --- a/src/oca_github_bot/tasks/merge_bot.py +++ b/src/oca_github_bot/tasks/merge_bot.py @@ -27,6 +27,11 @@ 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 ( + _create_or_find_branch_milestone, + _find_issue, + _check_line_issue +) _logger = getLogger(__name__) @@ -186,6 +191,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, @@ -200,6 +206,13 @@ 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 + milestone = _create_or_find_branch_milestone(gh_repo, target_branch) + migration_issue = _find_issue(gh_repo, milestone, target_branch) + if migration_issue: + lines = _check_line_issue(gh_pr, migration_issue) + migration_issue.edit(body="\n".join(lines)) return True diff --git a/src/oca_github_bot/tasks/migration_issue_bot.py b/src/oca_github_bot/tasks/migration_issue_bot.py index 7d75334a..e54335db 100644 --- a/src/oca_github_bot/tasks/migration_issue_bot.py +++ b/src/oca_github_bot/tasks/migration_issue_bot.py @@ -28,6 +28,15 @@ def _find_issue(gh_repo, milestone, target_branch): break return issue +def _check_line_issue(gh_pr, issue): + lines = [] + regex = r"\#%s\b" % gh_pr.number + for line in issue.body.split("\n"): + if re.findall(regex, line): + lines.append(line[:3] + "x" + line[4:]) + break + lines.append(line) + return lines def _set_lines_issue(gh_pr, issue, module): lines = []