@@ -14,23 +14,44 @@ async def check_status(event, gh, *args, **kwargs):
14
14
"""
15
15
Check the state change
16
16
"""
17
+ sha = event .data ["sha" ]
18
+
17
19
if (
18
20
event .data ["commit" ].get ("committer" )
19
21
and event .data ["commit" ]["committer" ]["login" ] == "miss-islington"
20
22
):
21
- sha = event .data ["sha" ]
22
23
await check_ci_status_and_approval (gh , sha , leave_comment = True )
24
+ else :
25
+ pr_for_commit = await util .get_pr_for_commit (gh , sha )
26
+ if pr_for_commit :
27
+ pr_labels = pr_for_commit ["labels" ]
28
+ if util .pr_is_automerge (pr_labels ) and util .pr_is_awaiting_merge (pr_labels ):
29
+ await check_ci_status_and_approval (
30
+ gh , sha , leave_comment = True , is_automerge = True
31
+ )
23
32
24
33
25
34
@router .register ("pull_request" , action = "labeled" )
26
35
async def pr_reviewed (event , gh , * args , ** kwargs ):
27
- if event .data ["pull_request" ]["user" ]["login" ] == "miss-islington" :
28
- if util .pr_is_awaiting_merge (event .data ["pull_request" ]["labels" ]):
29
- sha = event .data ["pull_request" ]["head" ]["sha" ]
30
- await check_ci_status_and_approval (gh , sha )
36
+
37
+ pr_labels = event .data ["pull_request" ]["labels" ]
38
+
39
+ if util .pr_is_automerge (pr_labels ) and util .pr_is_awaiting_merge (pr_labels ):
40
+ sha = event .data ["pull_request" ]["head" ]["sha" ]
41
+
42
+ await check_ci_status_and_approval (gh , sha , is_automerge = True )
43
+ elif event .data ["pull_request" ]["user" ][
44
+ "login"
45
+ ] == "miss-islington" and util .pr_is_awaiting_merge (
46
+ event .data ["pull_request" ]["labels" ]
47
+ ):
48
+ sha = event .data ["pull_request" ]["head" ]["sha" ]
49
+ await check_ci_status_and_approval (gh , sha )
31
50
32
51
33
- async def check_ci_status_and_approval (gh , sha , leave_comment = False ):
52
+ async def check_ci_status_and_approval (
53
+ gh , sha , leave_comment = False , is_automerge = False
54
+ ):
34
55
35
56
result = await gh .getitem (f"/repos/python/cpython/commits/{ sha } /status" )
36
57
all_ci_status = [status ["state" ] for status in result ["statuses" ]]
@@ -40,56 +61,66 @@ async def check_ci_status_and_approval(gh, sha, leave_comment=False):
40
61
"pending" not in all_ci_status
41
62
and "continuous-integration/travis-ci/pr" in all_ci_context
42
63
):
43
-
44
- prs_for_commit = await gh .getitem (f'/search/issues?q=type:pr+repo:python/cpython+sha:{ sha } ' )
45
- if prs_for_commit ["total_count" ] > 0 : # there should only be one
46
- pr_for_commit = prs_for_commit ["items" ][0 ]
64
+ pr_for_commit = await util .get_pr_for_commit (gh , sha )
65
+ if pr_for_commit :
47
66
pr_number = pr_for_commit ["number" ]
48
67
normalized_pr_title = util .normalize_title (
49
68
pr_for_commit ["title" ], pr_for_commit ["body" ]
50
69
)
51
70
52
71
title_match = TITLE_RE .match (normalized_pr_title )
53
- if title_match :
72
+ if title_match or is_automerge :
54
73
if leave_comment :
55
- original_pr_number = title_match . group ( "pr" )
56
- original_pr_url = (
57
- f"/repos/python/cpython/pulls/ { original_pr_number } "
58
- )
59
- original_pr_result = await gh . getitem ( original_pr_url )
60
- pr_author = original_pr_result [ "user" ][ "login" ]
61
- committer = original_pr_result [ "merged_by" ][ "login" ]
74
+ if is_automerge :
75
+ participants = await util . get_gh_participants ( gh , pr_number )
76
+ else :
77
+ original_pr_number = title_match . group ( "pr" )
78
+ participants = await util . get_gh_participants (
79
+ gh , original_pr_number
80
+ )
62
81
63
- participants = util .get_participants (pr_author , committer )
64
82
emoji = "✅" if result ["state" ] == "success" else "❌"
65
83
66
84
await util .leave_comment (
67
85
gh ,
68
86
pr_number = pr_number ,
69
- message = f"{ participants } : Backport status check is done, and it's a { result ['state' ]} { emoji } ." ,
87
+ message = f"{ participants } : Status check is done, and it's a { result ['state' ]} { emoji } ." ,
70
88
)
71
-
72
89
if result ["state" ] == "success" :
73
- pr = await gh .getitem (
74
- f"/repos/python/cpython/pulls/{ pr_number } "
75
- )
76
- if util .pr_is_awaiting_merge (pr ["labels" ]):
77
- await merge_pr (gh , pr_number , sha )
78
90
91
+ if util .pr_is_awaiting_merge (pr_for_commit ["labels" ]):
92
+ await merge_pr (
93
+ gh , pr_for_commit , sha , is_automerge = is_automerge
94
+ )
79
95
80
- async def merge_pr (gh , pr_number , sha ):
96
+
97
+ async def merge_pr (gh , pr , sha , is_automerge = False ):
98
+ pr_number = pr ["number" ]
81
99
async for commit in gh .getiter (f"/repos/python/cpython/pulls/{ pr_number } /commits" ):
82
100
if commit ["sha" ] == sha :
83
- pr_commit_msg = commit ["commit" ]["message" ].split ("\n " )
84
-
85
- cleaned_up_title = f"{ pr_commit_msg [0 ]} "
86
- await gh .put (
87
- f"/repos/python/cpython/pulls/{ pr_number } /merge" ,
88
- data = {
89
- "commit_title" : cleaned_up_title ,
90
- "commit_message" : "\n " .join (pr_commit_msg [1 :]),
91
- "sha" : sha ,
92
- "merge_method" : "squash" ,
93
- },
94
- )
101
+ if is_automerge :
102
+ pr_commit_msg = pr ["body" ]
103
+ pr_title = f"{ pr ['title' ]} (GH-{ pr_number } )"
104
+ await gh .put (
105
+ f"/repos/python/cpython/pulls/{ pr_number } /merge" ,
106
+ data = {
107
+ "commit_title" : pr_title ,
108
+ "commit_message" : pr_commit_msg ,
109
+ "sha" : sha ,
110
+ "merge_method" : "squash" ,
111
+ },
112
+ )
113
+ else :
114
+ pr_commit_msg = commit ["commit" ]["message" ].split ("\n " )
115
+
116
+ cleaned_up_title = f"{ pr_commit_msg [0 ]} "
117
+ await gh .put (
118
+ f"/repos/python/cpython/pulls/{ pr_number } /merge" ,
119
+ data = {
120
+ "commit_title" : cleaned_up_title ,
121
+ "commit_message" : "\n " .join (pr_commit_msg [1 :]),
122
+ "sha" : sha ,
123
+ "merge_method" : "squash" ,
124
+ },
125
+ )
95
126
break
0 commit comments