2323# Internationalization
2424gettext .install ("submit50" , str (files ("submit50" ).joinpath ("locale" )))
2525
26+ LOGGER = logging .getLogger ("submit50" )
27+
2628SUBMIT_URL = "https://submit.cs50.io"
2729
2830class LogLevel (enum .IntEnum ):
@@ -193,7 +195,7 @@ def check_slug_year(slug):
193195 # Ask if they want to continue
194196 if not re .match (f"^\s*(?:{ _ ('y|yes' )} )\s*$" , input (_ ("Do you want to continue with this submission (yes/no)? " )), re .I ):
195197 raise Error (_ ("User aborted submission." ))
196-
198+
197199 except ValueError :
198200 pass
199201
@@ -243,6 +245,12 @@ def main():
243245 '\n info: adds all commands run.'
244246 '\n debug: adds the output of all commands run.' )
245247 )
248+ parser .add_argument ("--https" ,
249+ action = "store_true" ,
250+ help = _ ("force authentication via HTTPS" ))
251+ parser .add_argument ("--ssh" ,
252+ action = "store_true" ,
253+ help = _ ("force authentication via SSH" ))
246254 parser .add_argument (
247255 "-V" , "--version" ,
248256 action = "version" ,
@@ -260,8 +268,26 @@ def main():
260268 check_announcements ()
261269 check_version ()
262270 check_slug_year (args .slug )
263-
264- user_name , commit_hash , message = lib50 .push ("submit50" , args .slug , CONFIG_LOADER , prompt = prompt )
271+
272+ # Decide whether to force HTTPS or SSH authentication
273+ if args .https and args .ssh :
274+ LOGGER .warning (_ ("--https and --ssh have no effect when used together" ))
275+ auth_method = None
276+ elif args .https :
277+ auth_method = "https"
278+ elif args .ssh :
279+ auth_method = "ssh"
280+ else :
281+ auth_method = None
282+
283+ try :
284+ user_name , commit_hash , message = lib50 .push ("submit50" , args .slug , CONFIG_LOADER , prompt = prompt , auth_method = auth_method )
285+ except lib50 .ConnectionError :
286+ LOGGER .debug (traceback .format_exc ()) # log the traceback
287+ raise Error (_ (
288+ "check50 failed to authenticate your Github account. Try running check50 again with --https or --ssh, "
289+ "or try restarting your codespace. If the problem persists, please email us at sysadmins@cs50.harvard.edu."
290+ ))
265291 print (message )
266292
267293if __name__ == "__main__" :
0 commit comments