Repository navigation
feat(parser): support regex matching on JSON arrays with scalar elements - #1163
Conversation
Signed-off-by: Shingo OKAWA <shingo.okawa.g.h.c@gmail.com>
|
cc: @RJSonnenberg |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1163 +/- ##
==========================================
+ Coverage 41.95% 42.30% +0.35%
==========================================
Files 21 21
Lines 1981 1991 +10
==========================================
+ Hits 831 842 +11
+ Misses 1150 1149 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Shingo OKAWA <shingo.okawa.g.h.c@gmail.com>
Signed-off-by: Shingo OKAWA <shingo.okawa.g.h.c@gmail.com>
Signed-off-by: Shingo OKAWA <shingo.okawa.g.h.c@gmail.com>
Signed-off-by: Shingo OKAWA <shingo.okawa.g.h.c@gmail.com>
|
Hey @RJSonnenberg (cc: @orhun ) , I generated the Previously, I believe this served as the fallback group setting. However, with the default continues to work as a fallback as before. Note: The original rule ends up matching an empty JSON array ( Any thoughts on this? |
…-json-array-field-matcher Signed-off-by: Shingo OKAWA <shingo.okawa.g.h.c@gmail.com>
I think that is a fine compromise. Like you said, the original only worked as a fallback, so the new fallback group setting looks fine to me. It might throw people off, but as long as it is documented well, we should be good. |
|
Thanks for your feedback! |
| /// Mode to match regex against fields: any or all. | ||
| #[serde(default)] | ||
| pub match_mode: MatchMode, |
There was a problem hiding this comment.
From reading the changes, it's not clear to me why this was added to fix this problem. Can you share some details?
Also, we should document this if it is a necessary change :)
There was a problem hiding this comment.
Thanks for the question!
To clarify with a concrete case: imagine we want to match PRs where at least one of the labels matches a pattern like "enhancement|refactor". If a commit has remote.pr_labels = ["feature", "refactor"], then:
- With
match_mode = "any", this is a match (since"refactor"matches). - With
match_mode = "all", it's not a match (since"feature"doesn't match).
Detailed Example
commit_parsers = [
{ field = "remote.pr_labels", pattern = "enhancement|refactor", group = "<!-- 1 -->🛠️ Enhancements" },
]
Given:
remote.pr_labels = ["feature", "refactor"]
✅ MatchMode::Any
- "feature" → ❌ (does not match)
- "refactor" → ✅ (matches)
→ Since at least one label matches, the whole condition is satisfied.
❌ MatchMode::All
- "feature" → ❌
- "refactor" → ✅
→ Since not all labels match, the match fails.
Explanation
Previously, CommitParser implicitly treated the remote.pr_labels field as if MatchMode::Any were applied, except when the field was empty.
With this internal changes where the field is now handled as a Vec, I introduced match_mode to make the aggregation behavior of regex matching across vector elements explicit at the API level — i.e., whether the matches should be interpreted as an AND or an OR.
This change ensures that the matching semantics are both predictable and configurable moving forward.
There was a problem hiding this comment.
Hmm I see... I still think that we can avoid this new field though. Maybe loop through each value in Value::Array and add them to the regex_checks array, wouldn't that work?
If we are going to go forward with it then we should document that this is useful for array types and also figure out if there are any other edge cases.
There was a problem hiding this comment.
You're right, and I think the behavior you're describing is actually quite similar to what I implemented with MatchMode::Any. It maintains backward compatibility while enabling more flexible matching for array values.
I'll try rewriting the implementation with this in mind and see if it simplifies the design. Thanks for the input!
There was a problem hiding this comment.
Cool, let me know about your progress :)
There was a problem hiding this comment.
Thanks! I’ve implemented the changes as you suggested.
One thing to note—as I mentioned in this comment—is that the following fallback:
{ field = "remote.pr_labels", pattern = ".*", group = "<!-- 5 -->🌀 Miscellaneous" },
no longer works as expected. Instead, you’ll need to use:
{ message = ".*", group = "<!-- 6 --> 🌀 Miscellaneous" },
The core logic update is complete, and the only remaining task is to add fixtures. I plan to address that as discussed in this thread.
There was a problem hiding this comment.
@orhun (cc: @RJSonnenberg)
Also, as an initial fixture test, I’ve added one based on the commit history from this repository:
https://github.com/mta-solutions/fsharp-data-validation
That said, if you think it’s better for maintainability to have a dedicated test case, as we discussed in the discussion thread, I can also add a commit history that uses PR labels explicitly for testing purposes. Let me know what you think :)
There was a problem hiding this comment.
Nice!
We can update/expand the fixtures after that discussion is resolved :)
Thanks for your work on this!
There was a problem hiding this comment.
Sure — we’ll continue the discussion there and figure out the best approach.
Thanks again for your support!
|
Hey guys! I just had some time catch up with #1157 and this PR - thanks for investigating and possible fix! I'd like to take a step back and see a minimal example what's broken for understanding this fix better. @ognis1205 can you add a new fixture test? Preferably for grouping |
This comment was marked as resolved.
This comment was marked as resolved.
Signed-off-by: Shingo OKAWA <shingo.okawa.g.h.c@gmail.com>
Signed-off-by: Shingo OKAWA <shingo.okawa.g.h.c@gmail.com>
Signed-off-by: Shingo OKAWA <shingo.okawa.g.h.c@gmail.com>
Signed-off-by: Shingo OKAWA <shingo.okawa.g.h.c@gmail.com>
|
I really appreciate your patience and thoroughness in the reviews. Thank you! |
|
Thanks for implementing! |
Description
This PR extends the commit parser to support regex matching on JSON arrays, where each element is a scalar value (e.g., strings, numbers, booleans). When a commit field (like
remote.pr_labels) is a JSON array, all entries are evaluated according to the specifiedmatch_mode(anyorall). Fixes #1157Motivation and Context
Previously, only scalar JSON values (e.g., strings, numbers) were matched against regex patterns. This change extends support to JSON arrays, where each element is a scalar value. All values in the array are checked based on the configured match mode (
any/all).How Has This Been Tested?
CHANGELOG.md:Screenshots / Logs (if applicable)
N/A
Types of Changes
Checklist: