Skip to content

Commit

Permalink
Proof of concept filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegirardi committed Jan 30, 2025
1 parent 1d0a896 commit efc824a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"net"
"net/http"
"os"
"regexp"
"strings"
"text/template"
"time"
Expand Down Expand Up @@ -105,11 +106,16 @@ type RejectionCondition struct {
Version string `yaml:"version"`
// Optional: label that must also match in addition to the app and version. If empty, does not check label.
Label string `yaml:"label"`
UserTextMatch string `yaml:"usertextmatch"`
}

// shouldReject returns true if the app name AND version AND labels all match the rejection condition.
// If any one of these do not match the condition, it is not rejected.
func (c RejectionCondition) shouldReject(appName, version string, labels []string) bool {
func (c RejectionCondition) shouldReject(appName, version string, labels []string, userText string) bool {
var userTextRegexp = regexp.MustCompile(c.UserTextMatch)
if c.UserTextMatch != "" && userTextRegexp.MatchString(userText) {
return true
}
if appName != c.App {
return false
}
Expand Down Expand Up @@ -141,7 +147,7 @@ func (c *config) matchesRejectionCondition(p *payload) bool {
if p.Data != nil {
version = p.Data["Version"]
}
if rc.shouldReject(p.AppName, version, p.Labels) {
if rc.shouldReject(p.AppName, version, p.Labels, p.UserText) {
return true
}
}
Expand Down
2 changes: 2 additions & 0 deletions rageshake.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ rejection_conditions:
- app: my-app
version: "0.4.9"
label: "nightly" # both label and Version must match for this condition to be true
- app: whatever
usertextmatch: "(\\w{4}\\s){11}\\w{4}"

# a GitHub personal access token (https://github.com/settings/tokens), which
# will be used to create a GitHub issue for each report. It requires
Expand Down

0 comments on commit efc824a

Please sign in to comment.