Skip to content

Commit

Permalink
Fmt and rename FieldsToUpdate
Browse files Browse the repository at this point in the history
Signed-off-by: Dmytro Aleksieiev <[email protected]>
  • Loading branch information
MytkoEnko committed Feb 6, 2024
1 parent aa7bd7a commit 5448540
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
18 changes: 9 additions & 9 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
10 changes: 5 additions & 5 deletions pkg/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
}

Expand Down

0 comments on commit 5448540

Please sign in to comment.