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