Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion github_backup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
28 changes: 22 additions & 6 deletions github_backup/github_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}/users/{1}/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)
Expand Down