create-classroom-assignment.sh(file created)
| @@ -0,0 +1,222 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | ||
| 3 | + | # GitHub Classroom Assignment Creator | |
| 4 | + | # This script creates a new assignment in a GitHub Classroom using the GitHub CLI | |
| 5 | + | ||
| 6 | + | set -e # Exit on any error | |
| 7 | + | ||
| 8 | + | # Color codes for output | |
| 9 | + | RED='\033[0;31m' | |
| 10 | + | GREEN='\033[0;32m' | |
| 11 | + | YELLOW='\033[1;33m' | |
| 12 | + | BLUE='\033[0;34m' | |
| 13 | + | NC='\033[0m' # No Color | |
| 14 | + | ||
| 15 | + | # Function to print colored output | |
| 16 | + | print_info() { | |
| 17 | + | echo -e "${BLUE}[INFO]${NC} $1" | |
| 18 | + | } | |
| 19 | + | ||
| 20 | + | print_success() { | |
| 21 | + | echo -e "${GREEN}[SUCCESS]${NC} $1" | |
| 22 | + | } | |
| 23 | + | ||
| 24 | + | print_warning() { | |
| 25 | + | echo -e "${YELLOW}[WARNING]${NC} $1" | |
| 26 | + | } | |
| 27 | + | ||
| 28 | + | print_error() { | |
| 29 | + | echo -e "${RED}[ERROR]${NC} $1" | |
| 30 | + | } | |
| 31 | + | ||
| 32 | + | # Function to show usage | |
| 33 | + | show_usage() { | |
| 34 | + | echo "Usage: $0 [OPTIONS]" | |
| 35 | + | echo "" | |
| 36 | + | echo "Creates a GitHub Classroom assignment with specified parameters." | |
| 37 | + | echo "" | |
| 38 | + | echo "Options:" | |
| 39 | + | echo " -c, --classroom CLASSROOM_ID GitHub Classroom ID (required)" | |
| 40 | + | echo " -t, --title TITLE Assignment title (required)" | |
| 41 | + | echo " -s, --starter-repo REPO Starter code repository (org/repo format)" | |
| 42 | + | echo " -d, --deadline DEADLINE Assignment deadline (YYYY-MM-DD format)" | |
| 43 | + | echo " -p, --prefix PREFIX Repository name prefix (default: assignment)" | |
| 44 | + | echo " --public Make student repositories public (default: private)" | |
| 45 | + | echo " --individual Individual assignment (default: group)" | |
| 46 | + | echo " --max-teams MAX Maximum number of teams (for group assignments)" | |
| 47 | + | echo " --max-members MAX Maximum members per team (for group assignments)" | |
| 48 | + | echo " -h, --help Show this help message" | |
| 49 | + | echo "" | |
| 50 | + | echo "Examples:" | |
| 51 | + | echo " $0 -c 12345 -t \"Data Pipeline Project\" -s ZipCodeCore/CentralLibraryData" | |
| 52 | + | echo " $0 -c 12345 -t \"Individual Exercise\" -s myorg/starter-repo --individual" | |
| 53 | + | echo "" | |
| 54 | + | echo "Note: This script requires the GitHub CLI (gh) to be installed and authenticated." | |
| 55 | + | } | |
| 56 | + | ||
| 57 | + | # Default values | |
| 58 | + | CLASSROOM_ID="" | |
| 59 | + | ASSIGNMENT_TITLE="" | |
| 60 | + | STARTER_REPO="" | |
| 61 | + | DEADLINE="" | |
| 62 | + | REPO_PREFIX="assignment" | |
| 63 | + | IS_PUBLIC="false" | |
| 64 | + | IS_INDIVIDUAL="false" | |
| 65 | + | MAX_TEAMS="" | |
| 66 | + | MAX_MEMBERS="" | |
| 67 | + | ||
| 68 | + | # Parse command line arguments | |
| 69 | + | while [[ $# -gt 0 ]]; do | |
| 70 | + | case $1 in | |
| 71 | + | -c|--classroom) | |
| 72 | + | CLASSROOM_ID="$2" | |
| 73 | + | shift 2 | |
| 74 | + | ;; | |
| 75 | + | -t|--title) | |
| 76 | + | ASSIGNMENT_TITLE="$2" | |
| 77 | + | shift 2 | |
| 78 | + | ;; | |
| 79 | + | -s|--starter-repo) | |
| 80 | + | STARTER_REPO="$2" | |
| 81 | + | shift 2 | |
| 82 | + | ;; | |
| 83 | + | -d|--deadline) | |
| 84 | + | DEADLINE="$2" | |
| 85 | + | shift 2 | |
| 86 | + | ;; | |
| 87 | + | -p|--prefix) | |
| 88 | + | REPO_PREFIX="$2" | |
| 89 | + | shift 2 | |
| 90 | + | ;; | |
| 91 | + | --public) | |
| 92 | + | IS_PUBLIC="true" | |
| 93 | + | shift | |
| 94 | + | ;; | |
| 95 | + | --individual) | |
| 96 | + | IS_INDIVIDUAL="true" | |
| 97 | + | shift | |
| 98 | + | ;; | |
| 99 | + | --max-teams) | |
| 100 | + | MAX_TEAMS="$2" | |
| 101 | + | shift 2 | |
| 102 | + | ;; | |
| 103 | + | --max-members) | |
| 104 | + | MAX_MEMBERS="$2" | |
| 105 | + | shift 2 | |
| 106 | + | ;; | |
| 107 | + | -h|--help) | |
| 108 | + | show_usage | |
| 109 | + | exit 0 | |
| 110 | + | ;; | |
| 111 | + | *) | |
| 112 | + | print_error "Unknown option: $1" | |
| 113 | + | show_usage | |
| 114 | + | exit 1 | |
| 115 | + | ;; | |
| 116 | + | esac | |
| 117 | + | done | |
| 118 | + | ||
| 119 | + | # Validate required parameters | |
| 120 | + | if [[ -z "$CLASSROOM_ID" ]]; then | |
| 121 | + | print_error "Classroom ID is required. Use -c or --classroom option." | |
| 122 | + | show_usage | |
| 123 | + | exit 1 | |
| 124 | + | fi | |
| 125 | + | ||
| 126 | + | if [[ -z "$ASSIGNMENT_TITLE" ]]; then | |
| 127 | + | print_error "Assignment title is required. Use -t or --title option." | |
| 128 | + | show_usage | |
| 129 | + | exit 1 | |
| 130 | + | fi | |
| 131 | + | ||
| 132 | + | # Check if GitHub CLI is installed | |
| 133 | + | if ! command -v gh &> /dev/null; then | |
| 134 | + | print_error "GitHub CLI (gh) is not installed. Please install it first:" | |
| 135 | + | echo " brew install gh" | |
| 136 | + | echo " or visit: https://cli.github.com/" | |
| 137 | + | exit 1 | |
| 138 | + | fi | |
| 139 | + | ||
| 140 | + | # Check if user is authenticated with GitHub CLI | |
| 141 | + | if ! gh auth status &> /dev/null; then | |
| 142 | + | print_error "Not authenticated with GitHub CLI. Please run:" | |
| 143 | + | echo " gh auth login" | |
| 144 | + | exit 1 | |
| 145 | + | fi | |
| 146 | + | ||
| 147 | + | # Validate starter repo format if provided | |
| 148 | + | if [[ -n "$STARTER_REPO" ]]; then | |
| 149 | + | if [[ ! "$STARTER_REPO" =~ ^[^/]+/[^/]+$ ]]; then | |
| 150 | + | print_error "Starter repository must be in format 'org/repo'" | |
| 151 | + | exit 1 | |
| 152 | + | fi | |
| 153 | + | fi | |
| 154 | + | ||
| 155 | + | # Validate deadline format if provided | |
| 156 | + | if [[ -n "$DEADLINE" ]]; then | |
| 157 | + | if [[ ! "$DEADLINE" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then | |
| 158 | + | print_error "Deadline must be in YYYY-MM-DD format" | |
| 159 | + | exit 1 | |
| 160 | + | fi | |
| 161 | + | fi | |
| 162 | + | ||
| 163 | + | print_info "Creating GitHub Classroom assignment..." | |
| 164 | + | print_info "Classroom ID: $CLASSROOM_ID" | |
| 165 | + | print_info "Title: $ASSIGNMENT_TITLE" | |
| 166 | + | print_info "Starter repo: ${STARTER_REPO:-"None"}" | |
| 167 | + | print_info "Assignment type: $([ "$IS_INDIVIDUAL" = "true" ] && echo "Individual" || echo "Group")" | |
| 168 | + | ||
| 169 | + | # Build the GitHub CLI command | |
| 170 | + | GH_CMD="gh classroom assignment create" | |
| 171 | + | GH_CMD="$GH_CMD --classroom $CLASSROOM_ID" | |
| 172 | + | GH_CMD="$GH_CMD --title \"$ASSIGNMENT_TITLE\"" | |
| 173 | + | GH_CMD="$GH_CMD --prefix \"$REPO_PREFIX\"" | |
| 174 | + | ||
| 175 | + | if [[ -n "$STARTER_REPO" ]]; then | |
| 176 | + | GH_CMD="$GH_CMD --starter-code-repository $STARTER_REPO" | |
| 177 | + | fi | |
| 178 | + | ||
| 179 | + | if [[ -n "$DEADLINE" ]]; then | |
| 180 | + | GH_CMD="$GH_CMD --deadline $DEADLINE" | |
| 181 | + | fi | |
| 182 | + | ||
| 183 | + | if [[ "$IS_PUBLIC" = "true" ]]; then | |
| 184 | + | GH_CMD="$GH_CMD --public" | |
| 185 | + | fi | |
| 186 | + | ||
| 187 | + | if [[ "$IS_INDIVIDUAL" = "true" ]]; then | |
| 188 | + | GH_CMD="$GH_CMD --individual" | |
| 189 | + | else | |
| 190 | + | # Group assignment options | |
| 191 | + | if [[ -n "$MAX_TEAMS" ]]; then | |
| 192 | + | GH_CMD="$GH_CMD --max-teams $MAX_TEAMS" | |
| 193 | + | fi | |
| 194 | + | if [[ -n "$MAX_MEMBERS" ]]; then | |
| 195 | + | GH_CMD="$GH_CMD --max-members $MAX_MEMBERS" | |
| 196 | + | fi | |
| 197 | + | fi | |
| 198 | + | ||
| 199 | + | # Execute the command | |
| 200 | + | print_info "Executing: $GH_CMD" | |
| 201 | + | echo "" | |
| 202 | + | ||
| 203 | + | if eval "$GH_CMD"; then | |
| 204 | + | print_success "Assignment created successfully!" | |
| 205 | + | echo "" | |
| 206 | + | print_info "Students can access the assignment through your GitHub Classroom." | |
| 207 | + | print_info "Assignment repositories will be created with prefix: $REPO_PREFIX" | |
| 208 | + | else | |
| 209 | + | print_error "Failed to create assignment. Please check the error messages above." | |
| 210 | + | exit 1 | |
| 211 | + | fi | |
| 212 | + | ||
| 213 | + | # Additional helpful information | |
| 214 | + | echo "" | |
| 215 | + | print_info "Next steps:" | |
| 216 | + | echo "1. Share the assignment link with your students" | |
| 217 | + | echo "2. Monitor student progress in your GitHub Classroom dashboard" | |
| 218 | + | echo "3. Students will get repositories named: $REPO_PREFIX-{student-name}" | |
| 219 | + | ||
| 220 | + | if [[ -n "$STARTER_REPO" ]]; then | |
| 221 | + | echo "4. Student repositories will be initialized with code from: $STARTER_REPO" | |
| 222 | + | fi | |
更新
更早