66
77router = routing .Router ()
88
9- TITLE_RE = re .compile (r' \[(?P<branch>\d+\.\d+)\].+?(?P<pr>\d+)\)' )
9+ TITLE_RE = re .compile (r" \[(?P<branch>\d+\.\d+)\].+?(?P<pr>\d+)\)" )
1010
1111
1212@router .register ("status" )
1313async def check_status (event , gh , * args , ** kwargs ):
1414 """
1515 Check the state change
1616 """
17- if event .data ["commit" ].get ("committer" ) \
18- and event .data ["commit" ]["committer" ]["login" ] == "miss-islington" :
17+ if (
18+ event .data ["commit" ].get ("committer" )
19+ and event .data ["commit" ]["committer" ]["login" ] == "miss-islington"
20+ ):
1921 sha = event .data ["sha" ]
2022 await check_ci_status_and_approval (gh , sha , leave_comment = True )
2123
@@ -32,45 +34,53 @@ async def pr_reviewed(event, gh, *args, **kwargs):
3234
3335async def check_ci_status_and_approval (gh , sha , leave_comment = False ):
3436
35- result = await gh .getitem (f' /repos/python/cpython/commits/{ sha } /status' )
37+ result = await gh .getitem (f" /repos/python/cpython/commits/{ sha } /status" )
3638 all_ci_status = [status ["state" ] for status in result ["statuses" ]]
3739 all_ci_context = [status ["context" ] for status in result ["statuses" ]]
3840
39- if "pending" not in all_ci_status \
40- and "continuous-integration/travis-ci/pr" in all_ci_context :
41- async for ref in gh .getiter ('/repos/miss-islington/cpython/git/refs/heads/' ):
41+ if (
42+ "pending" not in all_ci_status
43+ and "continuous-integration/travis-ci/pr" in all_ci_context
44+ ):
45+ async for ref in gh .getiter ("/repos/miss-islington/cpython/git/refs/heads/" ):
4246 if "backport-" in ref ["ref" ] and ref ["object" ]["sha" ] == sha :
4347 backport_branch_name = ref ["ref" ].split ("/" )[- 1 ]
44- async for pr_response in gh .getiter (f'/repos/python/cpython/pulls?state=open&head=miss-islington:{ backport_branch_name } ' ):
48+ async for pr_response in gh .getiter (
49+ f"/repos/python/cpython/pulls?state=open&head=miss-islington:{ backport_branch_name } "
50+ ):
4551 pr_number = pr_response ["number" ]
4652 normalized_pr_title = util .normalize_title (
47- pr_response ["title" ],
48- pr_response [ "body" ] )
53+ pr_response ["title" ], pr_response [ "body" ]
54+ )
4955
5056 title_match = TITLE_RE .match (normalized_pr_title )
5157 if title_match :
5258
5359 if leave_comment :
54- original_pr_number = title_match .group ('pr' )
55- original_pr_url = f"/repos/python/cpython/pulls/{ original_pr_number } "
60+ original_pr_number = title_match .group ("pr" )
61+ original_pr_url = (
62+ f"/repos/python/cpython/pulls/{ original_pr_number } "
63+ )
5664 original_pr_result = await gh .getitem (original_pr_url )
5765 pr_author = original_pr_result ["user" ]["login" ]
5866 committer = original_pr_result ["merged_by" ]["login" ]
5967
60- participants = util .get_participants (
61- pr_author , committer )
62- emoji = "✅" if result ['state' ] == "success" else "❌"
68+ participants = util .get_participants (pr_author , committer )
69+ emoji = "✅" if result ["state" ] == "success" else "❌"
6370
64- await util .leave_comment (gh ,
71+ await util .leave_comment (
72+ gh ,
6573 pr_number = pr_number ,
66- message = f"{ participants } : Backport status check is done, and it's a { result ['state' ]} { emoji } ." )
74+ message = f"{ participants } : Backport status check is done, and it's a { result ['state' ]} { emoji } ." ,
75+ )
6776
68- if result ['state' ] == "success" :
69- async for review in gh .getiter (f"/repos/python/cpython/pulls/{ pr_number } /reviews" ):
77+ if result ["state" ] == "success" :
78+ async for review in gh .getiter (
79+ f"/repos/python/cpython/pulls/{ pr_number } /reviews"
80+ ):
7081 reviewer = review ["user" ]["login" ]
7182 approved = review ["state" ].lower () == "approved"
72- if approved \
73- and await util .is_core_dev (gh , reviewer ):
83+ if approved and await util .is_core_dev (gh , reviewer ):
7484 await merge_pr (gh , pr_number , sha )
7585 break
7686
@@ -81,14 +91,13 @@ async def merge_pr(gh, pr_number, sha):
8191 pr_commit_msg = commit ["commit" ]["message" ].split ("\n " )
8292
8393 cleaned_up_title = f"{ pr_commit_msg [0 ]} "
84- await gh .put (f"/repos/python/cpython/pulls/{ pr_number } /merge" ,
85- data = {"commit_title" : cleaned_up_title ,
86- "commit_message" : "\n " .join (pr_commit_msg [1 :]),
87- "sha" : sha ,
88- "merge_method" : "squash"
89- }
90- )
94+ await gh .put (
95+ f"/repos/python/cpython/pulls/{ pr_number } /merge" ,
96+ data = {
97+ "commit_title" : cleaned_up_title ,
98+ "commit_message" : "\n " .join (pr_commit_msg [1 :]),
99+ "sha" : sha ,
100+ "merge_method" : "squash" ,
101+ },
102+ )
91103 break
92-
93-
94-
0 commit comments