Skip to content

Commit 3ecae56

Browse files
authored
Merge pull request #521 from PeterGabaldon/fix-deprecation-/users/{username}/subscriptions
Fix template URL for watched repositories backup
2 parents e0784e5 + 83b84ae commit 3ecae56

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎github_backup/cli.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def main():
8181
repositories = retrieve_repositories(args, authenticated_user)
8282
repositories = filter_repositories(args, repositories)
8383
backup_repositories(args, output_directory, repositories)
84-
backup_account(args, output_directory)
84+
backup_account(args, output_directory, authenticated_user)
8585

8686

8787
if __name__ == "__main__":

‎github_backup/github_backup.py‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)