Skip to content

fix(jira): correctly handle issues with null resolution (Fixes #4295) #4370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion notify/jira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ func (n *Notifier) searchExistingIssue(ctx context.Context, logger *slog.Logger,
jql := strings.Builder{}

if n.conf.WontFixResolution != "" {
jql.WriteString(fmt.Sprintf(`resolution != %q and `, n.conf.WontFixResolution))
// Ensure unresolved issues are included by adding `resolution is EMPTY` condition.
// This avoids excluding issues without a resolution when using `resolution != <value>`.
jql.WriteString(fmt.Sprintf(`(resolution is EMPTY or resolution != %q) and `, n.conf.WontFixResolution))
}

// If the group is firing, do not search for closed issues unless a reopen transition is defined.
Expand Down
57 changes: 57 additions & 0 deletions notify/jira/jira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ func TestSearchExistingIssue(t *testing.T) {
return
}
require.Equal(t, expectedJQL, data.JQL)

// Return different responses based on the request
if strings.Contains(data.JQL, `ALERT{2}`) {
// Unresolved issue exists (resolution is EMPTY)
w.Write([]byte(`{"total": 1, "issues": [{"key": "CRM-999", "fields": {"status": {"name": "To Do"}}}]}`))
return
}
if strings.Contains(data.JQL, `ALERT{3}`) {
// Resolved issue exists (resolution is Done)
w.Write([]byte(`{"total": 1, "issues": [{"key": "CRM-998", "fields": {"status": {"name": "Done"}}}]}`))
return
}
// Default: No matching issues found().Add(time.Hour),
w.Write([]byte(`{"total": 0, "issues": []}`))
return
default:
Expand Down Expand Up @@ -115,6 +128,50 @@ func TestSearchExistingIssue(t *testing.T) {
groupKey: "1",
expectedJQL: `statusCategory != Done and project="PROJ" and labels="ALERT{1}" order by status ASC,resolutiondate DESC`,
},
{
title: "existing unresolved issue (resolution is EMPTY)",
cfg: &config.JiraConfig{
Summary: `{{ template "jira.default.summary" . }}`,
Description: `{{ template "jira.default.description" . }}`,
Project: `{{ .CommonLabels.project }}`,
WontFixResolution: "Won't Fix",
},
groupKey: "2",
expectedJQL: `(resolution is EMPTY or resolution != "Won't Fix") and statusCategory != Done and project="PROJ" and labels="ALERT{2}" order by status ASC,resolutiondate DESC`,
expectedIssue: &issue{
Key: "CRM-999",
Fields: &issueFields{
Status: &issueStatus{
Name: "To Do",
StatusCategory: struct {
Key string `json:"key"`
}{Key: ""},
},
},
},
},
{
title: "existing resolved issue (resolution Done)",
cfg: &config.JiraConfig{
Summary: `{{ template "jira.default.summary" . }}`,
Description: `{{ template "jira.default.description" . }}`,
Project: `{{ .CommonLabels.project }}`,
WontFixResolution: "Won't Fix",
},
groupKey: "3",
expectedJQL: `(resolution is EMPTY or resolution != "Won't Fix") and statusCategory != Done and project="PROJ" and labels="ALERT{3}" order by status ASC,resolutiondate DESC`,
expectedIssue: &issue{
Key: "CRM-998",
Fields: &issueFields{
Status: &issueStatus{
Name: "Done",
StatusCategory: struct {
Key string `json:"key"`
}{Key: ""},
},
},
},
},
} {
tc := tc
t.Run(tc.title, func(t *testing.T) {
Expand Down