Skip to content

Commit

Permalink
Merge pull request #110 from dann7387/patch-1
Browse files Browse the repository at this point in the history
Workaround for adding an issue to a sprint
  • Loading branch information
ssbarnea committed Aug 4, 2015
2 parents 393f030 + 314b87f commit 0f33f03
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
17 changes: 13 additions & 4 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2673,8 +2673,9 @@ def create_sprint(self, name, board_id, startDate=None, endDate=None):

return Sprint(self._options, self._session, raw=raw_issue_json)

# TODO: broken, this API does not exsit anymore and we need to use
# TODO: broken, this API does not exist anymore and we need to use
# issue.update() to perform this operaiton
# Workaround based on https://answers.atlassian.com/questions/277651/jira-agile-rest-api-example
def add_issues_to_sprint(self, sprint_id, issue_keys):
"""
Add the issues in ``issue_keys`` to the ``sprint_id``. The sprint must
Expand All @@ -2691,10 +2692,18 @@ def add_issues_to_sprint(self, sprint_id, issue_keys):
:param sprint_id: the sprint to add issues to
:param issue_keys: the issues to add to the sprint
"""

# Get the customFieldId for "Sprint"
sprint_field_name = "Sprint"
sprint_field_id = [f['schema']['customId'] for f in self.fields()
if f['name'] == sprint_field_name][0]

data = {}
data['issueKeys'] = issue_keys
url = self._get_url('sprint/%s/issues/add' %
(sprint_id), base=self.AGILE_BASE_URL)
data['idOrKeys'] = issue_keys
data['customFieldId'] = sprint_field_id
data['sprintId'] = sprint_id
data['addToBacklog'] = False
url = self._get_url('sprint/rank', base=self.AGILE_BASE_URL)
r = self._session.put(url, data=json.dumps(data))

def add_issues_to_epic(self, epic_id, issue_keys, ignore_epics=True):
Expand Down
14 changes: 13 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,19 @@ def test_agile(self):
assert s.name == sprint_name
assert s.state == 'FUTURE'

#self.jira.add_issues_to_sprint(s.id, self.issue_1)
self.jira.add_issues_to_sprint(s.id, [self.issue_1])

sprint_field_name = "Sprint"
sprint_field_id = [f['schema']['customId'] for f in self.jira.fields()
if f['name'] == sprint_field_name][0]
sprint_customfield = "customfield_" + str(sprint_field_id)

updated_issue_1 = self.jira.issue(self.issue_1)
serialised_sprint = getattr(updated_issue_1.fields, sprint_customfield)[0]

# Too hard to serialise the sprint object. Performing simple regex match instead.
assert re.search('\[id=' + str(s.id) + ',', serialised_sprint)

#self.jira.add_issues_to_sprint(s.id, self.issue_2)

#self.jira.rank(self.issue_2, self.issue_1)
Expand Down

0 comments on commit 0f33f03

Please sign in to comment.