@@ -925,6 +925,37 @@ def validate_core_driver_page(self, repo):
925
925
return []
926
926
927
927
928
+ def github_get_all_pages (self , url , params ):
929
+ results = []
930
+ response = github .get (url , params = params )
931
+
932
+ if not response .ok :
933
+ # set error message and return ERROR_OUTPUT_HANDLER
934
+ # the caller must test and forward to the outside
935
+ self .output_file_data .append ("Github request failed: {}, {}" .format (repo ["full_name" ], link ))
936
+ return ERROR_OUTPUT_HANDLER
937
+
938
+ while response .ok :
939
+ results .extend (response .json ())
940
+ try :
941
+ links = response .headers ["Link" ]
942
+ except KeyError :
943
+ break
944
+
945
+ if links :
946
+ next_url = None
947
+ for link in links .split ("," ):
948
+ link , rel = link .split (";" )
949
+ link = link .strip (" <>" )
950
+ rel = rel .strip ()
951
+ if rel == "rel=\" next\" " :
952
+ next_url = link
953
+ break
954
+ if not next_url :
955
+ break
956
+ response = github .get (link )
957
+ return results
958
+
928
959
929
960
def gather_insights (self , repo , insights , since , show_closed_metric = False ):
930
961
"""Gather analytics about a repository like open and merged pull requests.
@@ -937,14 +968,12 @@ def gather_insights(self, repo, insights, since, show_closed_metric=False):
937
968
return []
938
969
params = {"sort" : "updated" ,
939
970
"state" : "all" ,
971
+ "per_page" : 100 ,
940
972
"since" : since .strftime ("%Y-%m-%dT%H:%M:%SZ" )}
941
- response = github .get ("/repos/" + repo ["full_name" ] + "/issues" , params = params )
942
- if not response .ok :
943
- # replace 'output_handler' with ERROR_OUTPUT_HANDLER
944
- self .output_file_data .append ("Insights request failed: {}" .format (repo ["full_name" ]))
973
+ issues = self .github_get_all_pages ("/repos/" + repo ["full_name" ] + "/issues" , params = params )
974
+ if issues == ERROR_OUTPUT_HANDLER :
945
975
return [ERROR_OUTPUT_HANDLER ]
946
976
947
- issues = response .json ()
948
977
for issue in issues :
949
978
created = datetime .datetime .strptime (issue ["created_at" ], "%Y-%m-%dT%H:%M:%SZ" )
950
979
if "pull_request" in issue :
@@ -1017,34 +1046,11 @@ def gather_insights(self, repo, insights, since, show_closed_metric=False):
1017
1046
insights ["closed_issues" ] += 1
1018
1047
insights ["issue_closers" ].add (issue_info ["closed_by" ]["login" ])
1019
1048
1020
- issues = []
1021
1049
params = {"state" : "open" , "per_page" : 100 }
1022
- response = github .get ("/repos/" + repo ["full_name" ] + "/issues" , params = params )
1023
- if not response .ok :
1024
- # replace 'output_handler' with ERROR_OUTPUT_HANDLER
1025
- self .output_file_data .append ("Issues request failed: {}" .format (repo ["full_name" ]))
1050
+ issues = self .github_get_all_pages ("/repos/" + repo ["full_name" ] + "/issues" , params = params )
1051
+ if issues == ERROR_OUTPUT_HANDLER :
1026
1052
return [ERROR_OUTPUT_HANDLER ]
1027
1053
1028
- while response .ok :
1029
- issues .extend (response .json ())
1030
- try :
1031
- links = response .headers ["Link" ]
1032
- except KeyError :
1033
- break
1034
-
1035
- if links :
1036
- next_url = None
1037
- for link in links .split ("," ):
1038
- link , rel = link .split (";" )
1039
- link = link .strip (" <>" )
1040
- rel = rel .strip ()
1041
- if rel == "rel=\" next\" " :
1042
- next_url = link
1043
- break
1044
- if not next_url :
1045
- break
1046
- response = requests .get (link , timeout = 30 )
1047
-
1048
1054
for issue in issues :
1049
1055
created = datetime .datetime .strptime (issue ["created_at" ], "%Y-%m-%dT%H:%M:%SZ" )
1050
1056
days_open = datetime .datetime .today () - created
0 commit comments