@@ -44,6 +44,27 @@ def __init__(self, key_manager, logger: logging.Logger, feature="rest"):
4444 self .key = None
4545 self .expired_keys_for_request = []
4646
47+ def endpoint_url (self , path : str , params : dict = None ) -> str :
48+ """Build a URL for a github endpoint using the specified path and query parameters
49+
50+ Args:
51+ path (str): the path to use (i.e. "/users/MoralCode")
52+ params (dict): optional query parameters to add to the url, as a dict
53+
54+ Returns:
55+ str: the full URL to the specified resource.
56+ """
57+ # using pythons url processing library helps handle accidental
58+ # inclusion of query parameters in the path string, ensuring all query
59+ # parameters are properly encoded and escaped
60+
61+ if not path .startswith ("/" ):
62+ path = "/" + path
63+
64+ url = "https://api.github.com" + path
65+
66+ return self .__add_query_params (url , params or {})
67+
4768 def get_resource_count (self , url ):
4869
4970 # set per_page to 100 explicitly so we know each page is 100 long
@@ -60,6 +81,20 @@ def get_resource_count(self, url):
6081
6182 return (100 * (num_pages - 1 )) + len (data )
6283
84+ def check_prs_enabled (self , owner : str , repo : str ,) -> bool :
85+ """
86+ Checks whether pull requests are enabled for a repository.
87+ Returns False if PRs are disabled (404 on /pulls) and true if there are PRs.
88+ """
89+ try :
90+ url = self .endpoint_url (f"repos/{ owner } /{ repo } /pulls" , {"per_page" : "1" })
91+ self .get_resource_page_count (url )
92+ return True
93+ except UrlNotFoundException :
94+ self .logger .info (f"{ owner } /{ repo } : Pull requests are disabled. Skipping PR collection." )
95+ return False
96+
97+
6398 def paginate_resource (self , url ):
6499
65100 response = self .make_request_with_retries (url )
0 commit comments