Skip to content

Commit

Permalink
New action 'get_issue_links' (#69)
Browse files Browse the repository at this point in the history
* New action get_issue_links

* overarching get_issue action can call get_issue_links

* added get_issue_links to README

* add get_issue_links to formatters and adjust priority

* bump pack version

* fixing formatting

---------

Co-authored-by: mjtice <[email protected]>
  • Loading branch information
mjtice and mjtice committed Nov 2, 2023
1 parent 8643af4 commit c3de69a
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 2.6.0

- Add new ``jira.get_issue_links`` action

- Evaluate if an issue has a priority set before attempting to get the priority

## 2.5.1

- Improve handling of `priority` field in update_field_value action to address [#65]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ The sensor monitors for new tickets and sends a trigger into the system whenever
* ``get_issue`` - Retrieve information about a particular JIRA issue.
* ``get_issue_attachments`` - Retrieve attachments for a particular JIRA issue.
* ``get_issue_comments`` - Retrieve comments for a particular JIRA issue.
* ``get_issue_links`` - Retrieve linked issues for a particular JIRA issue.
* ``link_issue`` - Link one JIRA issue to another JIRA issue.
* ``search_issues`` - Search JIRA issues with a JQL query.
* ``transition_issue`` - Do a transition on a JIRA issue / ticket.
Expand Down
6 changes: 4 additions & 2 deletions actions/get_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

class GetJiraIssueAction(BaseJiraAction):
def run(self, issue_key, include_comments=False, include_attachments=False,
include_customfields=False, include_components=False, include_subtasks=False):
include_customfields=False, include_components=False, include_subtasks=False,
include_links=False):
issue = self._client.issue(issue_key)
result = to_issue_dict(issue=issue, include_comments=include_comments,
include_attachments=include_attachments,
include_customfields=include_customfields,
include_components=include_components,
include_subtasks=include_subtasks)
include_subtasks=include_subtasks,
include_links=include_links)
return result
5 changes: 5 additions & 0 deletions actions/get_issue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ parameters:
description: True to include custom fields.
required: true
default: false
include_links:
type: boolean
description: True to include linked issues.
required: true
default: false
14 changes: 14 additions & 0 deletions actions/get_issue_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from lib.base import BaseJiraAction
from lib.formatters import to_links_dict

__all__ = [
'GetJiraIssueLinksAction'
]


class GetJiraIssueLinksAction(BaseJiraAction):
def run(self, issue_key):
issue = self._client.issue(issue_key)

result = [to_links_dict(i) for i in issue.fields.issuelinks]
return result
11 changes: 11 additions & 0 deletions actions/get_issue_links.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: get_issue_links
runner_type: python-script
description: Retrieve links for a particular JIRA issue.
enabled: true
entry_point: get_issue_links.py
parameters:
issue_key:
type: string
description: Issue key (e.g. PROJECT-1000).
required: true
25 changes: 23 additions & 2 deletions actions/lib/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@


def to_issue_dict(issue, include_comments=False, include_attachments=False,
include_customfields=False, include_components=False, include_subtasks=False):
include_customfields=False, include_components=False, include_subtasks=False,
include_links=False):
"""
:rtype: ``dict``
"""
Expand Down Expand Up @@ -34,7 +35,7 @@ def to_issue_dict(issue, include_comments=False, include_attachments=False,
'summary': issue.fields.summary,
'description': issue.fields.description,
'status': issue.fields.status.name,
'priority': issue.fields.priority.name,
'priority': issue.fields.priority.name if hasattr(issue.fields, 'priority') else None,
'resolution': resolution,
'labels': issue.fields.labels if hasattr(issue.fields, 'labels') else [],
'reporter': reporter,
Expand Down Expand Up @@ -71,6 +72,9 @@ def to_issue_dict(issue, include_comments=False, include_attachments=False,
if include_subtasks:
result['subtasks'] = [to_subtask_dict(s) for s in issue.fields.subtasks]

if include_links:
result['links'] = [to_links_dict(i) for i in issue.fields.issuelinks]

return result


Expand Down Expand Up @@ -121,6 +125,23 @@ def to_attachment_dict(attachment):
return result


def to_links_dict(issue):
"""
:rtype: ``dict``
"""
result = {
'id': issue.raw.get('id'),
'key': issue.raw.get('outwardIssue', issue.raw.get('inwardIssue')).get('key'),
'summary': issue.raw.get('outwardIssue', issue.raw.get('inwardIssue'))
.get('fields').get('summary'),
'status': issue.raw.get('outwardIssue', issue.raw.get('inwardIssue')).get('fields')
.get('status').get('name'),
'type': issue.raw.get('type').get('outward') if issue.raw.get('outwardIssue')
else issue.raw.get('type').get('inward'),
}
return result


def fmt_field_value(field, value):
"""
Returns specific field values in formats required by JIRA
Expand Down
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.5.1
version: 2.6.0
python_versions:
- "3"
author : StackStorm, Inc.
Expand Down

0 comments on commit c3de69a

Please sign in to comment.