Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag helper #193

Merged
merged 4 commits into from
Nov 1, 2024
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 @@ -211,6 +211,7 @@ services:
read_only: true
networks:
- denis
- git
git:
build:
context: git
Expand Down
1 change: 1 addition & 0 deletions denis/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ FROM alpine:3.20 AS denis

RUN apk add \
py3-peewee \
py3-gitpython \
;

WORKDIR /usr/local/share/denis
Expand Down
2 changes: 2 additions & 0 deletions denis/final.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
if sub])

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

utilities.update_tags(assignment, 'final')
2 changes: 2 additions & 0 deletions denis/initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@
utilities.release_subs([sub for sub in usernames_to_subs.values() if sub])

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

utilities.update_tags(assignment, 'initial')
3 changes: 3 additions & 0 deletions denis/peer_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
utilities.release_subs(ids)

print(f'peer review subs for {assignment} released')

utilities.update_tags(assignment, 'review1')
utilities.update_tags(assignment, 'review2')
41 changes: 41 additions & 0 deletions denis/utilities.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import git
import subprocess
import tempfile

import orbit.db
import mailman.db


PUSH_URL = 'http://git:8000/cgi-bin/git-receive-pack/grading.git'
PULL_URL = 'http://git:8000/grading.git'
REMOTE_NAME = 'grading'


def user_to_sub(assignment, component):
submission_ids = {}
grd_tbl = mailman.db.Gradeable
Expand All @@ -29,3 +36,37 @@ def release_subs(sub_ids):
subprocess.run(['/usr/local/bin/append_journal',
'/var/lib/email/journal/journal'],
input=journal_data, check=True)


def update_tags(assignment, component):
grd_tbl = mailman.db.Gradeable
subs = (grd_tbl.select()
.order_by(-grd_tbl.timestamp)
.where(grd_tbl.assignment == assignment)
.where(grd_tbl.component == component))
with tempfile.TemporaryDirectory() as repo_path:
repo = git.Repo.clone_from(PULL_URL, repo_path)
repo.create_remote(REMOTE_NAME, PUSH_URL)
repo.config_writer().set_value('user', 'name', 'denis').release()
(repo.config_writer().set_value('user', 'email', 'denis@denis')
.release())
if 'EMPTY' not in repo.tags:
repo.git.commit('--allow-empty', '-m', 'No gradeable submission.')
repo.create_tag('EMPTY')

for user in orbit.db.User.select():
new_tag_name = f'{assignment}_{component}_{user.username}'
if new_tag_name in repo.tags:
print('Potential issue? Attempted to create duplicate tag '
f'{new_tag_name}')
continue
user_sub = subs.where(grd_tbl.user == user.username).first()
if not user_sub:
msg = 'No gradeable submission'
to_promote = repo.tags['EMPTY']
else:
msg = user_sub.status
to_promote = repo.tags[user_sub.submission_id]
repo.create_tag(new_tag_name, ref=to_promote.commit, message=msg)

repo.git.push(REMOTE_NAME, tags=True)