github-backup 0.64.2__tar.gz → 0.65.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {github_backup-0.64.2 → github_backup-0.65.1}/CHANGES.rst +96 -1
  2. {github_backup-0.64.2/github_backup.egg-info → github_backup-0.65.1}/PKG-INFO +28 -4
  3. {github_backup-0.64.2 → github_backup-0.65.1}/README +27 -3
  4. {github_backup-0.64.2 → github_backup-0.65.1}/README.rst +27 -3
  5. github_backup-0.65.1/github_backup/__init__.py +1 -0
  6. {github_backup-0.64.2 → github_backup-0.65.1}/github_backup/github_backup.py +200 -4
  7. {github_backup-0.64.2 → github_backup-0.65.1}/github_backup/graphql_queries.py +60 -0
  8. {github_backup-0.64.2 → github_backup-0.65.1/github_backup.egg-info}/PKG-INFO +28 -4
  9. {github_backup-0.64.2 → github_backup-0.65.1}/github_backup.egg-info/SOURCES.txt +1 -0
  10. {github_backup-0.64.2 → github_backup-0.65.1}/release-requirements.txt +1 -1
  11. github_backup-0.65.1/tests/test_issue_timeline.py +459 -0
  12. github_backup-0.64.2/github_backup/__init__.py +0 -1
  13. {github_backup-0.64.2 → github_backup-0.65.1}/LICENSE.txt +0 -0
  14. {github_backup-0.64.2 → github_backup-0.65.1}/MANIFEST.in +0 -0
  15. {github_backup-0.64.2 → github_backup-0.65.1}/github_backup/__main__.py +0 -0
  16. {github_backup-0.64.2 → github_backup-0.65.1}/github_backup/cli.py +0 -0
  17. {github_backup-0.64.2 → github_backup-0.65.1}/github_backup.egg-info/dependency_links.txt +0 -0
  18. {github_backup-0.64.2 → github_backup-0.65.1}/github_backup.egg-info/entry_points.txt +0 -0
  19. {github_backup-0.64.2 → github_backup-0.65.1}/github_backup.egg-info/top_level.txt +0 -0
  20. {github_backup-0.64.2 → github_backup-0.65.1}/github_backup.egg-info/zip-safe +0 -0
  21. {github_backup-0.64.2 → github_backup-0.65.1}/requirements.txt +0 -0
  22. {github_backup-0.64.2 → github_backup-0.65.1}/setup.cfg +0 -0
  23. {github_backup-0.64.2 → github_backup-0.65.1}/setup.py +0 -0
  24. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_all_starred.py +0 -0
  25. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_attachments.py +0 -0
  26. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_auth.py +0 -0
  27. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_case_sensitivity.py +0 -0
  28. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_disabled_issues_pulls.py +0 -0
  29. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_discussions.py +0 -0
  30. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_gists.py +0 -0
  31. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_http_451.py +0 -0
  32. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_incremental_per_repository.py +0 -0
  33. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_json_dump_if_changed.py +0 -0
  34. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_logging_subprocess.py +0 -0
  35. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_pagination.py +0 -0
  36. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_pull_incremental_pagination.py +0 -0
  37. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_pull_reviews.py +0 -0
  38. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_releases.py +0 -0
  39. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_retrieve_data.py +0 -0
  40. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_skip_assets_on.py +0 -0
  41. {github_backup-0.64.2 → github_backup-0.65.1}/tests/test_starred_skip_size_over.py +0 -0
@@ -1,9 +1,104 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
- 0.64.2 (2026-07-18)
4
+ 0.65.1 (2026-08-01)
5
5
  -------------------
6
6
  ------------------------
