39
39
DEFAULT_FILE_LIMIT = 10000
40
40
41
41
42
- def push (tool , slug , config_loader , repo = None , data = None , prompt = lambda question , included , excluded : True , file_limit = DEFAULT_FILE_LIMIT ):
42
+ def push (tool , slug , config_loader , repo = None , data = None , prompt = lambda question , included , excluded : True , file_limit = DEFAULT_FILE_LIMIT , auth_method = None ):
43
43
"""
44
44
Pushes to Github in name of a tool.
45
45
What should be pushed is configured by the tool and its configuration in the .cs50.yml file identified by the slug.
@@ -61,6 +61,10 @@ def push(tool, slug, config_loader, repo=None, data=None, prompt=lambda question
61
61
:type prompt: lambda str, list, list => bool, optional
62
62
:param file_limit: maximum number of files to be matched by any globbing pattern.
63
63
:type file_limit: int
64
+ :param auth_method: The authentication method to use. Accepts `"https"` or `"ssh"`. \
65
+ If any other value is provided, attempts SSH \
66
+ authentication first and fall back to HTTPS if SSH fails.
67
+ :type auth_method: str
64
68
:return: GitHub username and the commit hash
65
69
:type: tuple(str, str)
66
70
@@ -89,7 +93,7 @@ def push(tool, slug, config_loader, repo=None, data=None, prompt=lambda question
89
93
remote , (honesty , included , excluded ) = connect (slug , config_loader , file_limit = DEFAULT_FILE_LIMIT )
90
94
91
95
# Authenticate the user with GitHub, and prepare the submission
92
- with authenticate (remote ["org" ], repo = repo ) as user , prepare (tool , slug , user , included ):
96
+ with authenticate (remote ["org" ], repo = repo , auth_method = auth_method ) as user , prepare (tool , slug , user , included ):
93
97
94
98
# Show any prompt if specified
95
99
if prompt (honesty , included , excluded ):
@@ -465,7 +469,7 @@ def batch_files(files, size=100):
465
469
files_list = list (files )
466
470
for i in range (0 , len (files_list ), size ):
467
471
yield files_list [i :i + size ]
468
-
472
+
469
473
for batch in batch_files (included ):
470
474
quoted_files = ' ' .join (shlex .quote (f ) for f in batch )
471
475
run (git (f"add -f -- { quoted_files } " ))
@@ -962,7 +966,7 @@ def run(command, quiet=False, timeout=None):
962
966
ProgressBar .stop_all ()
963
967
passphrase = _prompt_password ("Enter passphrase for SSH key: " )
964
968
child .sendline (passphrase )
965
-
969
+
966
970
# Get the full output by reading until EOF
967
971
full_output = child .before + child .after + child .read ()
968
972
command_output = full_output .strip ().replace ("\r \n " , "\n " )
0 commit comments