Skip to content

Commit 899ab5f

Browse files
committed
fix: warn and skip when --starred-gists used for different user
GitHub's API only allows retrieving starred gists for the authenticated user. Previously, using --starred-gists when backing up a different user would silently return no relevant data. Now warns and skips the retrieval entirely when the target user differs from the authenticated user. Uses case-insensitive comparison to match GitHub's username handling. Fixes #93
1 parent 2a9d86a commit 899ab5f

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ Starred gists vs starred repo behaviour
301301

302302
The starred normal repo cloning (``--all-starred``) argument stores starred repos separately to the users own repositories. However, using ``--starred-gists`` will store starred gists within the same directory as the users own gists ``--gists``. Also, all gist repo directory names are IDs not the gist's name.
303303

304+
Note: ``--starred-gists`` only retrieves starred gists for the authenticated user, not the target user, due to a GitHub API limitation.
305+
304306

305307
Skip existing on incomplete backups
306308
-----------------------------------

github_backup/github_backup.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,16 +1565,22 @@ def retrieve_repositories(args, authenticated_user):
15651565
repos.extend(gists)
15661566

15671567
if args.include_starred_gists:
1568-
starred_gists_template = "https://{0}/gists/starred".format(
1569-
get_github_api_host(args)
1570-
)
1571-
starred_gists = retrieve_data(
1572-
args, starred_gists_template, single_request=False
1573-
)
1574-
# flag each repo as a starred gist for downstream processing
1575-
for item in starred_gists:
1576-
item.update({"is_gist": True, "is_starred": True})
1577-
repos.extend(starred_gists)
1568+
if not authenticated_user.get("login") or args.user.lower() != authenticated_user["login"].lower():
1569+
logger.warning(
1570+
"Cannot retrieve starred gists for '%s'. GitHub only allows access to the authenticated user's starred gists.",
1571+
args.user,
1572+
)
1573+
else:
1574+
starred_gists_template = "https://{0}/gists/starred".format(
1575+
get_github_api_host(args)
1576+
)
1577+
starred_gists = retrieve_data(
1578+
args, starred_gists_template, single_request=False
1579+
)
1580+
# flag each repo as a starred gist for downstream processing
1581+
for item in starred_gists:
1582+
item.update({"is_gist": True, "is_starred": True})
1583+
repos.extend(starred_gists)
15781584

15791585
return repos
15801586

0 commit comments

Comments
 (0)