|
@@ -87,8 +87,15 @@ class Rule(namedtuple("Rule", "matcher owners")):
|
|
|
def load(cls, data: Mapping[str, Any]) -> Rule:
|
|
|
return cls(Matcher.load(data["matcher"]), [Owner.load(o) for o in data["owners"]])
|
|
|
|
|
|
- def test(self, data: Mapping[str, Any]) -> bool | Any:
|
|
|
- return self.matcher.test(data)
|
|
|
+ def test(
|
|
|
+ self,
|
|
|
+ data: Mapping[str, Any],
|
|
|
+ munged_data: tuple[Sequence[Mapping[str, Any]], Sequence[str]] | None,
|
|
|
+ ) -> bool | Any:
|
|
|
+ if munged_data:
|
|
|
+ return self.matcher.test_with_munged(data, munged_data)
|
|
|
+ else:
|
|
|
+ return self.matcher.test(data)
|
|
|
|
|
|
|
|
|
class Matcher(namedtuple("Matcher", "type pattern")):
|
|
@@ -130,6 +137,33 @@ class Matcher(namedtuple("Matcher", "type pattern")):
|
|
|
|
|
|
return frames, keys
|
|
|
|
|
|
+ def test_with_munged(
|
|
|
+ self, data: PathSearchable, munged_data: tuple[Sequence[Mapping[str, Any]], Sequence[str]]
|
|
|
+ ) -> bool:
|
|
|
+ """
|
|
|
+ Temporary function to test pre-munging data performance in production. will remove
|
|
|
+ and combine with test if prod deployment goes well.
|
|
|
+ """
|
|
|
+ if self.type == URL:
|
|
|
+ return self.test_url(data)
|
|
|
+ elif self.type == PATH:
|
|
|
+ return self.test_frames(*munged_data)
|
|
|
+ elif self.type == MODULE:
|
|
|
+ return self.test_frames(find_stack_frames(data), ["module"])
|
|
|
+ elif self.type.startswith("tags."):
|
|
|
+ return self.test_tag(data)
|
|
|
+ elif self.type == CODEOWNERS:
|
|
|
+ return self.test_frames(
|
|
|
+ *munged_data,
|
|
|
+ # Codeowners has a slightly different syntax compared to issue owners
|
|
|
+ # As such we need to match it using gitignore logic.
|
|
|
+ # See syntax documentation here:
|
|
|
+ # https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-code-owners
|
|
|
+ match_frame_value_func=lambda val, pattern: bool(codeowners_match(val, pattern)),
|
|
|
+ match_frame_func=lambda frame: frame.get("in_app") is not False,
|
|
|
+ )
|
|
|
+ return False
|
|
|
+
|
|
|
def test(self, data: PathSearchable) -> bool:
|
|
|
if self.type == URL:
|
|
|
return self.test_url(data)
|