Skip to content

Commit

Permalink
Make transitionIssue private
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke committed Jun 20, 2024
1 parent 510ccb6 commit 23628b3
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions notify/jira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,30 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
result := tmplText(tmpl)
return result, tmplTextErr
}

path string
method string
)

existingIssue, shouldRetry, err := n.searchExistingIssue(key, alerts.Status())
if err != nil {
return shouldRetry, fmt.Errorf("error searching existing issues: %w", err)
}

// Do not create new issues for resolved alerts
if existingIssue == nil && alerts.Status() == model.AlertResolved {
return false, nil
}

path := "issue"
method := http.MethodPost

if existingIssue == nil {
// Do not create new issues for resolved alerts
if alerts.Status() == model.AlertResolved {
return false, nil
}

level.Debug(n.logger).Log("msg", "create new issue", "alert", key.String())

path = "issue"
method = http.MethodPost
} else {
level.Debug(n.logger).Log("msg", "updating existing issue", "key", existingIssue.Key, "alert", key.String())

path += "/" + existingIssue.Key
path = "issue/" + existingIssue.Key
method = http.MethodPut
}

Expand All @@ -122,9 +125,9 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)

if existingIssue != nil && existingIssue.Key != "" && existingIssue.Fields != nil && existingIssue.Fields.Status != nil {
if n.conf.ResolveTransition != "" && alerts.Status() == model.AlertResolved && existingIssue.Fields.Status.StatusCategory.Key != "done" {
return n.TransitionIssue(key, existingIssue.Key, n.conf.ResolveTransition)
return n.transitionIssue(key, existingIssue.Key, n.conf.ResolveTransition)
} else if n.conf.ReopenTransition != "" && alerts.Status() == model.AlertFiring && existingIssue.Fields.Status.StatusCategory.Key == "done" {
return n.TransitionIssue(key, existingIssue.Key, n.conf.ReopenTransition)
return n.transitionIssue(key, existingIssue.Key, n.conf.ReopenTransition)
}
}

Expand Down Expand Up @@ -261,7 +264,7 @@ func (n *Notifier) getIssueTransitionByName(issueKey, transitionName string) (st
return "", false, fmt.Errorf("can't find transition %s for issue %s", transitionName, issueKey)
}

func (n *Notifier) TransitionIssue(key notify.Key, issueKey, transitionName string) (bool, error) {
func (n *Notifier) transitionIssue(key notify.Key, issueKey, transitionName string) (bool, error) {
transitionID, shouldRetry, err := n.getIssueTransitionByName(issueKey, transitionName)
if err != nil {
return shouldRetry, err
Expand Down

0 comments on commit 23628b3

Please sign in to comment.