Skip to content

Commit

Permalink
Fix rosdep file targeting with head_ref argument (#16)
Browse files Browse the repository at this point in the history
When we're using `head_ref`, we should determine what rosdep files exist
in the tree behind that ref, and not which files are present in the
working directory.
  • Loading branch information
cottsay authored Sep 20, 2024
1 parent f110b29 commit 26290b5
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions rosdistro_reviewer/element_analyzer/rosdep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the Apache License, Version 2.0

from pathlib import Path
from pathlib import PurePosixPath
from typing import Any
from typing import Dict
from typing import List
Expand All @@ -10,6 +11,9 @@

from colcon_core.logging import colcon_logger
from colcon_core.plugin_system import satisfies_version
from git import Repo
from git.objects import Blob
from git.objects import Tree
from rosdep2 import create_default_installer_context
from rosdistro_reviewer.element_analyzer \
import ElementAnalyzerExtensionPoint
Expand Down Expand Up @@ -291,15 +295,34 @@ def _check_installers(criteria, annotations, changed_rosdeps):
criteria.append(Criterion(recommendation, message))


def _is_yaml_blob(item, depth) -> bool:
return PurePosixPath(item.path).suffix == '.yaml'


def _get_changed_rosdeps(
path: Path,
target_ref: Optional[str] = None,
head_ref: Optional[str] = None,
) -> Tuple[Optional[Dict[str, int]], Optional[Dict[str, Any]]]:
rosdep_files = [
str(p.relative_to(path))
for p in path.glob('rosdep/*.yaml')
]
if head_ref:
with Repo(path) as repo:
tree = repo.tree(head_ref)
try:
tree = tree['rosdep']
except KeyError:
return None, None
if not isinstance(tree, Tree):
return None, None
rosdep_files = [
str(item.path)
for item in tree.traverse(predicate=_is_yaml_blob)
if isinstance(item, Blob)
]
else:
rosdep_files = [
str(p.relative_to(path))
for p in path.glob('rosdep/*.yaml')
]
if not rosdep_files:
logger.info('No rosdep files were found in the repository')
return None, None
Expand Down

0 comments on commit 26290b5

Please sign in to comment.