DATA CENTER AND SERVER | CLOUD

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Contents


Trigger saving a suspect configuration


The following script will update the projects suspect configuration.

In this example, the script will configure the suspect for project Sand Castle 'SC'. Refer to the parameters in Main for the settings that will be set in the suspect.

 Click here to expand...
Function
def configure_suspect(host_url, username, password, project_key, fields_list, link_type_id, scope, notify_assignee,
                      notify_reporter, notify_project_lead, notify_user_list):
    """
    This method is used to configure the Requirements Suspect Configuration
    Query parameters:
    [project_key] the project key
    Query parameters:
    [fields_list] fields that trigger a suspect
    [link_type_id] link types that should be affected if a field change
    [scope] define if a change in an issue will trigger suspect. Accepts 'both' or 'downstream'
    [notify_assignee] notify assignee if set to true
    [notify_reporter] notify reporter if set to true
    [notify_project_lead] notify project lead if set to true
    [notify_user_list] the jira users to be notified
    """

    # The REST API path to configure the Requirements Suspect Configuration
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/' + project_key + '/suspectconfiguration?'

    # The query string to be added to the URI
    query_string = ""

    # The field-value pair/s for the query string of the URI
    if fields_list:
        query_string += 'fieldList=' + fields_list
    if link_type_id:
        if query_string:
            query_string += '&linkTypeIds=' + link_type_id
        else:
            query_string += 'linkTypeIds=' + link_type_id
    if scope:
        if query_string:
            query_string += '&scope=' + scope
        else:
            query_string += 'scope=' + scope
    if notify_assignee:
        if query_string:
            query_string += '&notifyAssignee=' + notify_assignee
        else:
            query_string += 'notifyAssignee=' + notify_assignee
    if notify_reporter:
        if query_string:
            query_string += '&notifyReporter=' + notify_reporter
        else:
            query_string += 'notifyReporter=' + notify_reporter
    if notify_project_lead:
        if query_string:
            query_string += '&notifyProjectLead=' + notify_project_lead
        else:
            query_string += 'notifyProjectLead=' + notify_project_lead
    if notify_user_list:
        if query_string:
            query_string += '&notifyUserList=' + notify_user_list
        else:
            query_string += 'notifyUserList=' + notify_user_list

    # Send a PUT request to configure the Requirements Suspect Configuration
    # Return the result of the PUT request
    try:
        return requests.put(host_url + path_uri + query_string, auth=HTTPBasicAuth(username, password))
    except requests.exceptions.RequestException as e:
        print e
Main
# ['SC'] the project key parameter where the suspect will be configured
# ['summary'] the field parameter for the fields list
# ['-1'] the id parameter to select all link types
# ['down'] The scope parameter of the configuration
# ['true'] boolean parameter for Assignee notification
# ['true'] boolean parameter for reporter notification
# ['true'] boolean parameter for project lead notification
# ['myUser'] users parameter for the users to be notified.
# Store the result of the POST request to [response]
response = configure_suspect(HOST_URL, USERNAME, PASSWORD, 'SC', 'summary', '-1', 'down', 'true',
                             'true', 'true', 'myUser')

# Check response if Suspect is configured
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
Suspect Configuration saved for SC
  • No labels