Skip to content

Commit

Permalink
Change (add|update)_field_value actions to return issue dict. (#59)
Browse files Browse the repository at this point in the history
Fix update_field_value when field is 'labels'

Signed-off-by: Jeremiah Millay <[email protected]>
  • Loading branch information
floatingstatic authored Aug 15, 2023
1 parent 9477c90 commit 2f4e63b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
12 changes: 12 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions actions/add_field_value.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from lib.base import BaseJiraAction
from lib.formatters import to_issue_dict

__all__ = [
'AddFieldValue'
Expand All @@ -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)
2 changes: 1 addition & 1 deletion actions/lib/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions actions/update_field_value.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from lib.base import BaseJiraAction
from lib.formatters import to_issue_dict

__all__ = [
'UpdateFieldValue'
Expand All @@ -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)
2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords:
- issues
- ticket management
- project management
version: 2.3.1
version: 2.4.0
python_versions:
- "3"
author : StackStorm, Inc.
Expand Down

0 comments on commit 2f4e63b

Please sign in to comment.