github-backup 0.51.2__py3-none-any.whl → 0.51.3__py3-none-any.whl

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.
github_backup/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.51.2"
1
+ __version__ = "0.51.3"
@@ -592,27 +592,26 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
592
592
  auth = get_auth(args, encode=not args.as_app)
593
593
  query_args = get_query_args(query_args)
594
594
  per_page = 100
595
- page = 0
595
+ next_url = None
596
596
 
597
597
  while True:
598
598
  if single_request:
599
- request_page, request_per_page = None, None
599
+ request_per_page = None
600
600
  else:
601
- page = page + 1
602
- request_page, request_per_page = page, per_page
601
+ request_per_page = per_page
603
602
 
604
603
  request = _construct_request(
605
604
  request_per_page,
606
- request_page,
607
605
  query_args,
608
- template,
606
+ next_url or template,
609
607
  auth,
610
608
  as_app=args.as_app,
611
609
  fine=True if args.token_fine is not None else False,
612
610
  ) # noqa
613
- r, errors = _get_response(request, auth, template)
611
+ r, errors = _get_response(request, auth, next_url or template)
614
612
 
615
613
  status_code = int(r.getcode())
614
+
616
615
  # Check if we got correct data
617
616
  try:
618
617
  response = json.loads(r.read().decode("utf-8"))
@@ -644,15 +643,14 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
644
643
  retries += 1
645
644
  time.sleep(5)
646
645
  request = _construct_request(
647
- per_page,
648
- page,
646
+ request_per_page,
649
647
  query_args,
650
- template,
648
+ next_url or template,
651
649
  auth,
652
650
  as_app=args.as_app,
653
651
  fine=True if args.token_fine is not None else False,
654
652
  ) # noqa
655
- r, errors = _get_response(request, auth, template)
653
+ r, errors = _get_response(request, auth, next_url or template)
656
654
 
657
655
  status_code = int(r.getcode())
658
656
  try:
@@ -682,7 +680,16 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
682
680
  if type(response) is list:
683
681
  for resp in response:
684
682
  yield resp
685
- if len(response) < per_page:
683
+ # Parse Link header for next page URL (cursor-based pagination)
684
+ link_header = r.headers.get("Link", "")
685
+ next_url = None
686
+ if link_header:
687
+ # Parse Link header: <https://api.github.com/...?per_page=100&after=cursor>; rel="next"
688
+ for link in link_header.split(","):
689
+ if 'rel="next"' in link:
690
+ next_url = link[link.find("<") + 1:link.find(">")]
691
+ break
692
+ if not next_url:
686
693
  break
687
694
  elif type(response) is dict and single_request:
688
695
  yield response
@@ -735,22 +742,27 @@ def _get_response(request, auth, template):
735
742
 
736
743
 
737
744
  def _construct_request(
738
- per_page, page, query_args, template, auth, as_app=None, fine=False
745
+ per_page, query_args, template, auth, as_app=None, fine=False
739
746
  ):
740
- all_query_args = {}
741
- if per_page:
742
- all_query_args["per_page"] = per_page
743
- if page:
744
- all_query_args["page"] = page
745
- if query_args:
746
- all_query_args.update(query_args)
747
-
748
- request_url = template
749
- if all_query_args:
750
- querystring = urlencode(all_query_args)
751
- request_url = template + "?" + querystring
747
+ # If template is already a full URL with query params (from Link header), use it directly
748
+ if "?" in template and template.startswith("http"):
749
+ request_url = template
750
+ # Extract query string for logging
751
+ querystring = template.split("?", 1)[1]
752
752
  else:
753
- querystring = ""
753
+ # Build URL with query parameters
754
+ all_query_args = {}
755
+ if per_page:
756
+ all_query_args["per_page"] = per_page
757
+ if query_args:
758
+ all_query_args.update(query_args)
759
+
760
+ request_url = template
761
+ if all_query_args:
762
+ querystring = urlencode(all_query_args)
763
+ request_url = template + "?" + querystring
764
+ else:
765
+ querystring = ""
754
766
 
755
767
  request = Request(request_url)
756
768
  if auth is not None:
@@ -766,7 +778,7 @@ def _construct_request(
766
778
  "Accept", "application/vnd.github.machine-man-preview+json"
767
779
  )
768
780
 
769
- log_url = template
781
+ log_url = template if "?" not in template else template.split("?")[0]
770
782
  if querystring:
771
783
  log_url += "?" + querystring
772
784
  logger.info("Requesting {}".format(log_url))
@@ -843,8 +855,7 @@ def download_file(url, path, auth, as_app=False, fine=False):
843
855
  return
844
856
 
845
857
  request = _construct_request(
846
- per_page=100,
847
- page=1,
858
+ per_page=None,
848
859
  query_args={},
849
860
  template=url,
850
861
  auth=auth,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: github-backup
3
- Version: 0.51.2
3
+ Version: 0.51.3
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
@@ -0,0 +1,9 @@
1
+ github_backup/__init__.py,sha256=sAWIo0cwKX_KPS0IfEe_3-fBMoQG8DTarkiPtqUIFPA,23
2
+ github_backup/github_backup.py,sha256=mNTcVRvdVEt5M8LNCO6zXV0c7g2w_Mm8Rb4Cv6jo2yA,76237
3
+ github_backup-0.51.3.data/scripts/github-backup,sha256=I79TNA67phytRmI9nm_LlD9h2zauXFOsOn9tYyAy9pU,1546
4
+ github_backup-0.51.3.dist-info/licenses/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
5
+ github_backup-0.51.3.dist-info/METADATA,sha256=JstsidKzhrLnOHESpVtf2-s4a_6oUCb8y_PIMiCVfas,21544
6
+ github_backup-0.51.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ github_backup-0.51.3.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
8
+ github_backup-0.51.3.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
9
+ github_backup-0.51.3.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- github_backup/__init__.py,sha256=2AuLzuHMBBPVOM-m0Woty11pTO9ExwPKWRWtj1LvS-g,23
2
- github_backup/github_backup.py,sha256=ousskr9hBtfKgAh1x78vnSefQhPGqa9K2fLxWLUKdyY,75428
3
- github_backup-0.51.2.data/scripts/github-backup,sha256=I79TNA67phytRmI9nm_LlD9h2zauXFOsOn9tYyAy9pU,1546
4
- github_backup-0.51.2.dist-info/licenses/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
5
- github_backup-0.51.2.dist-info/METADATA,sha256=zoLPP4sNYwAsnFUXTZR1K1NB5J-i2xQidc9DZ3hbkfk,21544
6
- github_backup-0.51.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- github_backup-0.51.2.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
8
- github_backup-0.51.2.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
9
- github_backup-0.51.2.dist-info/RECORD,,