From e7e0295791876ef5a3a00af8fb4a06c7f7965f1a Mon Sep 17 00:00:00 2001 From: Mateusz Szostok Date: Mon, 20 Nov 2023 13:03:15 +0100 Subject: [PATCH 1/2] Add opt to use regex for json path values --- internal/source/github_events/json_matcher.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/source/github_events/json_matcher.go b/internal/source/github_events/json_matcher.go index 53e499fae..955592d5b 100644 --- a/internal/source/github_events/json_matcher.go +++ b/internal/source/github_events/json_matcher.go @@ -3,6 +3,7 @@ package github_events import ( "encoding/json" "fmt" + "regexp" "strings" "github.com/sirupsen/logrus" @@ -27,11 +28,23 @@ func (j *JSONPathMatcher) IsEventMatchingCriteria(obj json.RawMessage, jsonPath, j.log.WithError(err).Errorf("while parsing %s JSONPath", jsonPath) return false } - if value != expValue { - return false + + return j.isEqual(expValue, value) +} + +func (j *JSONPathMatcher) isEqual(exp, got string) bool { + // exact match + if exp == got { + return true } - return true + // regexp + matched, err := regexp.MatchString(exp, got) + if err != nil { + j.log.WithError(err).Errorf("while matching %q with regex %q", got, exp) + return false + } + return matched } func (j *JSONPathMatcher) parseJsonpath(raw []byte, jsonpathStr string) (string, error) { From a4cdd4267f191126601777ce4952aa8c3ac73d18 Mon Sep 17 00:00:00 2001 From: Mateusz Szostok Date: Mon, 20 Nov 2023 13:18:05 +0100 Subject: [PATCH 2/2] Update jsonschema --- internal/source/github_events/jsonschema.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/source/github_events/jsonschema.json b/internal/source/github_events/jsonschema.json index ef03e34fd..b0c6b7ba5 100644 --- a/internal/source/github_events/jsonschema.json +++ b/internal/source/github_events/jsonschema.json @@ -221,10 +221,12 @@ }, "jsonPath": { "title": "JSONPath Expression", + "description": "The JSONPath expression to filter based on specific criteria within the event payload.", "type": "string" }, "value": { "title": "Value", + "description": "The regex value to match in the JSONPath result.", "type": "string" }, "notificationTemplate": {