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

feat: add new target which is the default now: member_of

parent 968e09191349
......@@ -39,8 +39,8 @@ auto-mr:
- sed -i "s/TO_REPLACE_GITLAB_TOKEN/$GITLAB_TOKEN/" ~/.hgrc
script:
- cube-doctor rebase-all-my-mrs -a -d 10
- cube-doctor auto-mr -m -d 10
- cube-doctor auto-mr -d 10
- cube-doctor auto-mr -m -t cubes -d 10
- cube-doctor auto-mr -t cubes -d 10
artifacts:
paths:
- created_mr.log
......
......@@ -43,6 +43,61 @@ def check_if_python_script(filename):
return is_python
def get_all_projects_am_member_of(query):
cnx = gitlab.Gitlab(FORGE_HEPTAPOD, os.environ["GITLAB_TOKEN"])
# needed to get access to cnx.user.id
cnx.auth()
if query:
download_logigraphe_trig(cnx)
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
WHERE {
?project a doap:Project .
?project doap:name ?projectName .
%s
} ORDER BY ?projectName
"""
% query
)
logger.info(f"sparql query:\n{query}")
query_result = g.query(query)
if len(query_result) == 0:
raise EmptyCubeQueryResult(
f"ERROR: query failed to find any cube. Query:\n\n{query}"
)
for (project_id,) in query_result:
project = cnx.projects.get(id=project_id)
if cnx.user.id in {member.id for member in project.members.all(all=True)}:
yield project
else:
logger.info(
"no custom query, parsing all projects tagged 'project-dependency' or "
"'logilab-project' and in which I'm a user"
)
# for project in cnx.projects.list(all=True, as_list=False):
all_projects = (
x
for x in cnx.projects.list(all=True, as_list=False)
if cnx.user.id in {member.id for member in x.members.all(all=True)}
)
yield from all_projects
def get_all_cubes(query):
cnx = gitlab.Gitlab(FORGE_HEPTAPOD, os.environ["GITLAB_TOKEN"])
......@@ -368,6 +423,7 @@ class Command:
cubes = [get_project(project)]
else:
targets = {
"member_of": get_all_projects_am_member_of,
"cubes": get_all_cubes,
"clients": get_all_clients,
"core": get_all_core_projects,
......
......@@ -60,7 +60,7 @@ def auto_mr(merge_when_pipeline_succeeds, target, delay):
)
continue
if target not in command.__self__.__class__.TARGETS:
if target != "member_of" and target not in command.__self__.__class__.TARGETS:
logger.info(
f"skip command {command.__self__.__class__.__name__} because it is not meant to "
f"work on {target} projects"
......@@ -124,7 +124,10 @@ def main():
help="update existing MR if it exists",
)
parser.add_argument(
"-t", "--target", choices=["clients", "cubes", "core"], default="cubes"
"-t",
"--target",
choices=["clients", "cubes", "core", "member_of"],
default="member_of",
)
# advanced usage
......
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