33
44import requests
55
6- endpoint = r"https://api.github.com/graphql"
6+ ENDPOINT = r"https://api.github.com/graphql"
77
88
99def load_query_from_file (fname , repo_owner = "numpy" , repo_name = "numpy" ):
@@ -72,10 +72,10 @@ def send_query(query, query_type, headers, cursor=None):
7272 This is intended mostly for internal use within `get_all_responses`.
7373 """
7474 # TODO: Expand this, either by parsing the query type from the query
75- # directly or manually adding more query_types to the set
76- if query_type not in {"issues" , "pullRequests" }:
75+ # Directly or manually adding more query_types to the set
76+ if query_type not in {"issues" , "pullRequests" , "stargazerCount" }:
7777 raise ValueError (
78- "Only 'issues' and 'pullRequests ' queries are currently supported"
78+ "Only 'issues', 'pullRequests' and 'stargazerCount ' queries are currently supported"
7979 )
8080 # TODO: Generalize this
8181 # WARNING: The cursor injection depends on the specific structure of the
@@ -91,7 +91,7 @@ def send_query(query, query_type, headers, cursor=None):
9191 retries = max_retries
9292 while retries > 0 :
9393 try :
94- response = requests .post (endpoint , json = payload , headers = headers )
94+ response = requests .post (ENDPOINT , json = payload , headers = headers )
9595 except (
9696 requests .exceptions .ChunkedEncodingError ,
9797 requests .exceptions .ConnectionError ,
@@ -138,7 +138,15 @@ def get_all_responses(query, query_type, headers):
138138 print ("Fetching..." , end = "" , flush = True )
139139 rdata = send_query (query , query_type , headers , cursor = last_cursor )
140140 try :
141- pdata , last_cursor , total_count = parse_single_query (rdata , query_type )
141+ # TODO: Generalize this
142+ if query_type == "stargazerCount" :
143+ # Special case for stargazerCount
144+ pdata = [{"stargazerCount" :rdata ["data" ]["repository" ]["stargazerCount" ]}]
145+ last_cursor = None
146+ total_count = 1
147+ else :
148+ # Normal case for issues/PRs
149+ pdata , last_cursor , total_count = parse_single_query (rdata , query_type )
142150 except (KeyError , TypeError ):
143151 print ("Malformed response; repeating request after 1 minute" )
144152 time .sleep (1 * 60 )
0 commit comments