@@ -30,14 +30,50 @@ def __init__(self):
3030 self .broken_links = []
3131 self .changed_links = []
3232
33+ # Debug info
34+ print (f"GitHub token available: { 'Yes' if self .github_token else 'No' } " )
35+ if self .github_token :
36+ print (f"Token length: { len (self .github_token )} " )
37+ print (f"Token starts with: { self .github_token [:10 ]} ..." )
38+
39+ # Check rate limits
40+ self .check_rate_limits ()
41+
42+ def check_rate_limits (self ):
43+ """Check GitHub API rate limits"""
44+ try :
45+ headers = {
46+ 'Accept' : 'application/vnd.github.v3+json' ,
47+ 'User-Agent' : 'ComfyUI-Docs-Link-Tracker' ,
48+ 'X-GitHub-Api-Version' : '2022-11-28'
49+ }
50+ if self .github_token :
51+ headers ['Authorization' ] = f'Bearer { self .github_token } '
52+
53+ response = requests .get ('https://api.github.com/rate_limit' , headers = headers )
54+ if response .status_code == 200 :
55+ data = response .json ()
56+ core_limit = data ['resources' ]['core' ]
57+ print (f"API Rate Limit - Remaining: { core_limit ['remaining' ]} /{ core_limit ['limit' ]} " )
58+ if core_limit ['remaining' ] < 10 :
59+ print ("⚠️ WARNING: Very low rate limit remaining!" )
60+ else :
61+ print (f"Failed to check rate limits: { response .status_code } " )
62+ print (f"Response: { response .text [:500 ]} " )
63+ except Exception as e :
64+ print (f"Error checking rate limits: { str (e )} " )
65+
3366 def get_github_api_headers (self ):
3467 """Get headers for GitHub API requests"""
3568 headers = {
3669 'Accept' : 'application/vnd.github.v3+json' ,
37- 'User-Agent' : 'ComfyUI-Docs-Link-Tracker'
70+ 'User-Agent' : 'ComfyUI-Docs-Link-Tracker' ,
71+ 'X-GitHub-Api-Version' : '2022-11-28'
3872 }
3973 if self .github_token :
40- headers ['Authorization' ] = f'token { self .github_token } '
74+ headers ['Authorization' ] = f'Bearer { self .github_token } '
75+ else :
76+ print ("Warning: No GitHub token provided, using unauthenticated requests" )
4177 return headers
4278
4379 def fetch_repo_content (self , repo ):
@@ -48,8 +84,13 @@ def fetch_repo_content(self, repo):
4884 repo_url = f"https://api.github.com/repos/{ repo } "
4985 response = requests .get (repo_url , headers = self .get_github_api_headers ())
5086 if response .status_code != 200 :
51- print (f"Failed to get repo info for { repo } : { response .status_code } " )
52- return []
87+ print (f"❌ Failed to get repo info for { repo } : { response .status_code } " )
88+ if response .status_code == 403 :
89+ print (f" - This might be due to API rate limits or repository access permissions" )
90+ print (f" - Response: { response .text [:200 ]} " )
91+ elif response .status_code == 404 :
92+ print (f" - Repository { repo } not found or not accessible" )
93+ return None # Return None to indicate failure
5394
5495 default_branch = response .json ().get ('default_branch' , 'main' )
5596
@@ -58,8 +99,10 @@ def fetch_repo_content(self, repo):
5899 response = requests .get (tree_url , headers = self .get_github_api_headers ())
59100
60101 if response .status_code != 200 :
61- print (f"Failed to fetch tree for { repo } : { response .status_code } " )
62- return []
102+ print (f"❌ Failed to fetch tree for { repo } : { response .status_code } " )
103+ if response .status_code == 403 :
104+ print (f" - API rate limit or permission issue" )
105+ return None # Return None to indicate failure
63106
64107 files_content = []
65108 tree_data = response .json ()
@@ -239,11 +282,17 @@ def process_repositories(self):
239282 print (f"Found { len (docs_paths )} documentation files" )
240283
241284 all_found_links = {}
285+ failed_repos = []
242286
243287 for repo in self .target_repos :
244288 print (f"\n Processing repository: { repo } " )
245289 files_content = self .fetch_repo_content (repo )
246290
291+ # Check if fetch failed
292+ if files_content is None :
293+ failed_repos .append (repo )
294+ continue
295+
247296 repo_links = {}
248297 for file_info in files_content :
249298 links = self .extract_docs_links (file_info ['content' ])
@@ -253,6 +302,26 @@ def process_repositories(self):
253302 print (f"Found { sum (len (links ) for links in repo_links .values ())} docs.comfy.org links in { len (repo_links )} files" )
254303 all_found_links [repo ] = repo_links
255304
305+ # Check if any repositories failed to fetch
306+ if failed_repos :
307+ error_msg = f"Failed to fetch content from repositories: { ', ' .join (failed_repos )} "
308+ print (f"\n ❌ ERROR: { error_msg } " )
309+
310+ # Write error report
311+ with open ('/tmp/external-link-report.txt' , 'w' ) as f :
312+ f .write (f"## ❌ Repository Access Failed\n \n " )
313+ f .write (f"Unable to fetch content from the following repositories:\n \n " )
314+ for repo in failed_repos :
315+ f .write (f"- `{ repo } `\n " )
316+ f .write (f"\n **Possible causes:**\n " )
317+ f .write (f"- GitHub API rate limits exceeded\n " )
318+ f .write (f"- Insufficient token permissions\n " )
319+ f .write (f"- Repository access restrictions\n " )
320+ f .write (f"- Network connectivity issues\n \n " )
321+ f .write (f"**Action required:** Please check the GitHub Action logs and resolve the access issues.\n " )
322+
323+ sys .exit (1 )
324+
256325 # Validate all found links
257326 self .validate_all_links (all_found_links , docs_paths )
258327
0 commit comments