@@ -3068,8 +3068,10 @@ def fetch_repository(
30683068 logging_subprocess (git_command , cwd = local_dir )
30693069
30703070
3071- def backup_account (args , output_directory ):
3071+ def backup_account (args , output_directory , authenticated_user = None ):
30723072 account_cwd = os .path .join (output_directory , "account" )
3073+ if authenticated_user is None :
3074+ authenticated_user = {"login" : None }
30733075
30743076 if args .include_starred or args .include_everything :
30753077 output_file = "{0}/starred.json" .format (account_cwd )
@@ -3079,11 +3081,25 @@ def backup_account(args, output_directory):
30793081 _backup_data (args , "starred repositories" , template , output_file , account_cwd )
30803082
30813083 if args .include_watched or args .include_everything :
3082- output_file = "{0}/watched.json" .format (account_cwd )
3083- template = "https://{0}/users/{1}/subscriptions" .format (
3084- get_github_api_host (args ), args .user
3085- )
3086- _backup_data (args , "watched repositories" , template , output_file , account_cwd )
3084+ # GitHub deprecated /users/{username}/subscriptions; watched
3085+ # repositories are only available for the authenticated user via
3086+ # /user/subscriptions.
3087+ if (
3088+ not authenticated_user .get ("login" )
3089+ or args .user .lower () != authenticated_user ["login" ].lower ()
3090+ ):
3091+ logger .warning (
3092+ "Cannot retrieve watched repositories for '%s'. GitHub only allows access to the authenticated user's watched repositories." ,
3093+ args .user ,
3094+ )
3095+ else :
3096+ output_file = "{0}/watched.json" .format (account_cwd )
3097+ template = "https://{0}/user/subscriptions" .format (
3098+ get_github_api_host (args )
3099+ )
3100+ _backup_data (
3101+ args , "watched repositories" , template , output_file , account_cwd
3102+ )
30873103
30883104 if args .include_followers or args .include_everything :
30893105 output_file = "{0}/followers.json" .format (account_cwd )
0 commit comments