diff --git a/pydocteur/__init__.py b/pydocteur/__init__.py index 050dae1..4da1363 100644 --- a/pydocteur/__init__.py +++ b/pydocteur/__init__.py @@ -10,6 +10,7 @@ from pydocteur.utils.pr_status import is_label_set from pydocteur.utils.pr_status import is_pr_approved from pydocteur.utils.state_actions import comment_pr +from pydocteur.utils.state_actions import merge_and_thank_contributors load_dotenv() @@ -41,7 +42,7 @@ def process_incoming_payload(): if payload["sender"]["login"] == "PyDocTeur": return "OK", 200 pr = get_pull_request(payload) - if not pr: + if not pr or pr.is_merged(): return "OK", 200 state = state_name( @@ -55,7 +56,7 @@ def process_incoming_payload(): print("State has not changed, ignoring event.") return "OK", 200 state_dict = { - "automerge_approved": comment_pr + "automerge_approved_testok": merge_and_thank_contributors, # ... } state_dict.get(state, comment_pr)(state=state, pr=pr) diff --git a/pydocteur/utils/state_actions.py b/pydocteur/utils/state_actions.py index da0fa64..db8db36 100644 --- a/pydocteur/utils/state_actions.py +++ b/pydocteur/utils/state_actions.py @@ -1,10 +1,10 @@ import random +import time from github import PullRequest from pydocteur.utils.comment_body import get_comment_bodies - END_OF_BODY = """ --- @@ -46,7 +46,23 @@ def comment_pr(pr: PullRequest, state: str): pr.create_issue_comment(body + END_OF_BODY.format(state=state)) -def merge_and_thanks(pr: PullRequest, state: str): - # TODO: Add label and message before doing anything to warn that it is being merged - # Don't forgot to add the state in the comment :p - pass +def merge_and_thank_contributors(pr: PullRequest, state: str): + warnings = get_comment_bodies("automerge_approved_testok") + thanks = get_comment_bodies("automerge_approved_testok-done") + + print("MERGING: Sending warning") + warning_body = random.choice(warnings) + warning_body = replace_body_variables(pr, warning_body) + pr.create_issue_comment(warning_body + END_OF_BODY.format(state=state)) + + print("MERGING: Sleeping 1s") + time.sleep(1) + + print("MERGING: MERGING") + # TODO: Custom commit message/title with nice infos and saying it's auto merged. + pr.merge(merge_method="squash", commit_message="") + + print("MERGING: Sending thanks") + thanks_body = random.choice(thanks) + thanks_body = replace_body_variables(pr, thanks_body) + pr.create_issue_comment(thanks_body + END_OF_BODY.format(state=state))