Skip to content

Commit a33c4f8

Browse files
authored
fix: jira update ticket (#5122)
1 parent 4d07f64 commit a33c4f8

File tree

7 files changed

+397
-13
lines changed

7 files changed

+397
-13
lines changed

docs/snippets/providers/jira-snippet-autogenerated.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{/* This snippet is automatically generated using scripts/docs_render_provider_snippets.py
1+
{/* This snippet is automatically generated using scripts/docs_render_provider_snippets.py
22
Do not edit it manually, as it will be overwritten */}
33

44
## Authentication
@@ -8,12 +8,12 @@ This provider requires authentication.
88
- **host**: Atlassian Jira Host (required: True, sensitive: False)
99

1010
Certain scopes may be required to perform specific actions or queries via the provider. Below is a summary of relevant scopes and their use cases:
11-
- **BROWSE_PROJECTS**: Browse Jira Projects (mandatory)
12-
- **CREATE_ISSUES**: Create Jira Issues (mandatory)
13-
- **CLOSE_ISSUES**: Close Jira Issues
14-
- **EDIT_ISSUES**: Edit Jira Issues
15-
- **DELETE_ISSUES**: Delete Jira Issues
16-
- **MODIFY_REPORTER**: Modify Jira Issue Reporter
11+
- **BROWSE_PROJECTS**: Browse Jira Projects (mandatory)
12+
- **CREATE_ISSUES**: Create Jira Issues (mandatory)
13+
- **CLOSE_ISSUES**: Close Jira Issues
14+
- **EDIT_ISSUES**: Edit Jira Issues
15+
- **DELETE_ISSUES**: Delete Jira Issues
16+
- **MODIFY_REPORTER**: Modify Jira Issue Reporter
1717

1818

1919

@@ -59,4 +59,6 @@ Check the following workflow examples:
5959
- [create_jira_ticket_upon_alerts.yml](https://github.com/keephq/keep/blob/main/examples/workflows/create_jira_ticket_upon_alerts.yml)
6060
- [incident-enrich.yaml](https://github.com/keephq/keep/blob/main/examples/workflows/incident-enrich.yaml)
6161
- [jira_on_prem.yml](https://github.com/keephq/keep/blob/main/examples/workflows/jira_on_prem.yml)
62+
- [test_jira_create_with_custom_fields.yml](https://github.com/keephq/keep/blob/main/examples/workflows/test_jira_create_with_custom_fields.yml)
63+
- [test_jira_custom_fields_fix.yml](https://github.com/keephq/keep/blob/main/examples/workflows/test_jira_custom_fields_fix.yml)
6264
- [update_jira_ticket.yml](https://github.com/keephq/keep/blob/main/examples/workflows/update_jira_ticket.yml)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
workflow:
2+
id: test-jira-create-custom-fields
3+
name: Test Jira Create with Custom Fields
4+
description: Test workflow to demonstrate CREATE operations with custom fields
5+
disabled: false
6+
triggers:
7+
- type: manual
8+
inputs: []
9+
consts: {}
10+
owners: []
11+
services: []
12+
steps: []
13+
actions:
14+
- name: jira-action
15+
provider:
16+
type: jira
17+
config: "{{ providers.jira }}"
18+
with:
19+
project_key: "TEST"
20+
board_name: "TEST"
21+
summary: "Create new issue with custom fields"
22+
description: "This is a test issue created with custom fields"
23+
issue_type: "Task"
24+
custom_fields:
25+
customfield_10696: "10"
26+
customfield_10201: "Critical"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
workflow:
2+
id: test-jira-custom-fields-fix
3+
name: Test Jira Custom Fields Fix
4+
description: Test workflow to demonstrate the fix for Jira custom fields update issue
5+
disabled: false
6+
triggers:
7+
- type: manual
8+
inputs: []
9+
consts: {}
10+
owners: []
11+
services: []
12+
steps: []
13+
actions:
14+
- name: jira-action
15+
provider:
16+
type: jira
17+
config: "{{ providers.jira }}"
18+
with:
19+
issue_id: "{{ incident.ticket_id }}"
20+
project_key: "TEST"
21+
board_name: "TEST"
22+
summary: "Update summary of an issue"
23+
description: "Test description"
24+
issue_type: "Task"
25+
custom_fields:
26+
customfield_10696: "10"
27+
customfield_10201: "Critical"

keep/providers/jira_provider/jira_provider.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ def __update_issue(
348348
update["labels"] = [{"set": label} for label in labels]
349349

350350
if custom_fields:
351-
update.update(custom_fields)
351+
# Format custom fields properly for Jira API
352+
for field_name, field_value in custom_fields.items():
353+
update[field_name] = [{"set": field_value}]
352354

353355
request_body = {"update": update}
354356

@@ -437,7 +439,13 @@ def _notify(
437439
components (List[str]): The components of the issue.
438440
custom_fields (dict): The custom fields of the issue.
439441
"""
440-
issue_type = issue_type if issue_type else kwargs.get("issuetype", "Task")
442+
issue_type = (
443+
issue_type
444+
if issue_type
445+
else (
446+
kwargs.get("issuetype", "Task") if isinstance(kwargs, dict) else "Task"
447+
)
448+
)
441449
if labels and isinstance(labels, str):
442450
labels = json.loads(labels.replace("'", '"'))
443451
try:

keep/providers/jiraonprem_provider/jiraonprem_provider.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
from keep.exceptions.provider_exception import ProviderException
1515
from keep.providers.base.base_provider import BaseProvider
1616
from keep.providers.models.provider_config import ProviderConfig, ProviderScope
17+
from keep.validation.fields import HttpsUrl
1718

1819

1920
@pydantic.dataclasses.dataclass
2021
class JiraonpremProviderAuthConfig:
2122
"""Jira On Prem authentication configuration."""
2223

23-
host: pydantic.AnyHttpUrl = dataclasses.field(
24+
host: HttpsUrl = dataclasses.field(
2425
metadata={
2526
"required": True,
2627
"description": "Jira Host",
@@ -366,7 +367,9 @@ def __update_issue(
366367
update["labels"] = [{"set": label} for label in labels]
367368

368369
if custom_fields:
369-
update.update(custom_fields)
370+
# Format custom fields properly for Jira API
371+
for field_name, field_value in custom_fields.items():
372+
update[field_name] = [{"set": field_value}]
370373

371374
request_body = {"update": update}
372375

@@ -497,7 +500,13 @@ def _notify(
497500
Notify jira by creating an issue.
498501
"""
499502
# if the user didn't provider a project_key, try to extract it from the board name
500-
issue_type = issue_type if issue_type else kwargs.get("issuetype", "Task")
503+
issue_type = (
504+
issue_type
505+
if issue_type
506+
else (
507+
kwargs.get("issuetype", "Task") if isinstance(kwargs, dict) else "Task"
508+
)
509+
)
501510
if labels and isinstance(labels, str):
502511
labels = json.loads(labels.replace("'", '"'))
503512
try:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "keep"
3-
version = "0.45.9"
3+
version = "0.45.10"
44
description = "Alerting. for developers, by developers."
55
authors = ["Keep Alerting LTD"]
66
packages = [{include = "keep"}]

0 commit comments

Comments
 (0)