Skip to content

Commit b046b17

Browse files
authored
Merge pull request #4478 from pehlicd/main
fix jira notifier reopen logic
2 parents c653800 + 732172c commit b046b17

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

notify/jira/jira.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,17 @@ func (n *Notifier) searchExistingIssue(ctx context.Context, logger *slog.Logger,
201201
jql.WriteString(fmt.Sprintf(`resolution != %q and `, n.conf.WontFixResolution))
202202
}
203203

204-
// If the group is firing, do not search for closed issues unless a reopen transition is defined.
204+
// If the group is firing, search for open issues. If a reopen transition is
205+
// defined, also search for issues that were closed within the reopen duration.
205206
if firing {
206-
if n.conf.ReopenTransition == "" {
207-
jql.WriteString(`statusCategory != Done and `)
208-
}
209-
} else {
210207
reopenDuration := int64(time.Duration(n.conf.ReopenDuration).Minutes())
211-
if reopenDuration != 0 {
208+
if n.conf.ReopenTransition != "" && reopenDuration > 0 {
212209
jql.WriteString(fmt.Sprintf(`(resolutiondate is EMPTY OR resolutiondate >= -%dm) and `, reopenDuration))
210+
} else {
211+
jql.WriteString(`statusCategory != Done and `)
213212
}
213+
} else {
214+
jql.WriteString(`statusCategory != Done and `)
214215
}
215216

216217
alertLabel := fmt.Sprintf("ALERT{%s}", groupID)

notify/jira/jira_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,45 @@ func TestSearchExistingIssue(t *testing.T) {
100100
title string
101101
cfg *config.JiraConfig
102102
groupKey string
103+
firing bool
103104
expectedJQL string
104105
expectedIssue *issue
105106
expectedErr bool
106107
expectedRetry bool
107108
}{
108109
{
109-
title: "search existing issue with project template",
110+
title: "search existing issue with project template for firing alert",
110111
cfg: &config.JiraConfig{
111112
Summary: `{{ template "jira.default.summary" . }}`,
112113
Description: `{{ template "jira.default.description" . }}`,
113114
Project: `{{ .CommonLabels.project }}`,
114115
},
115116
groupKey: "1",
117+
firing: true,
118+
expectedJQL: `statusCategory != Done and project="PROJ" and labels="ALERT{1}" order by status ASC,resolutiondate DESC`,
119+
},
120+
{
121+
title: "search existing issue with reopen duration for firing alert",
122+
cfg: &config.JiraConfig{
123+
Summary: `{{ template "jira.default.summary" . }}`,
124+
Description: `{{ template "jira.default.description" . }}`,
125+
Project: `{{ .CommonLabels.project }}`,
126+
ReopenDuration: model.Duration(60 * time.Minute),
127+
ReopenTransition: "REOPEN",
128+
},
129+
groupKey: "1",
130+
firing: true,
131+
expectedJQL: `(resolutiondate is EMPTY OR resolutiondate >= -60m) and project="PROJ" and labels="ALERT{1}" order by status ASC,resolutiondate DESC`,
132+
},
133+
{
134+
title: "search existing issue for resolved alert",
135+
cfg: &config.JiraConfig{
136+
Summary: `{{ template "jira.default.summary" . }}`,
137+
Description: `{{ template "jira.default.description" . }}`,
138+
Project: `{{ .CommonLabels.project }}`,
139+
},
140+
groupKey: "1",
141+
firing: false,
116142
expectedJQL: `statusCategory != Done and project="PROJ" and labels="ALERT{1}" order by status ASC,resolutiondate DESC`,
117143
},
118144
} {
@@ -147,7 +173,7 @@ func TestSearchExistingIssue(t *testing.T) {
147173
return tmplText(tmpl), tmplTextErr
148174
}
149175

150-
issue, retry, err := pd.searchExistingIssue(ctx, logger, tc.groupKey, true, tmplTextFunc)
176+
issue, retry, err := pd.searchExistingIssue(ctx, logger, tc.groupKey, tc.firing, tmplTextFunc)
151177
if tc.expectedErr {
152178
require.Error(t, err)
153179
} else {

0 commit comments

Comments
 (0)