Coverage for tools / sel_tools / gitlab_api / comment_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"""Comment to gitlab issues."""
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.comment import Comment
16def comment_issues(comment: Comment, student_repos: list[dict], gitlab_instance: gitlab.Gitlab) -> None:
17 """Comment to all issues from comment to student repos."""
18 for student_repo in tqdm(student_repos, desc="Commenting to issues"):
19 student_homework_project = gitlab_instance.projects.get(student_repo["id"])
20 create_comment(deepcopy(comment), student_homework_project)
23def create_comment(comment: Comment, gitlab_project: Project) -> None:
24 """Create issue for gitlab project from task."""
25 uploaded_files = upload_attachments(comment.attachments, gitlab_project)
26 comment.message = replace_file_paths_with_urls(comment.message, uploaded_files, comment.attachments)
28 issue = gitlab_project.issues.get(comment.issue_id)
29 issue.notes.create({"body": comment.message})
30 if comment.state_event is not None:
31 issue.state_event = comment.state_event
32 issue.save()