Commit f1b4d072 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

feat: add `-p` option to select one specific project

parent fec07bcf4ad1
Pipeline #29261 failed with stage
in 40 seconds
......@@ -114,6 +114,12 @@ All commands share the same CLI arguments. They are:
-q, --query
Additional conditions to pass to the sparql query SELECT section.
-p, --project
If specified, select one specific project instead of using the query.
Arguments supported are: project id (an it), project url and project name
Default value: None (unused)
Sparql query reference
----------------------
......
......@@ -7,7 +7,7 @@ import subprocess
from time import sleep
from rdflib import ConjunctiveGraph
from pathlib import Path
from heptalab import download_heptapod_trig
from heptalab import download_heptapod_trig, download_logigraphe_trig
FORGE_HEPTAPOD = "https://forge.extranet.logilab.fr/"
......@@ -90,6 +90,50 @@ def get_all_cubes(query):
yield from all_cubes
def get_project(project):
cnx = gitlab.Gitlab(FORGE_HEPTAPOD, os.environ["GITLAB_TOKEN"])
download_logigraphe_trig(cnx) # operate of the whole forge
g = ConjunctiveGraph()
g.parse("./logigraphe.trig", format="trig")
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 ?project ?projectName ?projectDescription
WHERE {
?project a doap:Project .
?project doap:name ?projectName .
?project lgg:heptapod_id ?projectId .
?project dc:description ?projectDescription .
}
""")
query_result = g.query(query)
if len(query_result) == 0:
raise EmptyCubeQueryResult(
f"ERROR: query failed to find any cube. Query:\n\n{query}"
)
question_to_id = {}
for (project_id, project_url, project_name, project_description) in query_result:
question_to_id[str(project_url).lower()] = project_id
question_to_id[str(project_name).lower()] = project_id
question_to_id[str(project_name).replace("cubicweb-", "").lower()] = project_id
question_to_id[str(project_description).replace(" ", "").lower()] = project_id
if project.isdigit():
return cnx.projects.get(int(project))
return cnx.projects.get(int(question_to_id[project.lower()]))
class Repository:
def __init__(self, url):
self.url = url
......@@ -147,6 +191,7 @@ class Command:
merge_when_pipeline_succeeds=False,
number=None,
additional_checks=None,
project=None,
):
assert self.BRANCH_NAME is not None
......@@ -161,7 +206,7 @@ class Command:
number = int(number) if number is not None else None
cube_number_x = 0
for cube in get_all_cubes(query):
for cube in get_all_cubes(query) if project is None else [get_project(project)]:
if number is not None and cube_number_x >= number:
return
......
......@@ -72,6 +72,7 @@ if __name__ == "__main__":
)
parser.add_argument("-n", "--number", type=int)
parser.add_argument("-q", "--query", default="")
parser.add_argument("-p", "--project", default=None)
args = parser.parse_args()
......@@ -84,4 +85,5 @@ if __name__ == "__main__":
merge_when_pipeline_succeeds=args.merge_when_pipeline_succeeds,
number=args.number,
query=args.query,
project=args.project,
)
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