Skip to content

Commit 9dbf4a7

Browse files
authored
Merge pull request #28 from sinnershiki/feature/transition_by_name
To be able to use status name to transition issue
2 parents 44a7966 + f283ebf commit 9dbf4a7

6 files changed

Lines changed: 56 additions & 2 deletions

File tree

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 0.11.0
4+
5+
- Add new ``jira.transition_issue_by_name`` action
6+
37
## 0.10.1
48

59
- Updated PyYAML to 4.2b4 for CVE-2017-18342

actions/run.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ class ActionManager(BaseJiraAction):
1010

1111
def run(self, action, **kwargs):
1212
try:
13+
if action == 'transition_issue_by_name':
14+
action = 'transition_issue'
15+
kwargs['transition'] = self.transition_name_to_id(**kwargs)
16+
del kwargs['transition_name']
1317
return (True, getattr(self._client, action)(**kwargs))
1418
except JIRAError as e:
1519
return (False, str(e))
1620
except AttributeError as e:
1721
return (False, 'Action "%s" is not implemented' % action)
22+
23+
def transition_name_to_id(self, issue, transition_name):
24+
transitions = self._client.transitions(issue)
25+
res = list(filter(lambda x: x.get("name") == transition_name,
26+
transitions))
27+
if bool(res):
28+
return res[0].get("id")
29+
return None

actions/transition_issue.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ parameters:
1111
required: true
1212
transition:
1313
type: string
14-
description: Name of transition (e.g. Close, Start Progress, etc).
14+
description: ID of transition (e.g. 11, 21, etc).
1515
required: true
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: transition_issue_by_name
3+
runner_type: python-script
4+
description: Do a transition on a JIRA issue / ticket.
5+
enabled: true
6+
entry_point: run.py
7+
parameters:
8+
action:
9+
default: transition_issue_by_name
10+
immutable: true
11+
type: string
12+
issue:
13+
type: string
14+
description: Issue key (e.g. PROJECT-1000).
15+
required: true
16+
transition_name:
17+
type: string
18+
description: Name of transition (e.g. Close, Start Progress, etc).
19+
required: true

pack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords:
66
- issues
77
- ticket management
88
- project management
9-
version: 0.10.1
9+
version: 0.11.0
1010
python_versions:
1111
- "2"
1212
- "3"

tests/test_action_run.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,22 @@ def side_effect(*args, **kwargs):
4444
(is_success, value) = action.run(action='method')
4545
self.assertFalse(is_success)
4646
self.assertEqual(value, "JiraError HTTP error message\n\t")
47+
48+
@mock.patch('lib.base.JIRA')
49+
def test_transition_name_to_id(self, mock_jira):
50+
action = self.get_action_instance(self.full_auth_passwd_config)
51+
52+
def side_effect(*args, **kwargs):
53+
return [{'id': '11', 'name': 'Start'},
54+
{'id': '21', 'name': 'Doing'},
55+
{'id': '31', 'name': 'Close'}]
56+
57+
action._client.transitions.side_effect = side_effect
58+
59+
kwargs = {'issue': 'ISSUE-XX', 'transition_name': 'Doing'}
60+
transition_id = action.transition_name_to_id(**kwargs)
61+
self.assertEqual(transition_id, '21')
62+
63+
kwargs = {'issue': 'ISSUE-XX', 'transition_name': 'Done'}
64+
transition_id = action.transition_name_to_id(**kwargs)
65+
self.assertEqual(transition_id, None)

0 commit comments

Comments
 (0)