[docs]defget_runner_from_description(gl:gitlab.Gitlab,descr:str)->gitlab.v4.objects.runners.Runner:"""Retrieve a runner object matching the description, or raises. Arguments: gl: gitlab service instance descr: the runner description Returns ------- The runner object, if one is found matching the description Raises ------ RuntimeError: if no runner matching the description is found. """# search for the runner to affectrunners=[kforkingl.runners.list(all=True)ifk.attributes["description"]==descr]ifnotrunners:raiseRuntimeError("Cannot find runner with description = %s",descr)the_runner=typing.cast(gitlab.v4.objects.runners.Runner,runners[0])logger.info("Found runner %s (id=%d)",the_runner.attributes["description"],the_runner.attributes["id"],)returnthe_runner
[docs]defget_project(gl:gitlab.Gitlab,name:str)->gitlab.v4.objects.projects.Project:"""Retrieve one single project."""retval=gl.projects.get(name)logger.debug("Found gitlab project %s (id=%d)",retval.attributes["path_with_namespace"],retval.id,)returnretval
[docs]defget_projects_from_group(gl:gitlab.Gitlab,name:str)->list[gitlab.v4.objects.projects.Project]:"""Return a list with all projects in a GitLab group."""group=gl.groups.get(name)logger.debug("Found gitlab group %s (id=%d)",group.attributes["path"],group.id,)projects=group.projects.list(all=True,simple=True)logger.info("Retrieving details for %d projects in group %s (id=%d). ""This may take a while...",len(projects),group.attributes["path"],group.id,)packages=[]fork,projinenumerate(projects):packages.append(get_project(gl,proj.id))logger.debug("Got data from project %d/%d",k+1,len(projects))returnpackages
[docs]defget_projects_from_runner(gl:gitlab.Gitlab,runner:gitlab.v4.objects.runners.Runner)->list[gitlab.v4.objects.projects.Project]:"""Retrieve a list of all projects that include a particular runner."""the_runner=gl.runners.get(runner.id)logger.info("Retrieving details for %d projects using runner %s (id=%d). ""This may take a while...",len(the_runner.projects),the_runner.description,the_runner.id,)packages=[]fork,projinenumerate(the_runner.projects):packages.append(get_project(gl,proj["id"]))logger.debug("Got data from project %d/%d",k+1,len(the_runner.projects))returnpackages
[docs]defget_projects_from_file(gl:gitlab.Gitlab,filename:pathlib.Path)->list[gitlab.v4.objects.projects.Project]:"""Retrieve a list of projects based on lines of a file."""packages=[]withfilename.open("rt")asf:lines=[k.strip()forkinf.readlines()]lines=[kforkinlinesifkandnotk.startswith("#")]logger.info("Loaded %d entries from file %s",len(lines),filename)fork,projinenumerate(lines):packages.append(get_project(gl,proj))logger.debug("Got data from project %d/%d",k+1,len(lines))returnpackages