Coverage for tools/sel_tools/gitlab_api/create_issue.py: 100%
23 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-02 05:55 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-02 05:55 +0000
1"""Create gitlab issues from tasks."""
3import json
4from copy import deepcopy
5from pathlib import Path
7import gitlab
8from gitlab.v4.objects import Project
9from tqdm import tqdm
11from sel_tools.config import GITLAB_SERVER_URL
12from sel_tools.gitlab_api.attachments import (
13 replace_file_paths_with_urls,
14 upload_attachments,
15)
16from sel_tools.utils.task import Task
18EVALUATION_DASHBOARD_TASK = Task(
19 title="Homework Evaluation Dashboard",
20 description="""
21This issue will be used during the semester to share the evaluation scores of your homework assignments.
23Please note that the evaluation scores are not final.
24They should only be a first indicator for you and are generated by our automated evaluation pipeline.
26At the end of the semester, we will still review your code manually and adjust the scores if needed.
28If you have any questions regarding the evaluation scores, please contact us by commenting to this issue.
29Make sure you tag us via `@username`.""",
30 documentation="",
31)
34def create_issues(tasks: list[Task], student_repos_file: Path, gitlab_token: str) -> None:
35 """Create gitlab issues from tasks for all student repos."""
36 gitlab_instance = gitlab.Gitlab(GITLAB_SERVER_URL, private_token=gitlab_token)
37 student_repos = json.loads(student_repos_file.read_text())
38 for student_repo in tqdm(student_repos, desc="Creating issues in student repos"):
39 student_homework_project = gitlab_instance.projects.get(student_repo["id"])
40 for task in tasks:
41 create_issue(deepcopy(task), student_homework_project)
44def create_issue(task: Task, gitlab_project: Project) -> None:
45 """Create issue for gitlab project from task."""
46 uploaded_files = upload_attachments(task.attachments, gitlab_project)
47 task.description = replace_file_paths_with_urls(task.description, uploaded_files, task.attachments)
49 gitlab_project.issues.create(get_issue_dict(task))
52def get_issue_dict(task: Task) -> dict:
53 """Get a dict that contains the fields to create an issue from a task."""
54 return {
55 "title": task.title,
56 "description": task.description + "\n## Documentation\n" + task.documentation,
57 "due_date": str(task.due_date) if task.due_date else "",
58 "labels": [task.label] if task.label else [],
59 }