Skip to content

Commit fce9787

Browse files
authored
[JIRA] Issues Move to Sprint (#524)
* Added the `add_issues_to_sprint` functionality within jira * Placed relevant docs in docs/jira.rst * Added example at jira-add-issues-to-sprint.py Closes #486
1 parent 8299ade commit fce9787

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

atlassian/jira.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,15 @@ def create_issue(self, fields, update_history=False):
10341034
"""
10351035
Creates an issue or a sub-task from a JSON representation
10361036
:param fields: JSON data
1037+
mandatory keys are issuetype, summary and project
10371038
:param update_history: bool (if true then the user's project history is updated)
10381039
:return:
1040+
example:
1041+
fields = dict(summary='Into The Night',
1042+
project = dict(key='APA'),
1043+
issuetype = dict(name='Story')
1044+
)
1045+
jira.create_issue(fields=fields)
10391046
"""
10401047
url = 'rest/api/2/issue'
10411048
data = {'fields': fields}
@@ -2479,6 +2486,24 @@ def create_sprint(self, name, board_id, start_date=None, end_date=None, goal=Non
24792486
data['goal'] = goal
24802487
return self.post(url, data=data)
24812488

2489+
def add_issues_to_sprint(self, sprint_id, issues):
2490+
"""
2491+
Adding Issue(s) to Sprint
2492+
:param sprint_id: int/str: The ID for the Sprint.
2493+
Sprint to be Active or Open only.
2494+
eg. 104
2495+
:param issues: list: List of Issue Keys
2496+
eg. ['APA-1', 'APA-2']
2497+
:return: Dictionary of response received from the API
2498+
2499+
https://docs.atlassian.com/jira-software/REST/8.9.0/#agile/1.0/sprint-moveIssuesToSprint
2500+
"""
2501+
if not isinstance(issues, list):
2502+
raise ValueError("`issues` param should be List of Issue Keys")
2503+
url = '/rest/agile/1.0/sprint/{sprint_id}/issue'.format(sprint_id=sprint_id)
2504+
data = dict(issues=issues)
2505+
return self.post(url, data=data)
2506+
24822507
def get_all_sprint(self, board_id, state=None, start=0, limit=50):
24832508
"""
24842509
Returns all sprints from a board, for a given board Id.

docs/jira.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ Manage Boards
219219
# Rename sprint
220220
jira.rename_sprint(sprint_id, name, start_date, end_date)
221221
222+
# Add/Move Issues to sprint
223+
jira.add_issues_to_sprint(sprint_id, issues_list)
224+
222225
223226
Attachments actions
224227
-------------------
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from atlassian import Jira
2+
3+
# Issues can be 1 or more
4+
issues_lst = ['APA-1', 'APA-2']
5+
sprint_id = 103
6+
7+
jira = Jira(
8+
url='http://localhost:8080',
9+
username='admin',
10+
password='admin')
11+
12+
resp = jira.add_issues_to_sprint(
13+
sprint_id=sprint_id,
14+
issues=issues_lst
15+
)

0 commit comments

Comments
 (0)