Skip to content

Commit

Permalink
ADD support for creating subtasks in JIRA
Browse files Browse the repository at this point in the history
* Add support for creating Sub Task

Fixes #26

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>

* Fix parent field

According to JIRA API 'parent' field must be object with 'key' or 'id'.

* Added subtasks docs

* Fix _prepare_ticket_fields()
  • Loading branch information
fpob authored and dmranck committed May 15, 2018
1 parent bf9bbb4 commit 9497eb7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
26 changes: 26 additions & 0 deletions read-the-docs/source/JIRA.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ particular JIRA instance during ticket creation:
parent='KEY-XX'
customfield_XXXXX='Custom field text'
While creating a Sub task, parent ticket id is required, otherwise create()
method fails with KeyError - "Parent field is required while creating a Sub
Task"

edit()
------

Expand Down Expand Up @@ -256,3 +260,25 @@ Update existing JIRA tickets
# Close Requests session.
ticket.close_requests_session()
Create a Sub-Task inside existing JIRA ticket
---------------------------------------------

.. code:: python
from ticketutil.jira import JiraTicket
# Create a ticket object and pass the url and project key in as strings.
t = JiraTicket(<jira_url>,
<project_key>,
auth=('username', 'password'))
# Create a ticket and perform some common ticketing operations.
t.create(summary='Sub Task summary',
description='Sub Task description',
assignee='username',
type='Sub-task',
parent='existing_ticket_id')
t.change_status('In Progress')
# Close Requests session.
t.close_requests_session()
9 changes: 8 additions & 1 deletion ticketutil/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,20 @@ def _prepare_ticket_fields(fields):
Makes sure each key value pair in the fields dictionary is in the correct form.
:param fields: Ticket fields.
:return: fields: Ticket fields in the correct form for the ticketing tool.
:raises: KeyError: While creating Sub Task, if parent is not provided.
"""
if fields['type'] == 'Sub-task' and 'parent' not in fields:
raise KeyError("Parent field is required while creating a Sub Task")

for key, value in fields.items():
if key in ['priority', 'assignee', 'reporter', 'parent']:
if key in ['priority', 'assignee', 'reporter']:
fields[key] = {'name': value}
if key in ['parent']:
fields[key] = {'key': value}
if key == 'type':
fields['issuetype'] = {'name': value}
fields.pop('type')

return fields


Expand Down

0 comments on commit 9497eb7

Please sign in to comment.