FIX sanitize assignment name in github repos
+import string
import traceback
from parse import parse
@@ -82,9 +83,14 @@ def add_collaborator(github_org: str, new_repo_name: str, github_username: str):
)
+def get_github_safe_assignment_name(assignment: Assignment) -> str:
+ valid_charset = set(string.ascii_lowercase + string.digits + '_-')
+ return ''.join(c for c in assignment.name.lower().replace(" ", "-") if c in valid_charset)
+
+
def get_student_assignment_repo_name(user: User, assignment: Assignment) -> str:
# Get assignment name (lowercase and spaces removed)
- assignment_name = assignment.name.lower().replace(" ", "-")
+ assignment_name = get_github_safe_assignment_name(assignment)
# Create a repo name from assignment name, unique code and github username
new_repo_name = f"{assignment_name}-{assignment.unique_code}-{user.netid}"
@@ -94,7 +100,7 @@ def get_student_assignment_repo_name(user: User, assignment: Assignment) -> str:
def get_group_assignment_repo_name(users: list[User], assignment: Assignment) -> str:
# Get assignment name (lowercase and spaces removed)
- assignment_name = assignment.name.lower().replace(" ", "-")
+ assignment_name = get_github_safe_assignment_name(assignment)
netids = "-".join(user.netid for user in users)
