Skip to content
Snippets Groups Projects
Commit 82c51df3 authored by Walter Lozano's avatar Walter Lozano Committed by Dylan Aïssi
Browse files

gitlab-check: More functionality to class


The functionality of expaning project was implemented as a stand alone
function, but there is no real benefit on doing that. Instead, move
this functionality to the class to make it easier to share data.

Signed-off-by: default avatarWalter Lozano <walter.lozano@collabora.com>
parent c6ea19f8
No related branches found
No related tags found
1 merge request!198Improvements to release pipeline (5)
......@@ -11,30 +11,6 @@ RETRY_PIPELINE = 1
RETRY_JOBS = 2
RETRY_RETRIGGER = 3
def expand_projects(config):
projects_to_check = set(config['projects'])
for project in projects_to_check:
print(f'Expanding {project} to:')
if project.endswith("/*"):
project_path = project.replace('/*', '')
project_group = gitlab_check.gitlab.groups.get(project_path, lazy=True)
list_subprojects = project_group.projects.list(get_all=True)
for subproject in list_subprojects:
subproject_id = gitlab_check.gitlab.projects.get(subproject.id)
subproject_branches = subproject_id.branches.list(get_all=True)
subproject_branches = [project.name for project in subproject_branches]
if set(config['ref']) & set(subproject_branches):
config['projects'].append(subproject_id.path_with_namespace)
print(f' {subproject_id.path_with_namespace}')
config['projects'].remove(project)
return config
class GitlabCheck():
def __init__(self, url = None, token = None, instance = None):
if url:
......@@ -50,6 +26,30 @@ class GitlabCheck():
self.gitlab.auth()
def expand_projects(self, config):
projects_to_check = set(config['projects'])
for project in projects_to_check:
print(f'Expanding {project} to:')
if project.endswith("/*"):
project_path = project.replace('/*', '')
project_group = gitlab_check.gitlab.groups.get(project_path, lazy=True)
list_subprojects = project_group.projects.list(get_all=True)
for subproject in list_subprojects:
subproject_id = gitlab_check.gitlab.projects.get(subproject.id)
subproject_branches = subproject_id.branches.list(get_all=True)
subproject_branches = [project.name for project in subproject_branches]
if set(config['ref']) & set(subproject_branches):
config['projects'].append(subproject_id.path_with_namespace)
print(f' {subproject_id.path_with_namespace}')
config['projects'].remove(project)
return config
def fetch_pipelines(self, project_name, fetch_all = False):
project = self.gitlab.projects.get(project_name)
pipelines = project.pipelines.list(get_all=fetch_all)
......@@ -179,7 +179,7 @@ if __name__ == '__main__':
gitlab_check = GitlabCheck(args.url, args.token, args.instance)
config = expand_projects(config)
config = gitlab_check.expand_projects(config)
if args.action == 'check-pipelines':
pipeline_count = gitlab_check.check_pipelines(args.all, args.ref, args.status, args.fetch_all, args.retry, args.verbose)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment