Skip to content

Commit 4568874

Browse files
Update pr_merge_conflict_check.py
1 parent e4af4db commit 4568874

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

scripts/pr_merge_conflict_check.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
from scripts import install_third_party_libs
3131

3232
import requests
33-
from typing import Any, Dict, List, Optional
33+
from typing import Dict, List, Optional, TypedDict
34+
35+
# Define a TypedDict for pull request data.
36+
class PRData(TypedDict, total=False):
37+
number: int
38+
user: Dict[str, str]
39+
mergeable_state: str
3440

3541
# Global configuration.
3642
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
@@ -65,39 +71,39 @@ def __init__(self, token: str, repo: str) -> None:
6571
'Accept': 'application/vnd.github.v3+json'
6672
}
6773

68-
def list_open_prs(self) -> List[Dict[str, Any]]:
74+
def list_open_prs(self) -> List[PRData]:
6975
"""Fetches all open pull requests with pagination.
7076
7177
Returns:
72-
List of dictionaries representing open pull requests.
78+
List of PRData dictionaries representing open pull requests.
7379
"""
74-
prs: List[Dict[str, Any]] = []
80+
prs: List[PRData] = []
7581
page = 1
7682
while True:
7783
url = f'{self.base_url}/pulls?state=open&page={page}&per_page=100'
7884
response = requests.get(url, headers=self.rest_headers, timeout=TIMEOUT)
7985
response.raise_for_status()
80-
current_prs = response.json()
86+
current_prs: List[PRData] = response.json()
8187
if not current_prs:
8288
break
8389
prs.extend(current_prs)
8490
page += 1
8591
return prs
8692

87-
def fetch_pr_details(self, pr_number: int) -> Optional[Dict[str, Any]]:
93+
def fetch_pr_details(self, pr_number: int) -> Optional[PRData]:
8894
"""Fetches pull request details with retries until a definitive mergeable state is found.
8995
9096
Args:
9197
pr_number: The number of the pull request.
9298
9399
Returns:
94-
A dictionary with PR details if the mergeable state is determined; otherwise, None.
100+
A PRData dictionary with PR details if the mergeable state is determined; otherwise, None.
95101
"""
96102
pr_details_url = f'{self.base_url}/pulls/{pr_number}'
97103
for attempt in range(RETRY_COUNT):
98104
response = requests.get(pr_details_url, headers=self.rest_headers, timeout=TIMEOUT)
99105
response.raise_for_status()
100-
pr_details = response.json()
106+
pr_details: PRData = response.json()
101107
mergeable_state = pr_details.get('mergeable_state')
102108
if mergeable_state and mergeable_state != 'unknown':
103109
return pr_details

0 commit comments

Comments
 (0)