Commit 95376b96 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

feat(auto-mr): use Command.base_query to check if I need to apply a command on a cube

parent 860ef61c64d2
Pipeline #83897 failed with stage
in 3 minutes and 36 seconds
......@@ -409,6 +409,7 @@ class Command:
return self._workflow(*args, **kwargs)
wrap.command_name = self.command_name
wrap.base_query = self.base_query
self.workflow = wrap
def pre_check(self, root_files):
......
import os
import gitlab
import argparse
import subprocess
from loguru import logger
from rdflib import ConjunctiveGraph
from heptalab import download_logigraphe_trig
from cube_doctor import (
parse_config,
get_all_projects_am_member_of,
FORGE_HEPTAPOD,
)
from cube_doctor.utils import COMMANDS, commands_to_run
from cube_doctor.transforms.propose_base_config import ProposeBaseConfig
......@@ -18,7 +24,28 @@ def hg_command(dir, command):
subprocess.check_call(f"cd {dir} && {command}", shell=True)
AUTO_MR_BASE_QUERY = """
prefix lgg: <http://data.logilab.fr/logigraphe/>
prefix lon: <http://data.logilab.fr/ontology/network/>
prefix dep: <http://ontologi.es/doap-deps#>
prefix doap: <http://usefulinc.com/ns/doap#>
SELECT ?projectId
WHERE {
?project a doap:Project .
?project lgg:heptapod_id %s .
%s
}
"""
def auto_mr():
cnx = gitlab.Gitlab(FORGE_HEPTAPOD, os.environ["GITLAB_TOKEN"])
download_logigraphe_trig(cnx)
g = ConjunctiveGraph()
g.parse("./logigraphe.trig", format="trig")
for project in get_all_projects_am_member_of(""):
config = parse_config(project)
......@@ -35,7 +62,15 @@ def auto_mr():
continue
for command, arguments in commands_to_run(config):
# checks?
if command.base_query:
query_result = g.query(
AUTO_MR_BASE_QUERY % (project.id, command.base_query)
)
if len(query_result) == 0:
logger.info(
f"Project '{project.id} {project.name}' doesn't match command {command.command_name} query {command.base_query}, skip"
)
continue
logger.info(
f"Launch command {command.command_name} with arguments {arguments}"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment