Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pydocteur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
26 changes: 21 additions & 5 deletions pydocteur/utils/state_actions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import random
import time

from github import PullRequest

from pydocteur.utils.comment_body import get_comment_bodies


END_OF_BODY = """

---
Expand Down Expand Up @@ -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))