Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opt to use regex for json path values #1313

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading