DATA CENTER AND SERVER | CLOUD
Add/Move/Remove issues
- Franklin Gabito
Add an existing issue to the root folder
The following script will add an existing issue to the root folder. In this example, the script will add issue 'SC-196' to the root folder of the project 'SC'
Function
def add_issue_to_root(host_url, username, password, project_key, issue_key): """ This method is used to add an existing issue to root folder Template parameters: [project_key] the project key Query parameter [issue_key] the key of the issue to be added """ # The REST API path to add an issue on the root folder path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/tree/' + project_key + '/rootissue?' # The field-value pair/s that will be added to the query string issue_key_field_value = 'issuekey=' + issue_key # The query string to be added to the URI query_string = issue_key_field_value # Send a POST request to add an issue on the root folder of Requirements # Return the result of the POST request try: return requests.post(host_url + path_uri + query_string, auth=HTTPBasicAuth(username, password)) except requests.exceptions.RequestException as e: print e
Main
# ['SC'] project key parameter where the issue will be added # ['SC-196'] issue key parameter for the issue that will be added # Store the result of the POST request to [response] response = add_issue_to_root(HOST_URL, USERNAME, PASSWORD, 'SC', 'SC-196') # Check response if baseline is created if response.status_code == 200: # Get the value of the JSON response and print in a readable JSON format # json dumps formats the JSON string in readable format json_object = json.loads(response.text) print json.dumps(json_object, indent=4) else: print 'Error code: ', response.status_code print response.text
Refer to Constant variable for information of the following constant variable: [HOST_URL, USERNAME, PASSWORD]
Output
{ "childReqs": { "childReq": [] }, "issueId": 26238, "description_html": "", "rootfolderdescription": "", "url": "https://addontest.sandbox.easesolutions.com/browse/SC-196", "icon_url": "https://addontest.sandbox.easesolutions.com/images/icons/issuetypes/story.svg", "summary": "As a team, we can finish the sprint by clicking the cog icon next to the sprint name above the \"To Do\" column then selecting \"Complete Sprint\" >> Try closing this sprint now", "key": "SC-196", "issueType": "Story", "position": 7, "id": 8785 }
Add an existing issue to a given folder
The following script will add an existing issue to a given folder. In this example, the script will add issue 'SC-196' to the folder '213' of the project 'SC'
Function
def add_issue_to_folder(host_url, username, password, project_key, folder_id, issue_key): """ This method is used to add an existing issue to a given folder Template parameters: [project_key] the project key [folder_id] the folder ID Query parameter [issue_key] the key of the issue to be associated """ # The REST API path to add an issue on the specified folder path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/tree/' + \ project_key + '/folderissue/' + folder_id + '?' # The field-value pair/s that will be added to the query string issue_key_field_value = 'issuekey=' + issue_key # The query string to be added to the URI query_string = issue_key_field_value # Send a POST request to add an existing issue to a given folder # Return the result of the POST request try: return requests.post(host_url + path_uri + query_string, auth=HTTPBasicAuth(username, password)) except requests.exceptions.RequestException as e: print e
Main
def main(): # ['SC'] project key parameter where the issue will be added # ['213'] folder id parameter of the folder where the issue will be added # ['SC-196'] issue key parameter of the issue that will be added # Store the result of the POST request to [response] response = add_issue_to_folder(HOST_URL, USERNAME, PASSWORD, 'SC', '213', 'SC-196') # Check response if baseline is created if response.status_code == 200: # Get the value of the JSON response and print in a readable JSON format # json dumps formats the JSON string in readable format json_object = json.loads(response.text) print json.dumps(json_object, indent=4) else: print 'Error code: ', response.status_code print response.text
Refer to Constant variable for information of the following constant variable: [HOST_URL, USERNAME, PASSWORD]
Output
{ "childReqs": { "childReq": [] }, "issueId": 26238, "description_html": "", "rootfolderdescription": "", "url": "https://addontest.sandbox.easesolutions.com/browse/SC-196", "icon_url": "https://addontest.sandbox.easesolutions.com/images/icons/issuetypes/story.svg", "summary": "As a team, we can finish the sprint by clicking the cog icon next to the sprint name above the \"To Do\" column then selecting \"Complete Sprint\" >> Try closing this sprint now", "key": "SC-196", "issueType": "Story", "position": 1, "id": 8786 }
Move an existing issue association to a new folder
The following script will move an issue from one tree folder to another one of the same project. In this example, the script will move issue 'SC-196' from folder '302' to '303'
Function
def move_issue(host_url, username, password, project_key, issue_key, source_folder, target_folder): """ This method is used to move an existing issue association to a new folder Template parameters: [project_key] the project key Query parameter [issue_key] the key of the issue to be moved [source_folder] the ID of the source folder [target_folder] the ID of the destination folder """ # The REST API path to move an existing issue association to a new folder path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/tree/' + project_key + '/moveissue?' # The field-value pair/s for the query string of the URI source_folder_field_value = 'from=' + source_folder target_folder_field_value = '&to=' + target_folder issue_key_field_value = '&issuekey=' + issue_key # The query string to be added to the URI query_string = source_folder_field_value + target_folder_field_value + issue_key_field_value # Send a POST request to move an existing issue association to the target folder # Return the result of the POST request try: return requests.post(host_url + path_uri + query_string, auth=HTTPBasicAuth(username, password)) except requests.exceptions.RequestException as e: print e
Main
# ['SC'] project key parameter where the issue will be moved # ['SC-196'] issue key parameter of the issue that will be moved # [source_folder] the folder id parameter of the source folder # [target_folder] the folder id parameter of the target folder # Store the result of the POST request to [response] response = move_issue(HOST_URL, USERNAME, PASSWORD, 'SC', 'SC-196', '302', '303') # Check response if issue associated is moved to another folder if response.status_code == 200: print 'Issue association successfully moved to the target folder' else: print 'Error code: ', response.status_code print response.text
Refer to Constant variable for information of the following constant variable: [HOST_URL, USERNAME, PASSWORD]
Output
Issue association successfully moved to the target folder
Remove issue from root folder
The following script will remove an issue from the root folder of a given project. In this example, issue 'SC-196' will be remove from the project root
Function
def remove_issue_from_root(host_url, username, password, project_key, issue_key): """ This method is used to delete an existing issue from the root folder Template parameters: [project_key] the project key Query parameter [issue_key] the key of the issue to be deleted """ # The REST API path to delete an issue on project root path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/tree/' + project_key + '/rootissue?' # The field-value pair/s that will be added to the query string issue_key_field_value = 'issuekey=' + issue_key # The query string to be added to the URI query_string = issue_key_field_value # Send a DELETE request to delete an issue in the Requirements # Return the result of the DELETE request try: return requests.delete(host_url + path_uri + query_string, auth=HTTPBasicAuth(username, password)) except requests.exceptions.RequestException as e: print e
Main
# ['SC'] project key parameter where the issue will be deleted # ['SC-196'] issue key parameter of the issue where the association will be removed # Store the result of the POST request to [response] response = remove_issue_from_root(HOST_URL, USERNAME, PASSWORD, 'SC', 'SC-196') # Check response if issue association was removed if response.status_code == 200: print "Issue association removed from root folder" else: print 'Error code: ', response.status_code print response.text
Refer to Constant variable for information of the following constant variable: [HOST_URL, USERNAME, PASSWORD]
Output
Issue association removed from root folder
Remove an issue association from a given folder
The following script will remove an issue from a specified tree folder of a given project. In this example, the script will remove issue 'SC-196' on the folder with the id of '301'.
Function
def remove_issue_from_folder(host_url, username, password, project_key, folder_id, issue_key): """ This method is used to remove an issue association from a given folder Template parameters: [project_key] the project key [folder_id] the folder ID Query parameter [issue_key] the key of the issue whose association should be removed """ # The REST API path to remove an issue association from a given folder path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/tree/' + \ project_key + '/folderissue/' + folder_id + '?' # The field-value pair/s for the query string of the URI issue_key_field_value = 'issuekey=' + issue_key # The query string to be added to the URI query_string = issue_key_field_value # Send a DELETE request to remove an issue association from a given folder # Return the result of the DELETE request try: return requests.delete(host_url + path_uri + query_string, auth=HTTPBasicAuth(username, password)) except requests.exceptions.RequestException as e: print e
Main
# ['SC'] project key parameter where the issue will be deleted # ['301'] folder id parameter where the issue is associated # ['SC-196'] issue key parameter of the issue where the association will be removed # Store the result of the POST request to [response] response = remove_issue_from_folder(HOST_URL, USERNAME, PASSWORD, 'SC', '301', 'SC-196') # Check response if issue association was removed from the specified folder if response.status_code == 200: print "Issue association removed from folder" else: print 'Error code: ', response.status_code print response.text
Refer to Constant variable for information of the following constant variable: [HOST_URL, USERNAME, PASSWORD]
Output
Issue association removed from folder