From 59aeedbcd013d506e7780560c8f472b4d4769ad3 Mon Sep 17 00:00:00 2001 From: Alik Khilazhev Date: Wed, 30 Nov 2022 14:57:48 +0700 Subject: [PATCH] feat: add reopen_enabled flag - fixes #120 --- pkg/config/config.go | 11 +++++++++++ pkg/notify/notify.go | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index f72809c..b15fd59 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -135,6 +135,7 @@ type ReceiverConfig struct { Project string `yaml:"project" json:"project"` IssueType string `yaml:"issue_type" json:"issue_type"` Summary string `yaml:"summary" json:"summary"` + ReopenEnabled *bool `yaml:"reopen_enabled" json:"reopen_enabled"` ReopenState string `yaml:"reopen_state" json:"reopen_state"` ReopenDuration *Duration `yaml:"reopen_duration" json:"reopen_duration"` @@ -212,6 +213,11 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { } } + if c.Defaults.ReopenEnabled == nil { + var defaultReopenEnabled = false + c.Defaults.ReopenEnabled = &defaultReopenEnabled + } + for _, rc := range c.Receivers { if rc.Name == "" { return fmt.Errorf("missing name for receiver %+v", rc) @@ -269,6 +275,11 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { } rc.Summary = c.Defaults.Summary } + + if rc.ReopenEnabled == nil { + rc.ReopenEnabled = c.Defaults.ReopenEnabled + } + if rc.ReopenState == "" { if c.Defaults.ReopenState == "" { return fmt.Errorf("missing reopen_state in receiver %q", rc.Name) diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index 00a2d9e..0d1f733 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -17,12 +17,13 @@ import ( "bytes" "crypto/sha512" "fmt" - "github.com/andygrunwald/go-jira" "io" "reflect" "strings" "time" + "github.com/andygrunwald/go-jira" + "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/pkg/errors" @@ -299,6 +300,12 @@ func (r *Receiver) search(project, issueLabel string) (*jira.Issue, bool, error) } func (r *Receiver) findIssueToReuse(project string, issueGroupLabel string) (*jira.Issue, bool, error) { + + if !*r.conf.ReopenEnabled { + level.Debug(r.logger).Log("msg", "reopening disabled, skipping search for existing issue") + return nil, false, nil + } + issue, retry, err := r.search(project, issueGroupLabel) if err != nil { return nil, retry, err