Compare commits

..

7 Commits

Author SHA1 Message Date
Jose Diaz-Gonzalez
8f9cf7ff89 Merge pull request #459 from Iamrodos/issue-93-starred-gists-warning
fix: warn and skip when --starred-gists used for different user
2025-12-03 23:07:29 -05:00
Rodos
899ab5fdc2 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
2025-12-04 10:07:43 +11:00
GitHub Action
2a9d86a6bf Release version 0.54.0 2025-12-03 02:17:59 +00:00
Jose Diaz-Gonzalez
4fd3ea9e3c Merge pull request #457 from Iamrodos/readme-updates
docs: update README testing section and add fetch vs pull explanation
2025-12-02 21:15:33 -05:00
Jose Diaz-Gonzalez
041dc013f9 Merge pull request #458 from Iamrodos/fix-logging
fix: send INFO/DEBUG to stdout, WARNING/ERROR to stderr
2025-12-02 21:14:49 -05:00
Rodos
12802103c4 fix: send INFO/DEBUG to stdout, WARNING/ERROR to stderr
Fixes #182
2025-12-01 16:11:11 +11:00
Rodos
bf28b46954 docs: update README testing section and add fetch vs pull explanation 2025-12-01 15:55:00 +11:00
5 changed files with 74 additions and 16 deletions

View File

@@ -1,10 +1,25 @@
Changelog Changelog
========= =========
0.53.0 (2025-11-30) 0.54.0 (2025-12-03)
------------------- -------------------
------------------------ ------------------------
Fix
~~~
- Send INFO/DEBUG to stdout, WARNING/ERROR to stderr. [Rodos]
Fixes #182
Other
~~~~~
- Docs: update README testing section and add fetch vs pull explanation.
[Rodos]
0.53.0 (2025-11-30)
-------------------
Fix Fix
~~~ ~~~
- Case-sensitive username filtering causing silent backup failures. - Case-sensitive username filtering causing silent backup failures.

View File

@@ -301,6 +301,8 @@ Starred gists vs starred repo behaviour
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. 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.
Note: ``--starred-gists`` only retrieves starred gists for the authenticated user, not the target user, due to a GitHub API limitation.
Skip existing on incomplete backups Skip existing on incomplete backups
----------------------------------- -----------------------------------
@@ -308,6 +310,25 @@ Skip existing on incomplete backups
The ``--skip-existing`` argument will skip a backup if the directory already exists, even if the backup in that directory failed (perhaps due to a blocking error). This may result in unexpected missing data in a regular backup. The ``--skip-existing`` argument will skip a backup if the directory already exists, even if the backup in that directory failed (perhaps due to a blocking error). This may result in unexpected missing data in a regular backup.
Updates use fetch, not pull
---------------------------
When updating an existing repository backup, ``github-backup`` uses ``git fetch`` rather than ``git pull``. This is intentional - a backup tool should reliably download data without risk of failure. Using ``git pull`` would require handling merge conflicts, which adds complexity and could cause backups to fail unexpectedly.
With fetch, **all branches and commits are downloaded** safely into remote-tracking branches. The working directory files won't change, but your backup is complete.
If you look at files directly (e.g., ``cat README.md``), you'll see the old content. The new data is in the remote-tracking branches (confusingly named "remote" but stored locally). To view or use the latest files::
git show origin/main:README.md # view a file
git merge origin/main # update working directory
All branches are backed up as remote refs (``origin/main``, ``origin/feature-branch``, etc.).
If you want to browse files directly without merging, consider using ``--bare`` which skips the working directory entirely - the backup is just the git data.
See `#269 <https://github.com/josegonzalez/python-github-backup/issues/269>`_ for more discussion.
Github Backup Examples Github Backup Examples
====================== ======================
@@ -357,7 +378,12 @@ A huge thanks to all the contibuters!
Testing Testing
------- -------
This project currently contains no unit tests. To run linting:: To run the test suite::
pip install pytest
pytest
To run linting::
pip install flake8 pip install flake8
flake8 --ignore=E501 flake8 --ignore=E501

View File

@@ -16,12 +16,23 @@ from github_backup.github_backup import (
retrieve_repositories, retrieve_repositories,
) )
logging.basicConfig( # INFO and DEBUG go to stdout, WARNING and above go to stderr
format="%(asctime)s.%(msecs)03d: %(message)s", log_format = logging.Formatter(
fmt="%(asctime)s.%(msecs)03d: %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S", datefmt="%Y-%m-%dT%H:%M:%S",
level=logging.INFO,
) )
stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setLevel(logging.DEBUG)
stdout_handler.addFilter(lambda r: r.levelno < logging.WARNING)
stdout_handler.setFormatter(log_format)
stderr_handler = logging.StreamHandler(sys.stderr)
stderr_handler.setLevel(logging.WARNING)
stderr_handler.setFormatter(log_format)
logging.basicConfig(level=logging.INFO, handlers=[stdout_handler, stderr_handler])
def main(): def main():
args = parse_args() args = parse_args()

View File

@@ -1 +1 @@
__version__ = "0.53.0" __version__ = "0.54.0"

View File

@@ -1565,16 +1565,22 @@ def retrieve_repositories(args, authenticated_user):
repos.extend(gists) repos.extend(gists)
if args.include_starred_gists: if args.include_starred_gists:
starred_gists_template = "https://{0}/gists/starred".format( if not authenticated_user.get("login") or args.user.lower() != authenticated_user["login"].lower():
get_github_api_host(args) logger.warning(
) "Cannot retrieve starred gists for '%s'. GitHub only allows access to the authenticated user's starred gists.",
starred_gists = retrieve_data( args.user,
args, starred_gists_template, single_request=False )
) else:
# flag each repo as a starred gist for downstream processing starred_gists_template = "https://{0}/gists/starred".format(
for item in starred_gists: get_github_api_host(args)
item.update({"is_gist": True, "is_starred": True}) )
repos.extend(starred_gists) starred_gists = retrieve_data(
args, starred_gists_template, single_request=False
)
# flag each repo as a starred gist for downstream processing
for item in starred_gists:
item.update({"is_gist": True, "is_starred": True})
repos.extend(starred_gists)
return repos return repos