Trigger a requirements reuse


The following script will trigger a requirements reuse. Source and target may be in different projects.

In this example, the GUI Requirements structure will be reuse on the project Sand Castle 2.

Function
def reuse(host_url, username, password, source_folder, target_folder, rule_name):
    """
    This method trigger a requirements reuse. Source and target may be in different projects.
    Query parameters:
    [source_folder] is the the source folder for reuse (e.g. Requirements Plugin/Implementation)
    [target_folder] is the the target folder for the reuse (e.g. Requirements Plugin/Features/Baseline/Permissions)
    [rule_name] is the the name of a reuse rule (e.g. "rule 27")
    """

    # The REST API path to reuse a requirement
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/tree/reuse?'

    # The field-value pair/s for the query string of the URI
    source_folder_field_value = 'sourceFolder=' + source_folder
    target_folder_field_value = '&targetFolder=' + target_folder
    rule_name_field_value = '&ruleName=' + rule_name

    # The query string to be added to the URI
    query_string = source_folder_field_value + target_folder_field_value + rule_name_field_value

    # Send a POST request to reuse 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
# ['Sand Castle/GUI Requirements'] source path parameter for the requirement to reuse
# ['Sand Castle 2/'] target path parameter where the requirement will be reuse
# ['Reuse folder structure'] rule name parameter for the rule to use for the reuse
# Store the result of the POST request to [response]
response = reuse(HOST_URL, USERNAME, PASSWORD, 'Sand Castle/GUI Requirements',
                 'Sand Castle 2/', 'Reuse folder structure')

# Check response if requirement is reuse
if response.status_code == 200:
    print response.text
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
Reuse Success