Skip to content

Commit 86d8232

Browse files
authored
Added get_version and move_version (#1333)
Used for fetching a specific version if the id is known and used to reposition the versions without having to go through the awful UI to do so.
1 parent 6651796 commit 86d8232

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

atlassian/jira.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,15 @@ def get_project_versions_paginated(
24752475
url = "{base_url}/{key}/version".format(base_url=base_url, key=key)
24762476
return self.get(url, params=params)
24772477

2478+
def get_version(self, version):
2479+
"""
2480+
Returns a specific version with the given id.
2481+
:param version: The id of the version to return
2482+
"""
2483+
base_url = self.resource_url("version")
2484+
url = "{base_url}/{version}".format(base_url=base_url, version=version)
2485+
return self.get(url)
2486+
24782487
def add_version(
24792488
self,
24802489
project_key,
@@ -2550,6 +2559,26 @@ def update_version(
25502559
url = "{base_url}/{version}".format(base_url=base_url, version=version)
25512560
return self.put(url, data=payload)
25522561

2562+
def move_version(self, version, after=None, position=None):
2563+
"""
2564+
Reposition a project version
2565+
:param version: The version id to move
2566+
:param after: The version id to move version below
2567+
:param position: A position to move the version to
2568+
"""
2569+
base_url = self.resource_url("version")
2570+
url = "{base_url}/{version}/move".format(base_url=base_url, version=version)
2571+
if after is None and position is None:
2572+
raise ValueError('Must provide one of `after` or `position`')
2573+
if after:
2574+
after_url = self.get_version(after).get('self')
2575+
return self.post(url, data={'after': after_url})
2576+
if position:
2577+
position = position.lower().capitalize()
2578+
if position not in ['Earlier', 'Later', 'First', 'Last']:
2579+
raise ValueError('position must be one of Earlier, Later, First, or Last. Got {pos}'.format(pos=position))
2580+
return self.post(url, data={'position': position})
2581+
25532582
def get_project_roles(self, project_key):
25542583
"""
25552584
Provide associated project roles

0 commit comments

Comments
 (0)