7
+ - Fix timeline not being properly incremental. [Duncan Ogilvie]
8
+ - Chore(deps): bump twine from 6.2.0 to 7.0.0 in the python-packages
9
+ group. [dependabot[bot]]
10
+
11
+ Bumps the python-packages group with 1 update: [twine](https://github.com/pypa/twine).
12
+
13
+
14
+ Updates `twine` from 6.2.0 to 7.0.0
15
+ - [Release notes](https://github.com/pypa/twine/releases)
16
+ - [Changelog](https://github.com/pypa/twine/blob/main/docs/changelog.rst)
17
+ - [Commits](https://github.com/pypa/twine/compare/6.2.0...7.0.0)
18
+
19
+ ---
20
+ updated-dependencies:
21
+ - dependency-name: twine
22
+ dependency-version: 7.0.0
23
+ dependency-type: direct:production
24
+ update-type: version-update:semver-major
25
+ dependency-group: python-packages
26
+ ...
27
+
28
+
29
+ 0.65.0 (2026-07-27)
30
+ -------------------
31
+ - Refresh issue timelines when cross-references change (#168) [Rodos]
32
+
33
+ Cross-references do not change an issue's updated_at, so an incremental
34
+ run never lists the issue and never re-fetches its timeline. An issue
35
+ can be referenced from another repository years after its last activity
36
+ and the backup would never see it.
37
+
38
+ On incremental runs with --issue-timeline, ask GraphQL for each item's
39
+ cross-reference count and newest timestamp, compare both against what is
40
+ already saved, and re-fetch the timeline of anything that differs. Items
41
+ the since listing did not return are fetched individually. Both values
42
+ are needed: the count alone would miss a reference being added and
43
+ another deleted between runs, and the timestamp alone would miss a
44
+ deletion.
45
+
46
+ Pull requests are swept too when they are being stored as issues, which
47
+ is the case unless --pulls is used. They need their own query because
48
+ the issues connection excludes them, and because totalCount ignores the
49
+ itemTypes filter on a pull request although it honours it on an issue,
50
+ so their cross-references are counted from the nodes instead. Where that
51
+ count may have been truncated, the comparison falls back to the
52
+ timestamp alone rather than re-fetching on every run.
53
+
54
+ This costs one rate-limit point per 100 items against the GraphQL quota,
55
+ measured at 6 requests for a repository with 528 issues and pull
56
+ requests, and stores no new state: the comparison is against the
57
+ cross-references already in each item's timeline_data. A GraphQL failure
58
+ warns and leaves the rest of the backup unaffected.
59
+
60
+ Closes #168
61
+ - Add --issue-timeline flag to capture cross-reference events (#168)
62
+ [Rodos]
63
+
64
+ The issue events endpoint never returns cross-references, so an issue
65
+ mentioned from another issue or pull request leaves no trace in the
66
+ backup. GitHub only exposes those through the timeline endpoint. Full
67
+ backups miss them as well as incremental ones.
68
+
69
+ Adds --issue-timeline, which stores the timeline under a separate
70
+ timeline_data key alongside the unmodified event_data. The two
71
+ endpoints are complementary rather than nested: the timeline adds
72
+ cross-references, commits and reviews, while events carries
73
+ referenced entries the timeline drops, so neither replaces the other.
74
+
75
+ Timeline entries for comments are filtered out, since --issue-comments
76
+ already saves the bodies. Everything else is stored verbatim. The flag
77
+ is included in --all.
78
+
79
+ This makes the data obtainable, but does not change incremental
80
+ selection: a cross-reference does not bump the referenced issue's
81
+ updated_at, so an incremental run still never lists it. That half of
82
+ the issue remains open.
83
+
84
+ References #168
85
+ - Chore(deps): bump actions/setup-python from 6 to 7. [dependabot[bot]]
86
+
87
+ Bumps [actions/setup-python](https://github.com/actions/setup-python) from 6 to 7.
88
+ - [Release notes](https://github.com/actions/setup-python/releases)
89
+ - [Commits](https://github.com/actions/setup-python/compare/v6...v7)
90
+
91
+ ---
92
+ updated-dependencies:
93
+ - dependency-name: actions/setup-python
94
+ dependency-version: '7'
95
+ dependency-type: direct:production
96
+ update-type: version-update:semver-major
97
+ ...
98
+
99
+
100
+ 0.64.2 (2026-07-18)
101
+ -------------------
7
102
  - Add tests. [Duncan Ogilvie]
8
103
  - Skip fetching gists that have not been updated. [Duncan Ogilvie]
9
104
  - Skip retrieving repositories when not necessary. [Duncan Ogilvie]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: github-backup
3
- Version: 0.64.2
3
+ Version: 0.65.1
4
4
  Summary: backup a github user or organization
5
5
  Home-page: http://github.com/josegonzalez/python-github-backup
6
6
  Author: Jose Diaz-Gonzalez
@@ -71,7 +71,8 @@ CLI Help output::
71
71
  [--incremental-by-files]
72
72
  [--starred] [--all-starred] [--starred-skip-size-over MB]
73
73
  [--watched] [--followers] [--following] [--all]
74
- [--issues] [--issue-comments] [--issue-events] [--pulls]
74
+ [--issues] [--issue-comments] [--issue-events]
75
+ [--issue-timeline] [--pulls]
75
76
  [--pull-comments] [--pull-reviews] [--pull-commits]
76
77
  [--pull-details]
77
78
  [--labels] [--hooks] [--milestones] [--security-advisories]
@@ -126,6 +127,8 @@ CLI Help output::
126
127
  --issues include issues in backup
127
128
  --issue-comments include issue comments in backup
128
129
  --issue-events include issue events in backup
130
+ --issue-timeline include issue timeline in backup (cross-references,
131
+ commits and reviews; complements --issue-events)
129
132
  --pulls include pull requests in backup
130
133
  --pull-comments include pull request review comments in backup
131
134
  --pull-reviews include pull request reviews in backup
@@ -377,6 +380,27 @@ For finer control, avoid using ``--assets`` with starred repos, or use ``--skip-
377
380
 
378
381
  Alternatively, consider just storing links to starred repos in JSON format with ``--starred``.
379
382
 
383
+
384
+ About issue events and the issue timeline
385
+ -----------------------------------------
386
+
387
+ Use ``--issue-events`` and ``--issue-timeline`` with ``--issues``; on their own they back up nothing.
388
+
389
+ ``--issue-events`` backs up GitHub's issue events endpoint under each issue's ``event_data`` key. That endpoint returns a restricted set of event types and **never** includes cross-references, so an issue that was mentioned from another issue or pull request shows no sign of it. GitHub only exposes those through the timeline.
390
+
391
+ ``--issue-timeline`` backs up the timeline endpoint under a separate ``timeline_data`` key. The two flags are independent: ``event_data`` keeps its existing contents and shape whether or not the timeline is enabled, so nothing that already reads it is affected.
392
+
393
+ Use both flags together for a complete picture. Neither endpoint is a superset of the other, so they are complementary rather than alternatives. Only the timeline reports ``cross-referenced``, ``committed`` and ``reviewed`` entries. Only the events endpoint reliably reports ``referenced`` entries, where a commit elsewhere in the repository mentions the issue; the timeline omits many of these, substituting the issue's own ``committed`` entries instead.
394
+
395
+ Note that timeline entries are not all the same shape as events. ``cross-referenced`` and ``committed`` entries have no ``id`` field, so anything consuming ``timeline_data`` should not assume one is present. ``commented`` entries are excluded from the backup because they embed the full comment body, which ``--issue-comments`` already saves.
396
+
397
+ ``--issue-timeline`` is included in ``--all``. On issues with many cross-references it can be noticeably larger and slower than ``--issue-events`` alone, because each ``cross-referenced`` entry embeds the referencing issue in full. On a heavily cross-referenced issue this can mean several times the API requests and many times the JSON on disk. Ordinary repositories see little difference.
398
+
399
+ Incremental backups need extra help here, because being referenced from elsewhere does not change an issue's ``updated_at``. An issue can be mentioned from another repository years after its last activity, and the usual ``since`` listing will never report it as changed. On an incremental run with ``--issue-timeline``, github-backup therefore asks GitHub's GraphQL API for each item's cross-reference count and newest timestamp, compares those against what is already saved, and re-fetches the timeline of anything that differs. Pull requests are included in that check when they are being stored as issues, which is the case unless ``--pulls`` is used. The check needs no extra state on disk and also notices references that were later deleted. It costs one rate-limit point per 100 items checked, against GitHub's GraphQL quota, which is separate from the REST one. That is cheap in quota terms even on very large repositories, but it is not instant: a repository with 18,000 issues and pull requests took around 200 points and five minutes for the check alone.
400
+
401
+ If you enable ``--issue-timeline`` on an existing incremental backup, cross-references on older issues are picked up automatically by that check. Timeline entries of other kinds, such as commits and reviews, are only fetched when the issue itself is updated, so run once without ``--incremental`` if you want those filled in for historical issues too.
402
+
403
+
380
404
  About pull request reviews
381
405
  --------------------------
382
406
 
@@ -480,14 +504,14 @@ Quietly and incrementally backup useful Github user data (public and private rep
480
504
  FINE_ACCESS_TOKEN=SOME-GITHUB-TOKEN
481
505
  GH_USER=YOUR-GITHUB-USER
482
506
 
483
- github-backup -f $FINE_ACCESS_TOKEN --prefer-ssh -o ~/github-backup/ -l error -P -i --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --security-advisories --discussions --repositories --wikis --releases --assets --attachments --pull-details --gists --starred-gists $GH_USER
507
+ github-backup -f $FINE_ACCESS_TOKEN --prefer-ssh -o ~/github-backup/ -l error -P -i --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --issue-timeline --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --security-advisories --discussions --repositories --wikis --releases --assets --attachments --pull-details --gists --starred-gists $GH_USER
484
508
 
485
509
  Debug an error/block or incomplete backup into a temporary directory. Omit "incremental" to fill a previous incomplete backup. ::
486
510
 
487
511
  FINE_ACCESS_TOKEN=SOME-GITHUB-TOKEN
488
512
  GH_USER=YOUR-GITHUB-USER
489
513
 
490
- github-backup -f $FINE_ACCESS_TOKEN -o /tmp/github-backup/ -l debug -P --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --discussions --repositories --wikis --releases --assets --pull-details --gists --starred-gists $GH_USER
514
+ github-backup -f $FINE_ACCESS_TOKEN -o /tmp/github-backup/ -l debug -P --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --issue-timeline --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --discussions --repositories --wikis --releases --assets --pull-details --gists --starred-gists $GH_USER
491
515
 
492
516
  Pipe a token from stdin to avoid storing it in environment variables or command history (Unix-like systems only)::
493
517
 
@@ -41,7 +41,8 @@ CLI Help output::
41
41
  [--incremental-by-files]
42
42
  [--starred] [--all-starred] [--starred-skip-size-over MB]
43
43
  [--watched] [--followers] [--following] [--all]
44
- [--issues] [--issue-comments] [--issue-events] [--pulls]
44
+ [--issues] [--issue-comments] [--issue-events]
45
+ [--issue-timeline] [--pulls]
45
46
  [--pull-comments] [--pull-reviews] [--pull-commits]
46
47
  [--pull-details]
47
48
  [--labels] [--hooks] [--milestones] [--security-advisories]
@@ -96,6 +97,8 @@ CLI Help output::
96
97
  --issues include issues in backup
97
98
  --issue-comments include issue comments in backup
98
99
  --issue-events include issue events in backup
100
+ --issue-timeline include issue timeline in backup (cross-references,
101
+ commits and reviews; complements --issue-events)
99
102
  --pulls include pull requests in backup
100
103
  --pull-comments include pull request review comments in backup
101
104
  --pull-reviews include pull request reviews in backup
@@ -347,6 +350,27 @@ For finer control, avoid using ``--assets`` with starred repos, or use ``--skip-
347
350
 
348
351
  Alternatively, consider just storing links to starred repos in JSON format with ``--starred``.
349
352
 
353
+
354
+ About issue events and the issue timeline
355
+ -----------------------------------------
356
+
357
+ Use ``--issue-events`` and ``--issue-timeline`` with ``--issues``; on their own they back up nothing.
358
+
359
+ ``--issue-events`` backs up GitHub's issue events endpoint under each issue's ``event_data`` key. That endpoint returns a restricted set of event types and **never** includes cross-references, so an issue that was mentioned from another issue or pull request shows no sign of it. GitHub only exposes those through the timeline.
360
+
361
+ ``--issue-timeline`` backs up the timeline endpoint under a separate ``timeline_data`` key. The two flags are independent: ``event_data`` keeps its existing contents and shape whether or not the timeline is enabled, so nothing that already reads it is affected.
362
+
363
+ Use both flags together for a complete picture. Neither endpoint is a superset of the other, so they are complementary rather than alternatives. Only the timeline reports ``cross-referenced``, ``committed`` and ``reviewed`` entries. Only the events endpoint reliably reports ``referenced`` entries, where a commit elsewhere in the repository mentions the issue; the timeline omits many of these, substituting the issue's own ``committed`` entries instead.
364
+
365
+ Note that timeline entries are not all the same shape as events. ``cross-referenced`` and ``committed`` entries have no ``id`` field, so anything consuming ``timeline_data`` should not assume one is present. ``commented`` entries are excluded from the backup because they embed the full comment body, which ``--issue-comments`` already saves.
366
+
367
+ ``--issue-timeline`` is included in ``--all``. On issues with many cross-references it can be noticeably larger and slower than ``--issue-events`` alone, because each ``cross-referenced`` entry embeds the referencing issue in full. On a heavily cross-referenced issue this can mean several times the API requests and many times the JSON on disk. Ordinary repositories see little difference.
368
+
369
+ Incremental backups need extra help here, because being referenced from elsewhere does not change an issue's ``updated_at``. An issue can be mentioned from another repository years after its last activity, and the usual ``since`` listing will never report it as changed. On an incremental run with ``--issue-timeline``, github-backup therefore asks GitHub's GraphQL API for each item's cross-reference count and newest timestamp, compares those against what is already saved, and re-fetches the timeline of anything that differs. Pull requests are included in that check when they are being stored as issues, which is the case unless ``--pulls`` is used. The check needs no extra state on disk and also notices references that were later deleted. It costs one rate-limit point per 100 items checked, against GitHub's GraphQL quota, which is separate from the REST one. That is cheap in quota terms even on very large repositories, but it is not instant: a repository with 18,000 issues and pull requests took around 200 points and five minutes for the check alone.
370
+
371
+ If you enable ``--issue-timeline`` on an existing incremental backup, cross-references on older issues are picked up automatically by that check. Timeline entries of other kinds, such as commits and reviews, are only fetched when the issue itself is updated, so run once without ``--incremental`` if you want those filled in for historical issues too.
372
+
373
+
350
374
  About pull request reviews
351
375
  --------------------------
352
376
 
@@ -450,14 +474,14 @@ Quietly and incrementally backup useful Github user data (public and private rep
450
474
  FINE_ACCESS_TOKEN=SOME-GITHUB-TOKEN
451
475
  GH_USER=YOUR-GITHUB-USER
452
476
 
453
- github-backup -f $FINE_ACCESS_TOKEN --prefer-ssh -o ~/github-backup/ -l error -P -i --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --security-advisories --discussions --repositories --wikis --releases --assets --attachments --pull-details --gists --starred-gists $GH_USER
477
+ github-backup -f $FINE_ACCESS_TOKEN --prefer-ssh -o ~/github-backup/ -l error -P -i --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --issue-timeline --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --security-advisories --discussions --repositories --wikis --releases --assets --attachments --pull-details --gists --starred-gists $GH_USER
454
478
 
455
479
  Debug an error/block or incomplete backup into a temporary directory. Omit "incremental" to fill a previous incomplete backup. ::
456
480
 
457
481
  FINE_ACCESS_TOKEN=SOME-GITHUB-TOKEN
458
482
  GH_USER=YOUR-GITHUB-USER
459
483
 
460
- github-backup -f $FINE_ACCESS_TOKEN -o /tmp/github-backup/ -l debug -P --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --discussions --repositories --wikis --releases --assets --pull-details --gists --starred-gists $GH_USER
484
+ github-backup -f $FINE_ACCESS_TOKEN -o /tmp/github-backup/ -l debug -P --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --issue-timeline --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --discussions --repositories --wikis --releases --assets --pull-details --gists --starred-gists $GH_USER
461
485
 
462
486
  Pipe a token from stdin to avoid storing it in environment variables or command history (Unix-like systems only)::
463
487
 
@@ -41,7 +41,8 @@ CLI Help output::
41
41
  [--incremental-by-files]
42
42
  [--starred] [--all-starred] [--starred-skip-size-over MB]
43
43
  [--watched] [--followers] [--following] [--all]
44
- [--issues] [--issue-comments] [--issue-events] [--pulls]
44
+ [--issues] [--issue-comments] [--issue-events]
45
+ [--issue-timeline] [--pulls]
45
46
  [--pull-comments] [--pull-reviews] [--pull-commits]
46
47
  [--pull-details]
47
48
  [--labels] [--hooks] [--milestones] [--security-advisories]
@@ -96,6 +97,8 @@ CLI Help output::
96
97
  --issues include issues in backup
97
98
  --issue-comments include issue comments in backup
98
99
  --issue-events include issue events in backup
100
+ --issue-timeline include issue timeline in backup (cross-references,
101
+ commits and reviews; complements --issue-events)
99
102
  --pulls include pull requests in backup
100
103
  --pull-comments include pull request review comments in backup
101
104
  --pull-reviews include pull request reviews in backup
@@ -347,6 +350,27 @@ For finer control, avoid using ``--assets`` with starred repos, or use ``--skip-
347
350
 
348
351
  Alternatively, consider just storing links to starred repos in JSON format with ``--starred``.
349
352
 
353
+
354
+ About issue events and the issue timeline
355
+ -----------------------------------------
356
+
357
+ Use ``--issue-events`` and ``--issue-timeline`` with ``--issues``; on their own they back up nothing.
358
+
359
+ ``--issue-events`` backs up GitHub's issue events endpoint under each issue's ``event_data`` key. That endpoint returns a restricted set of event types and **never** includes cross-references, so an issue that was mentioned from another issue or pull request shows no sign of it. GitHub only exposes those through the timeline.
360
+
361
+ ``--issue-timeline`` backs up the timeline endpoint under a separate ``timeline_data`` key. The two flags are independent: ``event_data`` keeps its existing contents and shape whether or not the timeline is enabled, so nothing that already reads it is affected.
362
+
363
+ Use both flags together for a complete picture. Neither endpoint is a superset of the other, so they are complementary rather than alternatives. Only the timeline reports ``cross-referenced``, ``committed`` and ``reviewed`` entries. Only the events endpoint reliably reports ``referenced`` entries, where a commit elsewhere in the repository mentions the issue; the timeline omits many of these, substituting the issue's own ``committed`` entries instead.
364
+
365
+ Note that timeline entries are not all the same shape as events. ``cross-referenced`` and ``committed`` entries have no ``id`` field, so anything consuming ``timeline_data`` should not assume one is present. ``commented`` entries are excluded from the backup because they embed the full comment body, which ``--issue-comments`` already saves.
366
+
367
+ ``--issue-timeline`` is included in ``--all``. On issues with many cross-references it can be noticeably larger and slower than ``--issue-events`` alone, because each ``cross-referenced`` entry embeds the referencing issue in full. On a heavily cross-referenced issue this can mean several times the API requests and many times the JSON on disk. Ordinary repositories see little difference.
368
+
369
+ Incremental backups need extra help here, because being referenced from elsewhere does not change an issue's ``updated_at``. An issue can be mentioned from another repository years after its last activity, and the usual ``since`` listing will never report it as changed. On an incremental run with ``--issue-timeline``, github-backup therefore asks GitHub's GraphQL API for each item's cross-reference count and newest timestamp, compares those against what is already saved, and re-fetches the timeline of anything that differs. Pull requests are included in that check when they are being stored as issues, which is the case unless ``--pulls`` is used. The check needs no extra state on disk and also notices references that were later deleted. It costs one rate-limit point per 100 items checked, against GitHub's GraphQL quota, which is separate from the REST one. That is cheap in quota terms even on very large repositories, but it is not instant: a repository with 18,000 issues and pull requests took around 200 points and five minutes for the check alone.
370
+
371
+ If you enable ``--issue-timeline`` on an existing incremental backup, cross-references on older issues are picked up automatically by that check. Timeline entries of other kinds, such as commits and reviews, are only fetched when the issue itself is updated, so run once without ``--incremental`` if you want those filled in for historical issues too.
372
+
373
+
350
374
  About pull request reviews
351
375
  --------------------------
352
376
 
@@ -450,14 +474,14 @@ Quietly and incrementally backup useful Github user data (public and private rep
450
474
  FINE_ACCESS_TOKEN=SOME-GITHUB-TOKEN
451
475
  GH_USER=YOUR-GITHUB-USER
452
476
 
453
- github-backup -f $FINE_ACCESS_TOKEN --prefer-ssh -o ~/github-backup/ -l error -P -i --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --security-advisories --discussions --repositories --wikis --releases --assets --attachments --pull-details --gists --starred-gists $GH_USER
477
+ github-backup -f $FINE_ACCESS_TOKEN --prefer-ssh -o ~/github-backup/ -l error -P -i --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --issue-timeline --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --security-advisories --discussions --repositories --wikis --releases --assets --attachments --pull-details --gists --starred-gists $GH_USER
454
478
 
455
479
  Debug an error/block or incomplete backup into a temporary directory. Omit "incremental" to fill a previous incomplete backup. ::
456
480
 
457
481
  FINE_ACCESS_TOKEN=SOME-GITHUB-TOKEN
458
482
  GH_USER=YOUR-GITHUB-USER
459
483
 
460
- github-backup -f $FINE_ACCESS_TOKEN -o /tmp/github-backup/ -l debug -P --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --discussions --repositories --wikis --releases --assets --pull-details --gists --starred-gists $GH_USER
484
+ github-backup -f $FINE_ACCESS_TOKEN -o /tmp/github-backup/ -l debug -P --all-starred --starred --watched --followers --following --issues --issue-comments --issue-events --issue-timeline --pulls --pull-comments --pull-reviews --pull-commits --labels --milestones --discussions --repositories --wikis --releases --assets --pull-details --gists --starred-gists $GH_USER
461
485
 
462
486
  Pipe a token from stdin to avoid storing it in environment variables or command history (Unix-like systems only)::
463
487
 
@@ -0,0 +1 @@
1
+ __version__ = "0.65.1"
@@ -18,6 +18,7 @@ import subprocess
18
18
  import sys
19
19
  import threading
20
20
  import time
21
+ import traceback
21
22
  from collections.abc import Generator
22
23
  from datetime import datetime
23
24
  from http.client import IncompleteRead
@@ -33,10 +34,14 @@ except ImportError:
33
34
  VERSION = "unknown"
34
35
 
35
36
  from .graphql_queries import (
37
+ CROSS_REFERENCE_NODE_LIMIT,
38
+ CROSS_REFERENCE_PAGE_SIZE,
36
39
  DISCUSSION_DETAIL_QUERY,
37
40
  DISCUSSION_LIST_QUERY,
38
41
  DISCUSSION_PAGE_SIZE,
39
42
  DISCUSSION_REPLIES_QUERY,
43
+ ISSUE_CROSS_REFERENCE_COUNT_QUERY,
44
+ PULL_CROSS_REFERENCE_COUNT_QUERY,
40
45
  )
41
46
 
42
47
  FILE_URI_PREFIX = "file://"
@@ -278,6 +283,12 @@ def parse_args(args=None):
278
283
  dest="include_issue_events",
279
284
  help="include issue events in backup",
280
285
  )
286
+ parser.add_argument(
287
+ "--issue-timeline",
288
+ action="store_true",
289
+ dest="include_issue_timeline",
290
+ help="include issue timeline in backup (cross-references, commits and reviews; complements --issue-events)",
291
+ )
281
292
  parser.add_argument(
282
293
  "--pulls",
283
294
  action="store_true",
@@ -2569,6 +2580,141 @@ def backup_discussions(args, repo_cwd, repository):
2569
2580
  )
2570
2581
 
2571
2582
 
2583
+ def cross_reference_state(timeline_data):
2584
+ """Return (count, newest timestamp) of the cross-references in a timeline."""
2585
+ created = [
2586
+ item.get("created_at")
2587
+ for item in timeline_data or []
2588
+ if item.get("event") == "cross-referenced"
2589
+ ]
2590
+ return len(created), max((c for c in created if c), default=None)
2591
+
2592
+
2593
+ def _cross_reference_page(args, repository, query, connection, use_total_count):
2594
+ """Page one GraphQL connection, yielding {number: (count, newest)}.
2595
+
2596
+ totalCount honours the itemTypes filter on issues but not on pull
2597
+ requests, so pull request cross-references are counted from the nodes.
2598
+ """
2599
+ owner, name = _repository_owner_name(repository)
2600
+ state = {}
2601
+ after = None
2602
+ page = 1
2603
+
2604
+ while True:
2605
+ variables = {
2606
+ "owner": owner,
2607
+ "name": name,
2608
+ "after": after,
2609
+ "pageSize": CROSS_REFERENCE_PAGE_SIZE,
2610
+ }
2611
+ if not use_total_count:
2612
+ # Only the pull request query declares this.
2613
+ variables["nodeLimit"] = CROSS_REFERENCE_NODE_LIMIT
2614
+
2615
+ data = retrieve_graphql_data(
2616
+ args,
2617
+ query,
2618
+ variables,
2619
+ log_context="cross-references {0} {1} page {2}".format(
2620
+ repository["full_name"], connection, page
2621
+ ),
2622
+ )
2623
+ repository_data = data.get("repository")
2624
+ if repository_data is None:
2625
+ raise Exception(
2626
+ "Repository {0} not found in GraphQL response".format(
2627
+ repository["full_name"]
2628
+ )
2629
+ )
2630
+
2631
+ items = repository_data.get(connection) or {}
2632
+ for node in _connection_nodes(items):
2633
+ timeline = node.get("timelineItems") or {}
2634
+ created = [n.get("createdAt") for n in timeline.get("nodes") or [] if n]
2635
+ if use_total_count:
2636
+ count = timeline.get("totalCount", 0)
2637
+ elif len(created) >= CROSS_REFERENCE_NODE_LIMIT:
2638
+ # Counted from the nodes, so it may be truncated. Compare on
2639
+ # the timestamp alone rather than on a count we cannot trust.
2640
+ count = None
2641
+ else:
2642
+ count = len(created)
2643
+ state[node["number"]] = (count, created[-1] if created else None)
2644
+
2645
+ page_info = items.get("pageInfo") or {}
2646
+ if not page_info.get("hasNextPage"):
2647
+ break
2648
+
2649
+ after = page_info.get("endCursor")
2650
+ page += 1
2651
+
2652
+ return state
2653
+
2654
+
2655
+ def retrieve_cross_reference_state(args, repository, include_pulls=False):
2656
+ """Ask GitHub for each item's cross-reference count and newest timestamp."""
2657
+ state = _cross_reference_page(
2658
+ args,
2659
+ repository,
2660
+ ISSUE_CROSS_REFERENCE_COUNT_QUERY,
2661
+ "issues",
2662
+ use_total_count=True,
2663
+ )
2664
+ if include_pulls:
2665
+ state.update(
2666
+ _cross_reference_page(
2667
+ args,
2668
+ repository,
2669
+ PULL_CROSS_REFERENCE_COUNT_QUERY,
2670
+ "pullRequests",
2671
+ use_total_count=False,
2672
+ )
2673
+ )
2674
+ return state
2675
+
2676
+
2677
+ def find_stale_timeline_issues(args, issue_cwd, repository, include_pulls=False):
2678
+ """Issue numbers whose stored cross-references no longer match GitHub's.
2679
+
2680
+ Incremental runs select issues by updated_at, which a cross-reference does
2681
+ not change, so those issues would otherwise never be revisited.
2682
+ """
2683
+ if not get_graphql_auth(args):
2684
+ # The check needs the GraphQL API, which always requires a token.
2685
+ logger.debug("Skipping cross-reference check, no authentication")
2686
+ return set()
2687
+
2688
+ try:
2689
+ live = retrieve_cross_reference_state(args, repository, include_pulls)
2690
+ except Exception as e:
2691
+ logger.warning(
2692
+ "Unable to check {0} for new cross-references, "
2693
+ "issues referenced since the last backup may be missed: {1}".format(
2694
+ repository["full_name"], e
2695
+ )
2696
+ )
2697
+ logger.debug(traceback.format_exc())
2698
+ return set()
2699
+
2700
+ stale = set()
2701
+ for number, (count, newest) in live.items():
2702
+ existing = read_json_file_if_exists("{0}/{1}.json".format(issue_cwd, number))
2703
+ if existing is None:
2704
+ continue
2705
+ stored = cross_reference_state(existing.get("timeline_data"))
2706
+ changed = stored[1] != newest if count is None else stored != (count, newest)
2707
+ if changed:
2708
+ stale.add(number)
2709
+
2710
+ if stale:
2711
+ logger.info(
2712
+ "Refreshing {0} issues with new cross-references".format(len(stale))
2713
+ )
2714
+ logger.debug("Stale timelines: {0}".format(sorted(stale)))
2715
+ return stale
2716
+
2717
+
2572
2718
  def backup_issues(args, repo_cwd, repository, repos_template):
2573
2719
  has_issues_dir = os.path.isdir("{0}/issues/.git".format(repo_cwd))
2574
2720
  if args.skip_existing and has_issues_dir:
@@ -2584,6 +2730,7 @@ def backup_issues(args, repo_cwd, repository, repos_template):
2584
2730
  _issue_template = "{0}/{1}/issues".format(repos_template, repository["full_name"])
2585
2731
 
2586
2732
  should_include_pulls = args.include_pulls or args.include_everything
2733
+ include_timeline = args.include_issue_timeline or args.include_everything
2587
2734
  issue_states = ["open", "closed"]
2588
2735
  for issue_state in issue_states:
2589
2736
  query_args = {"filter": "all", "state": issue_state}
@@ -2600,6 +2747,35 @@ def backup_issues(args, repo_cwd, repository, repos_template):
2600
2747
 
2601
2748
  issues[issue["number"]] = issue
2602
2749
 
2750
+ stale_timelines = set()
2751
+ incremental_run = args.since or args.incremental_by_files
2752
+ if (
2753
+ include_timeline
2754
+ and incremental_run
2755
+ and any(f.endswith(".json") for f in os.listdir(issue_cwd))
2756
+ ):
2757
+ stale_timelines = find_stale_timeline_issues(
2758
+ args, issue_cwd, repository, include_pulls=not should_include_pulls
2759
+ )
2760
+
2761
+ # Issues selected only by the cross-reference sweep have not otherwise
2762
+ # changed. Reuse their complete stored payload and refresh only timeline_data.
2763
+ # Fetching the issue, comments, events and attachments again turns the first
2764
+ # --issue-timeline run into a near-full backup and can discard optional data
2765
+ # when the corresponding flags are absent.
2766
+ timeline_only_issues = stale_timelines - set(issues)
2767
+ for number in sorted(timeline_only_issues):
2768
+ existing = read_json_file_if_exists(
2769
+ "{0}/{1}.json".format(issue_cwd, number)
2770
+ )
2771
+ if existing is None:
2772
+ logger.warning(
2773
+ "Unable to refresh cross-references for issue {0}: "
2774
+ "stored issue data is unreadable".format(number)
2775
+ )
2776
+ continue
2777
+ issues[number] = existing
2778
+
2603
2779
  if issues_skipped:
2604
2780
  issues_skipped_message = " (skipped {0} pull requests)".format(issues_skipped)
2605
2781
 
@@ -2610,9 +2786,15 @@ def backup_issues(args, repo_cwd, repository, repos_template):
2610
2786
  )
2611
2787
  comments_template = _issue_template + "/{0}/comments"
2612
2788
  events_template = _issue_template + "/{0}/events"
2789
+ timeline_template = _issue_template + "/{0}/timeline"
2613
2790
  for number, issue in list(issues.items()):
2614
2791
  issue_file = "{0}/{1}.json".format(issue_cwd, number)
2615
- if args.incremental_by_files and os.path.isfile(issue_file):
2792
+ timeline_only_refresh = number in timeline_only_issues
2793
+ if (
2794
+ args.incremental_by_files
2795
+ and os.path.isfile(issue_file)
2796
+ and number not in stale_timelines
2797
+ ):
2616
2798
  modified = os.path.getmtime(issue_file)
2617
2799
  modified = datetime.fromtimestamp(modified).strftime("%Y-%m-%dT%H:%M:%SZ")
2618
2800
  if modified > issue["updated_at"]:
@@ -2623,13 +2805,27 @@ def backup_issues(args, repo_cwd, repository, repos_template):
2623
2805
  )
2624
2806
  continue
2625
2807
 
2626
- if args.include_issue_comments or args.include_everything:
2808
+ if not timeline_only_refresh and (
2809
+ args.include_issue_comments or args.include_everything
2810
+ ):
2627
2811
  template = comments_template.format(number)
2628
2812
  issues[number]["comment_data"] = retrieve_data(args, template)
2629
- if args.include_issue_events or args.include_everything:
2813
+ if not timeline_only_refresh and (
2814
+ args.include_issue_events or args.include_everything
2815
+ ):
2630
2816
  template = events_template.format(number)
2631
2817
  issues[number]["event_data"] = retrieve_data(args, template)
2632
- if args.include_attachments:
2818
+ if include_timeline:
2819
+ template = timeline_template.format(number)
2820
+ # "commented" timeline entries embed the full comment body, which
2821
+ # --issue-comments already backs up; storing them twice invites the
2822
+ # two copies to diverge.
2823
+ issues[number]["timeline_data"] = [
2824
+ item
2825
+ for item in retrieve_data(args, template)
2826
+ if item.get("event") != "commented"
2827
+ ]
2828
+ if args.include_attachments and not timeline_only_refresh:
2633
2829
  download_attachments(
2634
2830
  args, issue_cwd, issues[number], number, repository, item_type="issue"
2635
2831
  )
@@ -2,6 +2,66 @@
2
2
 
3
3
  DISCUSSION_PAGE_SIZE = 100
4
4
 
5
+ CROSS_REFERENCE_PAGE_SIZE = 100
6
+
7
+ # Cross-references do not change an issue's updatedAt, so the REST listing
8
+ # cannot report them as changed. Count and newest timestamp are compared
9
+ # against what is on disk: the count alone would miss an add paired with a
10
+ # delete, the timestamp alone would miss a delete.
11
+ ISSUE_CROSS_REFERENCE_COUNT_QUERY = """
12
+ query($owner: String!, $name: String!, $after: String, $pageSize: Int!) {
13
+ repository(owner: $owner, name: $name) {
14
+ issues(first: $pageSize, after: $after) {
15
+ nodes {
16
+ number
17
+ timelineItems(last: 1, itemTypes: [CROSS_REFERENCED_EVENT]) {
18
+ totalCount
19
+ nodes {
20
+ ... on CrossReferencedEvent {
21
+ createdAt
22
+ }
23
+ }
24
+ }
25
+ }
26
+ pageInfo {
27
+ hasNextPage
28
+ endCursor
29
+ }
30
+ }
31
+ }
32
+ }
33
+ """
34
+
35
+ # Pull requests are stored as issues when --pulls is not used, and the issues
36
+ # connection above excludes them. This query is shaped differently because
37
+ # totalCount ignores itemTypes on a pull request, unlike on an issue, so the
38
+ # cross-references have to be counted from the nodes themselves.
39
+ CROSS_REFERENCE_NODE_LIMIT = 100
40
+
41
+ PULL_CROSS_REFERENCE_COUNT_QUERY = """
42
+ query($owner: String!, $name: String!, $after: String, $pageSize: Int!,
43
+ $nodeLimit: Int!) {
44
+ repository(owner: $owner, name: $name) {
45
+ pullRequests(first: $pageSize, after: $after) {
46
+ nodes {
47
+ number
48
+ timelineItems(last: $nodeLimit, itemTypes: [CROSS_REFERENCED_EVENT]) {
49
+ nodes {
50
+ ... on CrossReferencedEvent {
51
+ createdAt
52
+ }
53
+ }
54
+ }
55
+ }
56
+ pageInfo {
57
+ hasNextPage
58
+ endCursor
59
+ }
60
+ }
61
+ }
62
+ }
63
+ """
64
+
5
65
  DISCUSSION_LIST_QUERY = """
6
66
  query($owner: String!, $name: String!, $after: String, $pageSize: Int!) {
7
67
  repository(owner: $owner, name: $name) {