Skip to content

Commit 851dc0a

Browse files
committed
Add merging label while merging a PR
Closes OCA#73
1 parent 9aa5fdc commit 851dc0a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/oca_github_bot/tasks/merge_bot.py

+20
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
_logger = getLogger(__name__)
2929

3030
LABEL_MERGED = "merged 🎉"
31+
LABEL_MERGING = "bot is merging ⏳"
3132

3233

3334
class MergeStrategy(Enum):
@@ -53,6 +54,17 @@ def _git_delete_branch(remote, branch):
5354
raise
5455

5556

57+
def _remove_merging_label(github, gh_pr, dry_run=False):
58+
gh_issue = github.gh_call(gh_pr.issue)
59+
labels = [l.name for l in gh_issue.labels()]
60+
if LABEL_MERGING in labels:
61+
if dry_run:
62+
_logger.info(f"DRY-RUN remove {LABEL_MERGING} label from PR {gh_pr.url}")
63+
else:
64+
_logger.info(f"remove {LABEL_MERGING} label from PR {gh_pr.url}")
65+
github.gh_call(gh_issue.remove_label, LABEL_MERGING)
66+
67+
5668
def _get_merge_bot_intro_message():
5769
i = random.randint(0, len(MERGE_BOT_INTRO_MESSAGES) - 1)
5870
return MERGE_BOT_INTRO_MESSAGES[i]
@@ -132,6 +144,7 @@ def _merge_bot_merge_pr(org, repo, merge_bot_branch, dry_run=False):
132144
f"Thanks a lot for contributing to {org}. ❤️",
133145
)
134146
gh_issue = github.gh_call(gh_pr.issue)
147+
_remove_merging_label(github, gh_pr, dry_run=dry_run)
135148
if dry_run:
136149
_logger.info(f"DRY-RUN add {LABEL_MERGED} label to PR {gh_pr.url}")
137150
else:
@@ -261,6 +274,10 @@ def merge_bot_start(
261274
f"of exception {e}.",
262275
)
263276
raise
277+
else:
278+
gh_issue = github.gh_call(gh_pr.issue)
279+
_logger.info(f"add {LABEL_MERGED} label to PR {gh_pr.url}")
280+
github.gh_call(gh_issue.add_labels, LABEL_MERGING)
264281

265282

266283
def _get_commit_success(gh_commit):
@@ -332,13 +349,15 @@ def merge_bot_status(org, repo, merge_bot_branch, sha):
332349
f"finalized, because "
333350
f"command `{cmd}` failed with output:\n```\n{e.output}\n```",
334351
)
352+
_remove_merging_label(github, gh_pr)
335353
raise
336354
except Exception as e:
337355
github.gh_call(
338356
gh_pr.create_comment,
339357
f"@{username} The merge process could not be "
340358
f"finalized because an exception was raised: {e}.",
341359
)
360+
_remove_merging_label(github, gh_pr)
342361
raise
343362
else:
344363
github.gh_call(
@@ -352,3 +371,4 @@ def merge_bot_status(org, repo, merge_bot_branch, sha):
352371
f"make the target branch red.",
353372
)
354373
_git_call(["git", "push", "origin", f":{merge_bot_branch}"])
374+
_remove_merging_label(github, gh_pr)

0 commit comments

Comments
 (0)