38
38
39
39
40
40
@cache
41
- def get_pr_commit (pull_number : int ) -> str :
41
+ def get_pr_commit (api : GhApi , pull_number : int ) -> str :
42
42
return api .pulls .get (pull_number = pull_number ).merge_commit_sha
43
43
44
44
@@ -63,6 +63,7 @@ def is_commit_title_in_branch(repo_path: str, title: str, branch: str) -> bool:
63
63
64
64
65
65
def check_prs (
66
+ api : GhApi ,
66
67
repo_path : str ,
67
68
branch_to_check : str ,
68
69
start : int = 1 ,
@@ -100,7 +101,7 @@ def check_prs(
100
101
if not pr .pull_request .merged_at :
101
102
# PR was closed without being merged, skip it
102
103
continue
103
- commit = get_pr_commit (pr .number )
104
+ commit = get_pr_commit (api , pr .number )
104
105
title = get_title_of_commit (repo_path , commit )
105
106
print (f" { title } " )
106
107
@@ -114,13 +115,50 @@ def check_prs(
114
115
return candidates
115
116
116
117
117
- def main (args ) -> None :
118
+ def main () -> None :
119
+ parser = argparse .ArgumentParser (
120
+ description = __doc__ ,
121
+ formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
122
+ )
123
+ parser .add_argument ("repo_path" , help = "path to CPython repo" )
124
+ parser .add_argument (
125
+ "-b" ,
126
+ "--branches" ,
127
+ default = "3.13,3.12,3.11,3.10,3.9" ,
128
+ help = "branches to check" ,
129
+ )
130
+ parser .add_argument (
131
+ "-s" , "--start" , default = 1 , type = int , help = "start at this PR number"
132
+ )
133
+ parser .add_argument (
134
+ "-n" , "--number" , default = 100 , type = int , help = "number of PRs to check"
135
+ )
136
+ parser .add_argument (
137
+ "--sort" ,
138
+ default = "newest" ,
139
+ choices = (
140
+ "newest" ,
141
+ "oldest" ,
142
+ "most-commented" ,
143
+ "least-commented" ,
144
+ "recently-updated" ,
145
+ "least-recently-updated" ,
146
+ ),
147
+ help = "Sort by" ,
148
+ )
149
+ parser .add_argument (
150
+ "-o" , "--open-prs" , action = "store_true" , help = "open PRs in browser"
151
+ )
152
+ args = parser .parse_args ()
153
+
154
+ api = GhApi (owner = "python" , repo = "cpython" , token = GITHUB_TOKEN )
155
+
118
156
# Find
119
157
total_candidates = defaultdict (list )
120
158
for branch in args .branches .split ("," ):
121
159
print (f"\n Checking branch { branch } " )
122
160
candidates = check_prs (
123
- args .repo_path , branch , args .start , args .number , args .sort
161
+ api , args .repo_path , branch , args .start , args .number , args .sort
124
162
)
125
163
for reason , prs in candidates .items ():
126
164
total_candidates [reason ].extend (prs )
@@ -154,40 +192,4 @@ def report(prs: list[PR]):
154
192
155
193
156
194
if __name__ == "__main__" :
157
- parser = argparse .ArgumentParser (
158
- description = __doc__ ,
159
- formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
160
- )
161
- parser .add_argument ("repo_path" , help = "path to CPython repo" )
162
- parser .add_argument (
163
- "-b" ,
164
- "--branches" ,
165
- default = "3.13,3.12,3.11,3.10,3.9" ,
166
- help = "branches to check" ,
167
- )
168
- parser .add_argument (
169
- "-s" , "--start" , default = 1 , type = int , help = "start at this PR number"
170
- )
171
- parser .add_argument (
172
- "-n" , "--number" , default = 100 , type = int , help = "number of PRs to check"
173
- )
174
- parser .add_argument (
175
- "--sort" ,
176
- default = "newest" ,
177
- choices = (
178
- "newest" ,
179
- "oldest" ,
180
- "most-commented" ,
181
- "least-commented" ,
182
- "recently-updated" ,
183
- "least-recently-updated" ,
184
- ),
185
- help = "Sort by" ,
186
- )
187
- parser .add_argument (
188
- "-o" , "--open-prs" , action = "store_true" , help = "open PRs in browser"
189
- )
190
- args = parser .parse_args ()
191
-
192
- api = GhApi (owner = "python" , repo = "cpython" , token = GITHUB_TOKEN )
193
- main (args )
195
+ main ()
0 commit comments