1414import sys
1515import tempfile
1616import time
17+ import traceback
1718
1819import attr
1920import lib50
@@ -259,6 +260,20 @@ def process_args(args):
259260 if args .ansi_log and "ansi" not in seen_output :
260261 LOGGER .warning (_ ("--ansi-log has no effect when ansi is not among the output formats" ))
261262
263+ if args .https or args .ssh :
264+ if args .offline :
265+ LOGGER .warning (_ ("Using either --https and --ssh will have no effect when running offline" ))
266+ args .auth_method = None
267+ elif args .https and args .ssh :
268+ LOGGER .warning (_ ("--https and --ssh have no effect when used together" ))
269+ args .auth_method = None
270+ elif args .https :
271+ args .auth_method = "https"
272+ else :
273+ args .auth_method = "ssh"
274+ else :
275+ args .auth_method = None
276+
262277
263278class LoggerWriter :
264279 def __init__ (self , logger , level ):
@@ -340,6 +355,12 @@ def main():
340355 const = "enabled" ,
341356 choices = ["true" , "enabled" , "1" , "on" , "false" , "disabled" , "0" , "off" ],
342357 help = _ ("enable or disable assertion rewriting; overrides ENABLE_CHECK50_ASSERT flag in the checks file" ))
358+ parser .add_argument ("--https" ,
359+ action = "store_true" ,
360+ help = _ ("force authentication via HTTPS" ))
361+ parser .add_argument ("--ssh" ,
362+ action = "store_true" ,
363+ help = _ ("force authentication via SSH" ))
343364 parser .add_argument ("-V" , "--version" ,
344365 action = "version" ,
345366 version = f"%(prog)s { __version__ } " )
@@ -361,7 +382,19 @@ def main():
361382
362383 # If remote, push files to GitHub and await results
363384 if not args .local :
364- commit_hash = lib50 .push ("check50" , internal .slug , internal .CONFIG_LOADER , data = {"check50" : True })[1 ]
385+ try :
386+ commit_hash = lib50 .push ("check50" , internal .slug , internal .CONFIG_LOADER , data = {"check50" : True }, auth_method = args .auth_method )[1 ]
387+ except lib50 .ConnectionError :
388+ LOGGER .debug (traceback .format_exc ())
389+ if not os .environ .get ("CODESPACES" ):
390+ raise _exceptions .Error (_ (
391+ "check50 failed to authenticate your Github account. Please make sure you are connected to the internet and try again."
392+ ))
393+ except Exception as e :
394+ LOGGER .debug (traceback .format_exc ())
395+ raise _exceptions .Error (_ ("Sorry, something's wrong, please try again.\n "
396+ "If the problem persists, please visit our status page https://cs50.statuspage.io for more information." )) from e
397+
365398 with lib50 .ProgressBar ("Waiting for results" ) if "ansi" in args .output else nullcontext ():
366399 tag_hash , results = await_results (commit_hash , internal .slug )
367400
0 commit comments