From 5448540c931641f958c65ae095d409c77792d994 Mon Sep 17 00:00:00 2001 From: MytkoEnko Date: Tue, 6 Feb 2024 20:00:27 +0100 Subject: [PATCH] Fmt and rename FieldsToUpdate Signed-off-by: Dmytro Aleksieiev --- pkg/config/config.go | 18 +++++++++--------- pkg/config/config_test.go | 2 +- pkg/notify/notify.go | 10 +++++----- pkg/notify/notify_test.go | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 0558857..3c8dc9f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -140,13 +140,13 @@ type ReceiverConfig struct { ReopenDuration *Duration `yaml:"reopen_duration" json:"reopen_duration"` // Optional issue fields - Priority string `yaml:"priority" json:"priority"` - Description string `yaml:"description" json:"description"` - WontFixResolution string `yaml:"wont_fix_resolution" json:"wont_fix_resolution"` - Fields map[string]interface{} `yaml:"fields" json:"fields"` - Components []string `yaml:"components" json:"components"` - StaticLabels []string `yaml:"static_labels" json:"static_labels"` - FieldsToUpdate []string `yaml:"update_always_fields" json:"update_always_fields"` + Priority string `yaml:"priority" json:"priority"` + Description string `yaml:"description" json:"description"` + WontFixResolution string `yaml:"wont_fix_resolution" json:"wont_fix_resolution"` + Fields map[string]interface{} `yaml:"fields" json:"fields"` + Components []string `yaml:"components" json:"components"` + StaticLabels []string `yaml:"static_labels" json:"static_labels"` + FieldsToUpdate []string `yaml:"update_always_fields" json:"update_always_fields"` // Label copy settings AddGroupLabels *bool `yaml:"add_group_labels" json:"add_group_labels"` @@ -313,8 +313,8 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { } } } - if len(c.Defaults.CustomFieldsToUpdate) > 0 { - rc.CustomFieldsToUpdate = c.Defaults.CustomFieldsToUpdate + if len(c.Defaults.FieldsToUpdate) > 0 { + rc.FieldsToUpdate = c.Defaults.FieldsToUpdate } if len(c.Defaults.StaticLabels) > 0 { rc.StaticLabels = append(rc.StaticLabels, c.Defaults.StaticLabels...) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 3ca2dcb..5e6ee99 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -134,7 +134,7 @@ type receiverTestConfig struct { Description string `yaml:"description,omitempty"` WontFixResolution string `yaml:"wont_fix_resolution,omitempty"` AddGroupLabels *bool `yaml:"add_group_labels,omitempty"` - UpdateInComment *bool `yaml:"update_in_comment,omitempty"` + UpdateInComment *bool `yaml:"update_in_comment,omitempty"` StaticLabels []string `yaml:"static_labels" json:"static_labels"` CustomFieldsToUpdate []string `yaml:"update_always_fields,omitempty"` diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index 11134dd..5af8eac 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -93,7 +93,7 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum issueCustomFields := tcontainer.NewMarshalMap() - for _, field := range r.conf.CustomFieldsToUpdate { + for _, field := range r.conf.FieldsToUpdate { if _, ok := r.conf.Fields[field]; ok { issueCustomFields[field], err = deepCopyWithTemplate(r.conf.Fields[field], r.tmpl, data) if err != nil { @@ -147,10 +147,10 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum } for field := range issueCustomFields { - if _, ok := issue.Fields.Unknowns[CustomField]; ok { - if issue.Fields.Unknowns[CustomField] != issueCustomFields[CustomField] { + if _, ok := issue.Fields.Unknowns[field]; ok { + if issue.Fields.Unknowns[field] != issueCustomFields[field] { retry, err = r.updateUnknownFields(issue.Key, tcontainer.MarshalMap(map[string]interface{}{ - CustomField: issueCustomFields[CustomField], + field: issueCustomFields[field], })) if err != nil { return retry, err @@ -340,7 +340,7 @@ func (r *Receiver) search(projects []string, issueLabel string) (*jira.Issue, bo projectList := "'" + strings.Join(projects, "', '") + "'" query := fmt.Sprintf("project in(%s) and labels=%q order by resolutiondate desc", projectList, issueLabel) options := &jira.SearchOptions{ - Fields: append([]string{"summary", "status", "resolution", "resolutiondate", "description", "comment"}, r.conf.CustomFieldsToUpdate...), + Fields: append([]string{"summary", "status", "resolution", "resolutiondate", "description", "comment"}, r.conf.FieldsToUpdate...), MaxResults: 2, } diff --git a/pkg/notify/notify_test.go b/pkg/notify/notify_test.go index ecb3016..c306a5f 100644 --- a/pkg/notify/notify_test.go +++ b/pkg/notify/notify_test.go @@ -238,7 +238,7 @@ func testReceiverConfigWithCustomFields() *config.ReceiverConfig { Fields: tcontainer.MarshalMap(map[string]interface{}{ "customfield_12345": `{{ (index .Alerts 0).Annotations.AlertValue }}`, }), - CustomFieldsToUpdate: []string{"customfield_12345", "non_existant_field"}, + FieldsToUpdate: []string{"customfield_12345", "non_existant_field"}, } }