From b2ebb8c77e4af730917aad80e8768f9e4b20a019 Mon Sep 17 00:00:00 2001 From: ivanharvard <144486839+ivanharvard@users.noreply.github.com> Date: Wed, 6 Aug 2025 17:08:33 -0400 Subject: [PATCH 1/2] add authentication flag and debug support --- submit50/__main__.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/submit50/__main__.py b/submit50/__main__.py index 0a3a72e..63eb148 100755 --- a/submit50/__main__.py +++ b/submit50/__main__.py @@ -23,6 +23,8 @@ # Internationalization gettext.install("submit50", str(files("submit50").joinpath("locale"))) +LOGGER = logging.getLogger("submit50") + SUBMIT_URL = "https://submit.cs50.io" class LogLevel(enum.IntEnum): @@ -193,7 +195,7 @@ def check_slug_year(slug): # Ask if they want to continue if not re.match(f"^\s*(?:{_('y|yes')})\s*$", input(_("Do you want to continue with this submission (yes/no)? ")), re.I): raise Error(_("User aborted submission.")) - + except ValueError: pass @@ -243,6 +245,12 @@ def main(): '\ninfo: adds all commands run.' '\ndebug: adds the output of all commands run.') ) + parser.add_argument("--https", + action="store_true", + help=_("force authentication via HTTPS")) + parser.add_argument("--ssh", + action="store_true", + help=_("force authentication via SSH")) parser.add_argument( "-V", "--version", action="version", @@ -260,8 +268,26 @@ def main(): check_announcements() check_version() check_slug_year(args.slug) - - user_name, commit_hash, message = lib50.push("submit50", args.slug, CONFIG_LOADER, prompt=prompt) + + # Decide whether to force HTTPS or SSH authentication + if args.https and args.ssh: + LOGGER.warning(_("--https and --ssh have no effect when used together")) + auth_method = None + elif args.https: + auth_method = "https" + elif args.ssh: + auth_method = "ssh" + else: + auth_method = None + + try: + user_name, commit_hash, message = lib50.push("submit50", args.slug, CONFIG_LOADER, prompt=prompt, auth_method=auth_method) + except lib50.ConnectionError: + LOGGER.debug(traceback.format_exc()) # log the traceback + raise Error(_( + "check50 failed to authenticate your Github account. Try running check50 again with --https or --ssh, " + "or try restarting your codespace. If the problem persists, please email us at sysadmins@cs50.harvard.edu." + )) print(message) if __name__ == "__main__": From e836ff17044e0676062e5b6dfb97c6dff5c30ae7 Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Thu, 7 Aug 2025 00:02:48 -0400 Subject: [PATCH 2/2] improve error handling for GitHub authentication failures in codespaces --- submit50/__main__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/submit50/__main__.py b/submit50/__main__.py index 63eb148..b000684 100755 --- a/submit50/__main__.py +++ b/submit50/__main__.py @@ -195,7 +195,7 @@ def check_slug_year(slug): # Ask if they want to continue if not re.match(f"^\s*(?:{_('y|yes')})\s*$", input(_("Do you want to continue with this submission (yes/no)? ")), re.I): raise Error(_("User aborted submission.")) - + except ValueError: pass @@ -283,11 +283,15 @@ def main(): try: user_name, commit_hash, message = lib50.push("submit50", args.slug, CONFIG_LOADER, prompt=prompt, auth_method=auth_method) except lib50.ConnectionError: - LOGGER.debug(traceback.format_exc()) # log the traceback - raise Error(_( - "check50 failed to authenticate your Github account. Try running check50 again with --https or --ssh, " - "or try restarting your codespace. If the problem persists, please email us at sysadmins@cs50.harvard.edu." - )) + LOGGER.debug(traceback.format_exc()) + if not os.environ.get("CODESPACES"): + raise Error(_( + "submit50 failed to authenticate your Github account. Please make sure you are connected to the internet and try again." + )) + except Exception as e: + LOGGER.debug(traceback.format_exc()) + raise Error(_("Sorry, something's wrong, please try again.\n" + "If the problem persists, please visit our status page https://cs50.statuspage.io for more information.")) from e print(message) if __name__ == "__main__":