diff --git a/atlassian/jira.py b/atlassian/jira.py index 2a3d22e97..d26e68a18 100644 --- a/atlassian/jira.py +++ b/atlassian/jira.py @@ -2526,6 +2526,15 @@ def get_project_versions_paginated( url = "{base_url}/{key}/version".format(base_url=base_url, key=key) return self.get(url, params=params) + def get_version(self, version): + """ + Returns a specific version with the given id. + :param version: The id of the version to return + """ + base_url = self.resource_url("version") + url = "{base_url}/{version}".format(base_url=base_url, version=version) + return self.get(url) + def add_version( self, project_key, @@ -2601,6 +2610,28 @@ def update_version( url = "{base_url}/{version}".format(base_url=base_url, version=version) return self.put(url, data=payload) + def move_version(self, version, after=None, position=None): + """ + Reposition a project version + :param version: The version id to move + :param after: The version id to move version below + :param position: A position to move the version to + """ + base_url = self.resource_url("version") + url = "{base_url}/{version}/move".format(base_url=base_url, version=version) + if after is None and position is None: + raise ValueError("Must provide one of `after` or `position`") + if after: + after_url = self.get_version(after).get("self") + return self.post(url, data={"after": after_url}) + if position: + position = position.lower().capitalize() + if position not in ["Earlier", "Later", "First", "Last"]: + raise ValueError( + "position must be one of Earlier, Later, First, or Last. Got {pos}".format(pos=position) + ) + return self.post(url, data={"position": position}) + def get_project_roles(self, project_key): """ Provide associated project roles