Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions submit50/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",
Expand All @@ -260,8 +268,30 @@ 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())
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__":
Expand Down
Loading