@@ -849,12 +849,21 @@ def validate_readthedocs(self, repo):
849
849
errors .append (ERROR_RTD_ADABOT_MISSING )
850
850
851
851
# Get the README file contents
852
- try :
853
- lib_repo = GH_INTERFACE .get_repo ("Adafruit/" + repo ["full_name" ])
854
- except pygithub .GithubException :
855
- errors .append (ERROR_RTD_FAILED_TO_LOAD_BUILD_STATUS )
856
- return errors
857
- content_file = lib_repo .get_contents ("README.rst" )
852
+ while True :
853
+ try :
854
+ lib_repo = GH_INTERFACE .get_repo ("Adafruit/" + repo ["full_name" ])
855
+ content_file = lib_repo .get_contents ("README.rst" )
856
+ break
857
+ except pygithub .RateLimitExceededException :
858
+ core_rate_limit_reset = GH_INTERFACE .get_rate_limit ().core .reset
859
+ sleep_time = core_rate_limit_reset - datetime .datetime .now ()
860
+ logging .warning ("Rate Limit will reset at: %s" , core_rate_limit_reset )
861
+ time .sleep (sleep_time .seconds )
862
+ continue
863
+ except pygithub .GithubException :
864
+ errors .append (ERROR_RTD_FAILED_TO_LOAD_BUILD_STATUS )
865
+ return errors
866
+
858
867
readme_text = content_file .decoded_content .decode ("utf-8" )
859
868
860
869
# Parse for the ReadTheDocs slug
@@ -864,12 +873,28 @@ def validate_readthedocs(self, repo):
864
873
rtd_slug : str = search_results .named ["slug" ]
865
874
rtd_slug = rtd_slug .replace ("_" , "-" , - 1 )
866
875
867
- # GET the latest documentation build runs
868
- url = f"https://readthedocs.org/api/v3/projects/{ rtd_slug } /builds/"
869
- rtd_token = os .environ ["RTD_TOKEN" ]
870
- headers = {"Authorization" : f"token { rtd_token } " }
871
- response = requests .get (url , headers = headers )
872
- json_response = response .json ()
876
+ while True :
877
+ # GET the latest documentation build runs
878
+ url = f"https://readthedocs.org/api/v3/projects/{ rtd_slug } /builds/"
879
+ rtd_token = os .environ ["RTD_TOKEN" ]
880
+ headers = {"Authorization" : f"token { rtd_token } " }
881
+ response = requests .get (url , headers = headers )
882
+ json_response = response .json ()
883
+
884
+ error_message = json_response .get ("detail" )
885
+ if error_message :
886
+ if error_message == "Not found." or not error_message .startswith (
887
+ "Request was throttled."
888
+ ):
889
+ errors .append (ERROR_RTD_FAILED_TO_LOAD_BUILD_STATUS )
890
+ return errors
891
+ time_result = parse .search (
892
+ "Request was throttled. Expected available in {throttled:d} seconds." ,
893
+ error_message ,
894
+ )
895
+ time .sleep (time_result .named ["throttled" ] + 3 )
896
+ continue
897
+ break
873
898
874
899
# Return the results of the latest run
875
900
doc_build_results = json_response .get ("results" )
0 commit comments