Skip to content
Merged
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
1 change: 1 addition & 0 deletions container-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ services:
- orbit_source=./orbit
environment:
TZ: ${SINGULARITY_TIMEZONE}
SINGULARITY_HOSTNAME: ${SINGULARITY_HOSTNAME}
volumes:
- type: volume
source: denis-db
Expand Down
8 changes: 4 additions & 4 deletions denis/final.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

assignment = sys.argv[1]

utilities.release_subs([sub for sub in
utilities.user_to_sub(assignment, 'final').values()
if sub])
usernames_to_subs = utilities.user_to_sub(assignment, 'final')

utilities.release_subs([sub.submission_id for sub in usernames_to_subs.values() if sub])

print(f'final subs for {assignment} released')

tags = utilities.update_tags(assignment, 'final')

utilities.run_automated_checks(tags)
utilities.run_automated_checks(tags, usernames_to_subs)
8 changes: 4 additions & 4 deletions denis/initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

usernames_to_subs = utilities.user_to_sub(assignment, 'initial')

students_who_submitted = [username for username, sub_id in
usernames_to_subs.items() if sub_id is not None]
students_who_submitted = [username for username, sub in
usernames_to_subs.items() if sub is not None]

# restrict future email access for students who didnt make an initial sub
for student, sub_id in usernames_to_subs.items():
Expand Down Expand Up @@ -54,10 +54,10 @@
print(e)


utilities.release_subs([sub for sub in usernames_to_subs.values() if sub])
utilities.release_subs([sub.submission_id for sub in usernames_to_subs.values() if sub])

print(f'initial subs for {assignment} released')

tags = utilities.update_tags(assignment, 'initial')

utilities.run_automated_checks(tags)
utilities.run_automated_checks(tags, usernames_to_subs)
4 changes: 2 additions & 2 deletions denis/peer_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

ids = []

ids += [sub for sub in utilities.user_to_sub(assignment, 'review1').values() if sub]
ids += [sub for sub in utilities.user_to_sub(assignment, 'review2').values() if sub]
ids += [sub.submission_id for sub in utilities.user_to_sub(assignment, 'review1').values() if sub]
ids += [sub.submission_id for sub in utilities.user_to_sub(assignment, 'review2').values() if sub]

utilities.release_subs(ids)

Expand Down
97 changes: 95 additions & 2 deletions denis/utilities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import git
import subprocess
import tempfile
Expand All @@ -23,7 +24,7 @@ def user_to_sub(assignment, component):
sub = (relevant_gradeables
.where(grd_tbl.user == username)
.first())
submission_ids[user.username] = sub.submission_id if sub else None
submission_ids[user.username] = sub if sub else None

return submission_ids

Expand Down Expand Up @@ -80,7 +81,92 @@ def update_tags(assignment, component):
return updated_tags


def run_automated_checks(tags):
def check_corrupt_or_missing(repo, tag, username_to_subs):
[assignment, component, user] = tag.split('_')

gradable = username_to_subs[user]

msg = 'corruption and existence check'
msg += '\n'
msg += '------------------------------'
msg += '\n\n'
if not gradable or gradable.status[-1] == '!':
repo.git.execute(['git', 'notes', '--ref=grade', 'add', tag, '-m', '0'])
if not gradable:
msg += 'automatic 0 due to missing submission!'
else:
msg += 'automatic 0 due to corrupt submission!'
else:
msg += 'Patchset applies.'

msg += '\n\n'
return msg


def check_signed_off_by(repo, tag):
[_, _, user] = tag.split('_')
hostname = os.getenv("SINGULARITY_HOSTNAME")

msg = 'signed off by check'
msg += '\n'
msg += '-------------------'
msg += '\n\n'

commits = repo.git.execute(['git', 'rev-list', '--reverse', tag]).split('\n')
expected_dco = f'Signed-off-by: {user} <{user}@{hostname}>'
nr_flawless = 0
for i, commit in enumerate(commits):
patch = repo.git.execute(['git', 'show', commit])
if expected_dco in patch:
nr_flawless += 1
elif ('Signed-off-by:' in patch) or ('signed-off-by:' in patch):
msg += f'patch {i}: double check Signed-off-by\n'
else:
msg += f'patch {i}: no Signed-off-by line found\n'

if len(commits) == nr_flawless:
msg += 'All signed off by lines present as expected.\n'
Comment thread
theyoyojo marked this conversation as resolved.

msg += '\n'
return msg


def check_subject_tag(repo, tag):
[assignment, component, user] = tag.split('_')

msg = 'subject tag check'
msg += '\n'
msg += '-----------------'
msg += '\n\n'

commits = repo.git.execute(['git', 'rev-list', '--reverse', tag]).split('\n')

sub_tbl = mailman.db.Submission
relevant_submissions = (sub_tbl.select()
.where(sub_tbl.recipient == assignment)
.where(sub_tbl.user == user)
.order_by(sub_tbl.timestamp.desc()))
expected_revision_number = relevant_submissions.count()

nr_commits = len(commits)

nr_flawless = 0
for i, commit in enumerate(commits):
# from 0/n .. n/n
expected_tag = f'[{"RFC " if component == "initial" else ""}PATCH v{expected_revision_number} {i}/{nr_commits - 1}]'
patch = repo.git.execute(['git', 'show', commit])
if expected_tag in patch:
nr_flawless += 1
else:
msg += f'patch {i}: subject tag not detected (expected "{expected_tag}")\n'

if nr_commits == nr_flawless:
msg += 'Found all expected correct subject tags\n'
Comment thread
theyoyojo marked this conversation as resolved.

return msg


def run_automated_checks(tags, username_to_subs):
with tempfile.TemporaryDirectory() as repo_path:
repo = git.Repo.clone_from(PULL_URL, repo_path)

Expand All @@ -90,6 +176,13 @@ def run_automated_checks(tags):

for tag in tags:
msg = 'Automated tests by denis'
msg += '\n\n'
msg += check_corrupt_or_missing(repo, tag, username_to_subs)
if msg[-3] != '!':
msg += '\n\n'
msg += check_signed_off_by(repo, tag)
msg += check_subject_tag(repo, tag)

repo.git.execute(['git', 'notes', '--ref=denis', 'add', tag, '-m', msg])

remote.push('refs/notes/*:refs/notes/*')