Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions grading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def commits_substring_count(resp: list, needle: str):
"""Counts commits with substring in message. Accepts parsed JSON from response to github api"""
i=0
for commit in resp:
i += needle in commit['commit']['message']
return i

def issues_substring_count(resp: list, needle: str):
"""Counts issues with substring in title. Accepts parsed JSON from response to github api"""
i=0
for issue in resp:
i += needle in issue['title']
return i

def commits_local_count(resp: list):
"""Counts commits made w/o using github web. Accepts parsed JSON from response to github api"""
i=0
for commit in resp:
if not (commit['commit']['committer']['email'] == 'noreply@github.com' and commit['commit']['verification']['verified']):
i += 1
return i
25 changes: 24 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from dotenv import load_dotenv
from itsdangerous import TimestampSigner, BadSignature
import re
import grading

load_dotenv()
app = FastAPI()
Expand Down Expand Up @@ -430,8 +431,30 @@ def grade_lab(course_id: str, group_id: str, lab_id: str, request: GradeRequest)
summary.append(f"{emoji} {name} — {html_url}")

total_checks = len(check_runs)
result_string = f"{passed_count}/{total_checks} тестов пройдено"

if lab_config.get('validation'):
valComm=lab_config['validation'].get('commits') # geting validation rules for commits
if valComm is not None:
total_checks += len(valComm)
for chk in valComm: # checking every rule from the list
match chk.get('filter'):
case 'message': # substring check
if grading.commits_substring_count(commits_resp.json(), chk['contains']) >= chk['min-count']:
passed_count += 1
case 'console': # local commits check
if grading.commits_local_count(commits_resp.json()) >= chk['min-count']:
passed_count += 1

valIssu=lab_config['validation'].get('issues') # geting validation rules for issues
if valIssu is not None:
total_checks += len(valIssu)
issues_resp = requests.get(f"https://api.github.com/repos/{org}/{repo_name}/issues")
if issues_resp.json(): # issues are present
for chk in valIssu: # checking every rule from the list
if grading.issues_substring_count(issues_resp.json(), chk['contains']) >= chk['min-count']: # substring check
passed_count += 1

result_string = f"{passed_count}/{total_checks} тестов пройдено"
final_result = "✓" if passed_count == total_checks else "✗"

scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
Expand Down