Compare commits

...

4 Commits

2 changed files with 40 additions and 5 deletions

View File

@ -4,7 +4,7 @@ import re
from datetime import datetime
from pathlib import Path
from time import sleep
from typing import TYPE_CHECKING, List
from typing import TYPE_CHECKING, List, Optional
# from filelock import FileLock
from git import Repo
@ -450,6 +450,8 @@ def joj3_check_env(
"Example: --group-config joj=10:24,run=20:48"
),
),
valid_after: Optional[datetime] = Option(None),
valid_before: Optional[datetime] = Option(None),
) -> None:
app.pretty_exceptions_enable = False
set_settings(Settings(_env_file=env_path))
@ -462,10 +464,21 @@ def joj3_check_env(
):
logger.error("missing required env var")
raise Exit(code=1)
msg, failed = tea.pot.joj3_check_submission_count(
time_msg, time_failed = tea.pot.joj3_check_submission_time(
valid_after,
valid_before,
)
count_msg, count_failed = tea.pot.joj3_check_submission_count(
env, grading_repo_name, group_config, scoreboard_filename
)
echo(json.dumps({"msg": msg, "failed": failed})) # print result to stdout for joj3
echo(
json.dumps(
{
"msg": time_msg + count_msg,
"failed": time_failed or count_failed,
}
)
) # print result to stdout for joj3
logger.info("joj3-check-env done")

View File

@ -282,6 +282,26 @@ class Teapot:
)
return joj3_issue.number
def joj3_check_submission_time(
self,
valid_after: Optional[datetime] = None,
valid_before: Optional[datetime] = None,
) -> Tuple[str, bool]:
now = datetime.now()
if (valid_after and now < valid_after) or (valid_before and now > valid_before):
return (
"### Submission Time Check Failed:\n"
f"Current time {now} is not in the valid range "
f"[{valid_after}, {valid_before}].\n",
True,
)
return (
"### Submission Time Check Passed:\n"
f"Current time {now} is in the valid range "
f"[{valid_after}, {valid_before}].\n",
False,
)
def joj3_check_submission_count(
self,
env: joj3.Env,
@ -364,13 +384,15 @@ class Teapot:
comment += f"keyword `{name}` "
use_group = name.lower() in env.joj3_groups.lower()
comment += (
f"in last {time_period} hour(s): "
f"In last {time_period} hour(s): "
f"submit count {submit_count}, "
f"max count {max_count}"
)
if use_group and submit_count + 1 > max_count:
failed = True
comment += ", exceeded"
comment += ", exceeded."
else:
comment += "."
comment += "\n"
if failed:
title = "### Submission Count Check Failed:"