Skip to content

Commit

Permalink
Add opt to use regex for json path values in github-events source(kub…
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok authored and huseyinbabal committed Nov 20, 2023
1 parent e66ae31 commit 567f893
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 16 additions & 3 deletions internal/source/github_events/json_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package github_events
import (
"encoding/json"
"fmt"
"regexp"
"strings"

"github.com/sirupsen/logrus"
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions internal/source/github_events/jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 567f893

Please sign in to comment.