From 2f4e63b993ae8e8ecb0f3c40678f3147075fabd7 Mon Sep 17 00:00:00 2001 From: Jeremiah Millay <5504449+floatingstatic@users.noreply.github.com> Date: Tue, 15 Aug 2023 11:37:27 -0400 Subject: [PATCH] Change (add|update)_field_value actions to return issue dict. (#59) Fix update_field_value when field is 'labels' Signed-off-by: Jeremiah Millay --- CHANGES.md | 12 ++++++++++++ actions/add_field_value.py | 4 ++-- actions/lib/formatters.py | 2 +- actions/update_field_value.py | 6 ++++-- pack.yaml | 2 +- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 34847f3..331dab8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,17 @@ # Change Log +## 2.4.0 + +- `add_field_value` and `update_field_value` actions now return a dictionary representation of the issue being modified. Previously these actions would return +only the `labels` field if it exists as an attribute. This addresses [#53](https://github.com/StackStorm-Exchange/stackstorm-jira/issues/53) but is also beneficial for displaying other field values (inclusive of `labels`) that may have been updated. + +- Fix for [#54](https://github.com/StackStorm-Exchange/stackstorm-jira/issues/54) which prevents callers of the `update_field_value` action from updating `labels` which must be passed as a list via the api. As labels cannot contain spaces we split +the `value` field of this action on whitespace in the case where `field` == `"labels"`. Example invocation: + +``` +st2 action execute jira.update_field_value issue_key=NETOPS-1 field=labels value='Label1 Label2' +``` + ## 2.3.1 - Update `README.md` to include `api_token` as an auth method diff --git a/actions/add_field_value.py b/actions/add_field_value.py index c2befef..300d6e8 100644 --- a/actions/add_field_value.py +++ b/actions/add_field_value.py @@ -1,4 +1,5 @@ from lib.base import BaseJiraAction +from lib.formatters import to_issue_dict __all__ = [ 'AddFieldValue' @@ -9,5 +10,4 @@ class AddFieldValue(BaseJiraAction): def run(self, issue_key, field, value): issue = self._client.issue(issue_key) issue.add_field_value(field, value) - result = issue.fields.labels - return result + return to_issue_dict(issue) diff --git a/actions/lib/formatters.py b/actions/lib/formatters.py index 58694bc..9a27168 100644 --- a/actions/lib/formatters.py +++ b/actions/lib/formatters.py @@ -35,7 +35,7 @@ def to_issue_dict(issue, include_comments=False, include_attachments=False, 'description': issue.fields.description, 'status': issue.fields.status.name, 'resolution': resolution, - 'labels': issue.fields.labels, + 'labels': issue.fields.labels if hasattr(issue.fields, 'labels') else [], 'reporter': reporter, 'assignee': assignee, 'created_at': issue.fields.created, diff --git a/actions/update_field_value.py b/actions/update_field_value.py index 984b7b0..4576daa 100644 --- a/actions/update_field_value.py +++ b/actions/update_field_value.py @@ -1,4 +1,5 @@ from lib.base import BaseJiraAction +from lib.formatters import to_issue_dict __all__ = [ 'UpdateFieldValue' @@ -8,6 +9,7 @@ class UpdateFieldValue(BaseJiraAction): def run(self, issue_key, field, value, notify): issue = self._client.issue(issue_key) + if field == "labels": + value = value.split() issue.update(fields={field: value}, notify=notify) - result = issue.fields.labels - return result + return to_issue_dict(issue) diff --git a/pack.yaml b/pack.yaml index d0faf4b..a886264 100644 --- a/pack.yaml +++ b/pack.yaml @@ -6,7 +6,7 @@ keywords: - issues - ticket management - project management -version: 2.3.1 +version: 2.4.0 python_versions: - "3" author : StackStorm, Inc.