DATA CENTER AND SERVER | CLOUD

Create/Update/Get/Delete suspect configuration

Contents


Create suspect configuration


The following script will create a suspect configuration on a give project.

In this example, the script will create a 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 create_suspect(host_url, username, password, project_key, config_name, notify_assignee, notify_reporter,
                   notify_project_lead, user_keys, link_type_ids, use_all_link_types, field, stream, scope):
    """
    This method allows to create suspect configuration on a project
    """

    # The REST API path to allow the creation of suspect configuration for a project
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/{}/suspectconfiguration'.format(project_key)

    # The request body
    json_data = {'configName': config_name, 'notifyAssignee': notify_assignee, 'notifyReporter': notify_reporter,
                 'notifyProjectLead': notify_project_lead, 'userKeys': [user_keys], 'linkTypeIds': [link_type_ids],
                 'useAllLinktypes': use_all_link_types, 'suspectConfigItems': [{'field': field, 'stream': stream}],
                 'scope': scope}

    # Send and return the POST request
    try:
        return requests.post(host_url + path_uri, json=json_data, auth=HTTPBasicAuth(username, password))
    except requests.exceptions.RequestException as e:
        print e
Main
# ['SC'] the project key parameter where the suspect will be configured
# ['SC_Suspect'] suspect configuration name
# [False] true to notify assignee, otherwise false
# [False] true to notify reporter, otherwise false
# [False] true to notify project lead, otherwise false
# ['admin'] List of users to be notified if suspect is triggered
# ['10002'] Define the link types that should be affected
# [False] true if use all link types, otherwise false
# ['assignee']Input the fieldId that trigger a suspect. Add to trigger on any field change.
# ['up'] Define if a change in an issue will trigger suspect to downstream relationships only or in both directions.
# Note: "stream" and "scope" must always have the same value.

response = create_suspect(HOST_URL, USERNAME, PASSWORD, 'SC', 'SC_Suspect', False, False, False, "admin",
                          "10002", False, "assignee", "up", "up")

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


Update suspect configuration


The following script will udpate a suspect configuration on a give project.

In this example, the script will update a 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 update_suspect(host_url, username, password, project_key, suspect_id, config_name, notify_assignee,
                   notify_reporter, notify_project_lead, user_keys, link_type_ids, use_all_link_types,
                   field, stream, scope):
    """
    This method allows to update suspect configuration on a project
    """

    # The REST API path to allow update of suspect configuration for a project
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/{}/suspectconfiguration/{}'.\
        format(project_key, suspect_id)

    # The request body
    json_data = {'configName': config_name, 'notifyAssignee': notify_assignee, 'notifyReporter': notify_reporter,
                 'notifyProjectLead': notify_project_lead, 'userKeys': [user_keys], 'linkTypeIds': [link_type_ids],
                 'useAllLinktypes': use_all_link_types, 'suspectConfigItems': [{'field': field, 'stream': stream}],
                 'scope': scope}
    # Send and return the PUT request
    try:
        return requests.put(host_url + path_uri, json=json_data, auth=HTTPBasicAuth(username, password))
    except requests.exceptions.RequestException as e:
        print e
Main
# ['SC'] the project key parameter where the suspect will be configured
# [17] The suspect configuration id to be updated
# ['SC_Suspect_Update'] suspect configuration name
# [True] true to notify assignee, otherwise false
# [False] true to notify reporter, otherwise false
# [False] true to notify project lead, otherwise false
# ['admin'] List of users to be notified if suspect is triggered
# ['10002'] Define the link types that should be affected
# [False] true if use all link types, otherwise false
# ['assignee']Input the fieldId that trigger a suspect. Add to trigger on any field change.
# ['up'] Define if a change in an issue will trigger suspect to downstream relationships only or in both directions.
# Note: "stream" and "scope" must always have the same value.

response = update_suspect(HOST_URL, USERNAME, PASSWORD, 'SC', 17, 'SC_Suspect_Update', True, False, False, "admin",
                          "10002", False, "assignee", "up", "up")

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


Get all suspect configuration of a project


The following script will get all suspect configuration on a give project.

In this example, the script will get all suspect for project Sand Castle 'SC'.

 Click here to expand...
Function
def get_suspect(host_url, username, password, project_key):
    """
    This method allows to get all suspect configuration on a project
    """

    # The REST API path to get all suspect configuration of a project
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/{}/suspectconfigurations'.format(project_key)

    # Send and return the GET request
    try:
        return requests.get(host_url + path_uri, auth=HTTPBasicAuth(username, password))
    except requests.exceptions.RequestException as e:
        print e
Main
# ['SC'] the project key parameter where all suspect configuration will be fetched

response = get_suspect(HOST_URL, USERNAME, PASSWORD, 'SC')

if response.status_code == 200:
    parsed = json.loads(response.text)
    print json.dumps(parsed, indent=4, sort_keys=True)
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
[
    {
        "configId": 17, 
        "configName": "SC_Suspect_Update", 
        "linkTypeIds": [
            "10002"
        ], 
        "notifyAssignee": true, 
        "notifyProjectLead": false, 
        "notifyReporter": false, 
        "projectId": 10000, 
        "scope": "up", 
        "suspectConfigItems": [
            {
                "field": "assignee", 
                "stream": "up"
            }
        ], 
        "useAllLinktypes": false, 
        "userKeys": [
            "admin"
        ]
    }, 
    {
        "configId": 18, 
        "configName": "SC_Suspect", 
        "linkTypeIds": [
            "10002"
        ], 
        "notifyAssignee": false, 
        "notifyProjectLead": false, 
        "notifyReporter": false, 
        "projectId": 10000, 
        "scope": "up", 
        "suspectConfigItems": [
            {
                "field": "assignee", 
                "stream": "up"
            }
        ], 
        "useAllLinktypes": false, 
        "userKeys": [
            "admin"
        ]
    }
]


Delete suspect configuration


The following script will delete a suspect configuration on a give project.

In this example, the script will delete the suspect configuration with id 17 on project Sand Castle 'SC'.

 Click here to expand...
Function
def del_suspect(host_url, username, password, project_key, suspect_id):
    """
    This method allows to delete suspect configuration on a project
    """

    # The REST API path to delete a suspect configuration
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/{}/suspectconfiguration/{}'.\
        format(project_key, suspect_id)

    # Send and return the DELETE request
    try:
        return requests.delete(host_url + path_uri, auth=HTTPBasicAuth(username, password))
    except requests.exceptions.RequestException as e:
        print e
Main
# ['SC'] the project key parameter where the suspect configuration will be deleted
# [17] The suspect configuration id to be deleted

response = del_suspect(HOST_URL, USERNAME, PASSWORD, 'SC', 17)

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 deleted for SC