Coverage for tools / sel_tools / gitlab_api / fetch_repo.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-02 18:55 +0000

1"""Clone or pull repos into a local workspace.""" 

2 

3import os 

4from pathlib import Path 

5 

6import gitlab 

7from gitlab.v4.objects import Project 

8from tqdm import tqdm 

9 

10from sel_tools.utils.repo import GitlabProject, GitRepo 

11from sel_tools.utils.student_config import get_branch_from_student_config 

12 

13 

14def fetch_repos(workspace: Path, student_repos: list[dict], gitlab_instance: gitlab.Gitlab) -> list[GitlabProject]: 

15 """Fetch the student repositories into the workspace.""" 

16 workspace.mkdir(parents=True, exist_ok=True) 

17 return [ 

18 fetch_repo( 

19 GitRepo(workspace / student_repo["name"], get_branch_from_student_config(student_repo)), 

20 gitlab_instance.projects.get(student_repo["id"]), 

21 ) 

22 for student_repo in tqdm(student_repos, desc="Fetching Repos") 

23 ] 

24 

25 

26def fetch_repo(repo: GitRepo, gitlab_project: Project) -> GitlabProject: 

27 """Clone or pull student repo.""" 

28 if os.environ.get("CI"): # This variable is set by the CI pipeline 

29 repo.fetch_from(gitlab_project.http_url_to_repo) 

30 elif repo.is_repo(): 

31 repo.pull() 

32 else: 

33 repo.clone(gitlab_project.ssh_url_to_repo) 

34 return GitlabProject(repo.path, gitlab_project)