Skip to content

Instantly share code, notes, and snippets.

@colematt
Created February 25, 2020 17:06
Show Gist options
  • Select an option

  • Save colematt/89d0e446ce3c360f14a236cfe40d484a to your computer and use it in GitHub Desktop.

Select an option

Save colematt/89d0e446ce3c360f14a236cfe40d484a to your computer and use it in GitHub Desktop.
GitHub Classroom Scripts
#!/bin/bash
# This file is for cloning assignments made in GitHub Classroom into the
# present working directory.
# USAGE
# This script accepts the following command line arguments:
# $1 - the name of the github classroom (e.g. "bucs220")
# $2 - the assignment's prefix before the username MINUS a trailing hyphen (e.g. "F17-A1")
# $3 - the name of the file with a list of repository owners (either individual users or groups).
# $4 - (optional) time in seconds to sleep between requests
# PREREQUISITES
# You must set up your shell to use SSH keys and enable credential caching. See https://help.github.com/articles/caching-your-github-password-in-git/
# The names in the file MUST be one username per line, with a carriage return at end of file
# CREDITS
# Inspired by https://github.com/umasshokie/classroom_scripts
#Check that 3 or 4 parameters are given
if [[ $# -lt 3 || $# -gt 4 ]];
then
echo "Usage: source classroom-clone.sh CLASSROOM ASSIGNMENT NAMES [SLEEP]"
else
if [[ $# -ge 4 ]]; then
t=$4
else
t=0
fi
#set parameters to more obvious variable names
classroom="git@github.com:"$1"/"
assignment=$2
file=$3
# read line by line and clone the assignment
while read line
do
name=${assignment}-${line}
git clone ${classroom}${name}
sleep ${t}
done < $file
fi
#!/bin/bash
# This script visits a directory of Github cloned directories and grades them.
# If you want to use it with group assignments, you will need a list of each group name instead of student usernames.
# It requires three command line arguments:
# 1. CLONEDIR - Path to the directory containing the cloned directories.
# 2. GRADEDIR - Path to the directory containing the grading files test.c and test.py
# 3. GRADER - Name of the grader. Will appear in the commit message.
# Author: @colematt, Matthew Cole
#Check that 3 parameters are given:
if [[ $# -ne 3 ]];
then
echo "Usage: source dir-grade.sh <CLONEDIR> <GRADEDIR> <GRADER>"
exit 1
else
REPOS="$1"
GRADEFILES="$2"
GRADER="$3"
let DIRCOUNT=`ls -l ${REPOS} | grep -c ^d`
let DNUM=0
for dir in REPOS/*
do
if [ -d "${dir}" ] ; then
let DNUM++
echo "Processing ${dir} (${DNUM}/${DIRCOUNT}) ..."
# Copy grading source files
cp $GRADEFILES/test.c $GRADEFILES/test.py ${dir}
# Build process
make -C ${dir} test
make -C ${dir} test-run
rm -fv ${dir}/test.c ${dir}/test.py
make really-clean
# Verify test results were published by make test-run
if [ -e ${dir}/test_results.log ]
then
cat ${dir}/test_results.log
else
echo "Failed to complete test-run! See ${GRADER}" > test_results.log
cat ${dir}/test_results.log
fi
# Commit the grading to the repository
git -C ${dir} add ${dir}/test_results.log
git -C ${dir} commit -a -m "Graded by ${GRADER}"
git -C ${dir} push
fi
done
fi
#! /bin/bash
# This file is for pushing graded assignments to GitHub Classroom repositories
# It requires at least 2 command line arguments
# 1 - name of the assignment, for cycling through folders
# 2 - an option argument: 1 or 2
# 3 - if option 1 is chosen, the name of the file to push
# Author: @umasshokie, Megan Olsen
#Check that at least 2 parameter is given
if [[ $# -ne 2 ]];
then
echo "This script requires exactly 2 parameters."
echo "First is an assignment name, i.e. common start to all directory names"
echo "Second is a numerical option:"
echo " 1 - add a single file and commit/push. Filename is third parameter."
echo " 2 - no new files, commit and push all changes to the repository."
# If the option choice is 1, add given file and commit/push
elif [[ $2 -eq 1 ]];
then
if [[ $# -eq 3 ]];
then
assignment=$1
file=$3
for f in ${assignment}*
do
cd $f
git add $file
git commit $file -m "Graded"
git push origin master
cd ..
done
else
echo "For option 1, you must list a filename as a third parameter"
fi
# If the option choice is 2, commit and push all files in directory
elif [[ $2 -eq 2 ]];
then
assignment=$1
for f in ${assignment}*
do
cd $f
git commit * -m "Graded"
git push origin master
echo $f
cd ..
done
else
echo "Option must be 1 or 2"
fi
@colematt

Copy link
Copy Markdown
Author

Scripts useful for managing a Github Classroom within your local working directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment