From 9604dd6fe5fc8c04fddbbf59779967c0ea56768a Mon Sep 17 00:00:00 2001 From: Peter Gabaldon <34518201+PeterGabaldon@users.noreply.github.com> Date: Sun, 5 Jul 2026 13:24:14 +0200 Subject: [PATCH 1/2] Fix template URL for watched repositories backup --- github_backup/github_backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index e72622d..63835e4 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -3075,7 +3075,7 @@ def backup_account(args, output_directory): if args.include_watched or args.include_everything: output_file = "{0}/watched.json".format(account_cwd) - template = "https://{0}/users/{1}/subscriptions".format( + template = "https://{0}/user/subscriptions".format( get_github_api_host(args), args.user ) _backup_data(args, "watched repositories", template, output_file, account_cwd) From 83b84ae5ce2495b0359f4c3e3d55b7f29d481961 Mon Sep 17 00:00:00 2001 From: Peter Gabaldon Date: Tue, 7 Jul 2026 08:38:42 +0200 Subject: [PATCH 2/2] Applied diff issuecomment-4900281663 --- github_backup/cli.py | 2 +- github_backup/github_backup.py | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/github_backup/cli.py b/github_backup/cli.py index 987ae71..f51a9c0 100644 --- a/github_backup/cli.py +++ b/github_backup/cli.py @@ -81,7 +81,7 @@ def main(): repositories = retrieve_repositories(args, authenticated_user) repositories = filter_repositories(args, repositories) backup_repositories(args, output_directory, repositories) - backup_account(args, output_directory) + backup_account(args, output_directory, authenticated_user) if __name__ == "__main__": diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index 63835e4..92acfa1 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -3063,8 +3063,10 @@ def fetch_repository( logging_subprocess(git_command, cwd=local_dir) -def backup_account(args, output_directory): +def backup_account(args, output_directory, authenticated_user=None): account_cwd = os.path.join(output_directory, "account") + if authenticated_user is None: + authenticated_user = {"login": None} if args.include_starred or args.include_everything: output_file = "{0}/starred.json".format(account_cwd) @@ -3074,11 +3076,25 @@ def backup_account(args, output_directory): _backup_data(args, "starred repositories", template, output_file, account_cwd) if args.include_watched or args.include_everything: - output_file = "{0}/watched.json".format(account_cwd) - template = "https://{0}/user/subscriptions".format( - get_github_api_host(args), args.user - ) - _backup_data(args, "watched repositories", template, output_file, account_cwd) + # GitHub deprecated /users/{username}/subscriptions; watched + # repositories are only available for the authenticated user via + # /user/subscriptions. + if ( + not authenticated_user.get("login") + or args.user.lower() != authenticated_user["login"].lower() + ): + logger.warning( + "Cannot retrieve watched repositories for '%s'. GitHub only allows access to the authenticated user's watched repositories.", + args.user, + ) + else: + output_file = "{0}/watched.json".format(account_cwd) + template = "https://{0}/user/subscriptions".format( + get_github_api_host(args) + ) + _backup_data( + args, "watched repositories", template, output_file, account_cwd + ) if args.include_followers or args.include_everything: output_file = "{0}/followers.json".format(account_cwd)