Skip to content

Commit 29aaace

Browse files
authored
Merge pull request #6 from AFPy/merge_pr
2 parents 2621a1d + 2c9b459 commit 29aaace

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

pydocteur/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pydocteur.utils.pr_status import is_label_set
1111
from pydocteur.utils.pr_status import is_pr_approved
1212
from pydocteur.utils.state_actions import comment_pr
13+
from pydocteur.utils.state_actions import merge_and_thank_contributors
1314

1415

1516
load_dotenv()
@@ -41,7 +42,7 @@ def process_incoming_payload():
4142
if payload["sender"]["login"] == "PyDocTeur":
4243
return "OK", 200
4344
pr = get_pull_request(payload)
44-
if not pr:
45+
if not pr or pr.is_merged():
4546
return "OK", 200
4647

4748
state = state_name(
@@ -55,7 +56,7 @@ def process_incoming_payload():
5556
print("State has not changed, ignoring event.")
5657
return "OK", 200
5758
state_dict = {
58-
"automerge_approved": comment_pr
59+
"automerge_approved_testok": merge_and_thank_contributors,
5960
# ...
6061
}
6162
state_dict.get(state, comment_pr)(state=state, pr=pr)

pydocteur/utils/state_actions.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import random
2+
import time
23

34
from github import PullRequest
45

56
from pydocteur.utils.comment_body import get_comment_bodies
67

7-
88
END_OF_BODY = """
99
1010
---
@@ -46,7 +46,23 @@ def comment_pr(pr: PullRequest, state: str):
4646
pr.create_issue_comment(body + END_OF_BODY.format(state=state))
4747

4848

49-
def merge_and_thanks(pr: PullRequest, state: str):
50-
# TODO: Add label and message before doing anything to warn that it is being merged
51-
# Don't forgot to add the state in the comment :p
52-
pass
49+
def merge_and_thank_contributors(pr: PullRequest, state: str):
50+
warnings = get_comment_bodies("automerge_approved_testok")
51+
thanks = get_comment_bodies("automerge_approved_testok-done")
52+
53+
print("MERGING: Sending warning")
54+
warning_body = random.choice(warnings)
55+
warning_body = replace_body_variables(pr, warning_body)
56+
pr.create_issue_comment(warning_body + END_OF_BODY.format(state=state))
57+
58+
print("MERGING: Sleeping 1s")
59+
time.sleep(1)
60+
61+
print("MERGING: MERGING")
62+
# TODO: Custom commit message/title with nice infos and saying it's auto merged.
63+
pr.merge(merge_method="squash", commit_message="")
64+
65+
print("MERGING: Sending thanks")
66+
thanks_body = random.choice(thanks)
67+
thanks_body = replace_body_variables(pr, thanks_body)
68+
pr.create_issue_comment(thanks_body + END_OF_BODY.format(state=state))

0 commit comments

Comments
 (0)