forked from M-Labs/it-infra
nixbld: fix hooks page breaking github backups
https://github.com/josegonzalez/python-github-backup/issues/176
This commit is contained in:
parent
01212b4e51
commit
977cccc997
61
nixbld-etc-nixos/ghbackup-179.patch
Normal file
61
nixbld-etc-nixos/ghbackup-179.patch
Normal file
@ -0,0 +1,61 @@
|
||||
diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py
|
||||
index 4ef8b7e..82cbdca 100644
|
||||
--- a/github_backup/github_backup.py
|
||||
+++ b/github_backup/github_backup.py
|
||||
@@ -425,7 +425,7 @@ def get_github_repo_url(args, repository):
|
||||
return repo_url
|
||||
|
||||
|
||||
-def retrieve_data_gen(args, template, query_args=None, single_request=False):
|
||||
+def retrieve_data_gen(args, template, query_args=None, single_request=False, optional=False):
|
||||
auth = get_auth(args, encode=not args.as_app)
|
||||
query_args = get_query_args(query_args)
|
||||
per_page = 100
|
||||
@@ -452,6 +452,11 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
|
||||
else:
|
||||
read_error = False
|
||||
|
||||
+ # Requested data does not exist for this repository, but that was expected.
|
||||
+ # Generate an empty list.
|
||||
+ if status_code == 404 and optional:
|
||||
+ return
|
||||
+
|
||||
# be gentle with API request limit and throttle requests if remaining requests getting low
|
||||
limit_remaining = int(r.headers.get('x-ratelimit-remaining', 0))
|
||||
if args.throttle_limit and limit_remaining <= args.throttle_limit:
|
||||
@@ -509,8 +514,8 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
|
||||
break
|
||||
|
||||
|
||||
-def retrieve_data(args, template, query_args=None, single_request=False):
|
||||
- return list(retrieve_data_gen(args, template, query_args, single_request))
|
||||
+def retrieve_data(args, template, query_args=None, single_request=False, optional=False):
|
||||
+ return list(retrieve_data_gen(args, template, query_args, single_request, optional))
|
||||
|
||||
|
||||
def get_query_args(query_args=None):
|
||||
@@ -1011,7 +1016,8 @@ def backup_hooks(args, repo_cwd, repository, repos_template):
|
||||
'hooks',
|
||||
template,
|
||||
output_file,
|
||||
- hook_cwd)
|
||||
+ hook_cwd,
|
||||
+ optional=not args.include_hooks)
|
||||
except SystemExit:
|
||||
log_info("Unable to read hooks, skipping")
|
||||
|
||||
@@ -1158,12 +1164,12 @@ def backup_account(args, output_directory):
|
||||
account_cwd)
|
||||
|
||||
|
||||
-def _backup_data(args, name, template, output_file, output_directory):
|
||||
+def _backup_data(args, name, template, output_file, output_directory, optional=False):
|
||||
skip_existing = args.skip_existing
|
||||
if not skip_existing or not os.path.exists(output_file):
|
||||
log_info('Retrieving {0} {1}'.format(args.user, name))
|
||||
mkdir_p(output_directory)
|
||||
- data = retrieve_data(args, template)
|
||||
+ data = retrieve_data(args, template, optional=optional)
|
||||
|
||||
log_info('Writing {0} {1} to disk'.format(len(data), name))
|
||||
with codecs.open(output_file, 'w', encoding='utf-8') as f:
|
@ -9,6 +9,7 @@ let
|
||||
rev = "18e78a4d66120961590836e63d1fa939e4d036f3";
|
||||
sha256 = "1c5qxyv322z5zkx8mxdwdqrnjgqhk00aqcgwkn53b4xkfr2idkbn";
|
||||
};
|
||||
patches = [ ./ghbackup-179.patch ];
|
||||
propagatedBuildInputs = [ pkgs.git ];
|
||||
};
|
||||
token = (import /etc/nixos/secret/github_tokens.nix).backup;
|
||||
@ -31,7 +32,7 @@ in
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable GitHub backups";
|
||||
description = "Enable backups";
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user