From 84d4d39e9deab9e9460e67feceb37423c0ec875e Mon Sep 17 00:00:00 2001 From: davidegirardi <16451191+davidegirardi@users.noreply.github.com> Date: Thu, 30 Jan 2025 08:47:26 +0100 Subject: [PATCH] Match either an app or the user text in the rejection conditions --- main.go | 54 +++++++++++++++++++++++++------------------ rageshake.sample.yaml | 3 +-- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/main.go b/main.go index 20dfc03..493220b 100644 --- a/main.go +++ b/main.go @@ -99,45 +99,53 @@ type config struct { } // RejectionCondition contains the fields that should match a bug report for it to be rejected. +// The condition matches a specific app, with optionall version and label, or the user submitted text type RejectionCondition struct { - // Required field: if a payload does not match this app name, the condition does not match. + // If a payload is not a UserTextMatch and does not match this app name, the condition does not match. App string `yaml:"app"` // Optional: version that must also match in addition to the app and label. If empty, does not check version. 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"` + // Alternative to matching app names, match the content of the user text UserTextMatch string `yaml:"usertextmatch"` } -// shouldReject returns true if the app name AND version AND labels all match the rejection condition. +// shouldReject returns true in two situations: +// - if the app name AND version AND labels all match the rejection condition. +// - if the text provided by the user matches a regex specified in 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, userText string) bool { - var userTextRegexp = regexp.MustCompile(c.UserTextMatch) - if c.UserTextMatch != "" && userTextRegexp.MatchString(userText) { - return true - } - if appName != c.App { - return false - } - // version was a condition and it doesn't match => accept it - if version != c.Version && c.Version != "" { - return false - } + if c.App != "" { + if appName != c.App { + return false + } + // version was a condition and it doesn't match => accept it + if version != c.Version && c.Version != "" { + return false + } - // label was a condition and no label matches it => accept it - if c.Label != "" { - labelMatch := false - for _, l := range labels { - if l == c.Label { - labelMatch = true - break + // label was a condition and no label matches it => accept it + if c.Label != "" { + labelMatch := false + for _, l := range labels { + if l == c.Label { + labelMatch = true + break + } + } + if !labelMatch { + return false } } - if !labelMatch { - return false + } + if c.UserTextMatch != "" { + var userTextRegexp = regexp.MustCompile(c.UserTextMatch) + if userTextRegexp.MatchString(userText) { + return true } } - return true } diff --git a/rageshake.sample.yaml b/rageshake.sample.yaml index cccc805..991f837 100644 --- a/rageshake.sample.yaml +++ b/rageshake.sample.yaml @@ -23,8 +23,7 @@ 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}" + - usertextmatch: "(\\w{4}\\s){11}\\w{4}" # reject text containing possible recovery keys # a GitHub personal access token (https://github.com/settings/tokens), which # will be used to create a GitHub issue for each report. It requires