Create coverage view (since 4.0.0)


The following script will trigger the creation of a coverage view. In this example, a coverage view for the GUI requirements will be created.

Function
def create_coverage_view(host_url, username, password, project_id, filter_name, is_public, column_data, display_fields):
    """
    This method trigger the creation of a coverage view
    Template parameters:
    [project_id] the project the view to be created
    [filter_name] the name parameter of the view
    [is_public] the boolean parameter for the visibility of the view
    [column_data] an parameter of objects composed of column data
	[display_fields] the display fields for the view
    """

    # The REST API path to trigger the creation of a coverage view
    path_uri = '/rest/com.easesolutions.jira.plugins.coverage/1.0/filter/saveFilter'

	# The request body
    json_data = {'projectId': project_id,
                 'name': filter_name,
				 'isPublic': is_public,
				 'columnFilterJsonObject': column_data,
				 'addedFieldsJsonArray': display_fields}

    # Send a POST request to trigger the creation of a coverage view
    # Return the result of 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
    project_id = "10000"
    filter_name = "GUI Coverage"
    is_public = "true"

    columns = '{"label":"Level 1","jiraJql":"","jiraFilterId":"","linkTypes":[{"id":"-1","directions":{"in":true,"out":true}}],"currentIssueTypes":["-1"],"projects":["10000,PA,Project A","10002,PB,Project B"],"fromLevel":-1}, ' \
	'{"label":"Level 2","jiraJql":"","jiraFilterId":"10004","linkTypes":[{"id":"-1","directions":{"in":true,"out":true}}],"currentIssueTypes":[],"projects":["10000,PA,Project A"],"fromLevel":0}, ' \
	'{"label":"Level 3","jiraJql":"assignee IS NOT EMPTY","jiraFilterId":"","linkTypes":[{"id":"10001","directions":{"in":false,"out":true}}],"currentIssueTypes":[],"projects":["10000,PA,Project A"],"fromLevel":1}'
    column_data = '{"columns":[' + columns + '],"projectId":' + project_id + ',"fields":[],"folderIssueKeys":[],"filterId":0,"folderId":0,"folderName":"","fromColumn":0,"isFiltered":false}'
	
    display_fields = '["issuetype","issuekey","status","priority","summary","assignee","reporter"]'

    # Store the result of the POST request to [response]
    response = create_coverage_view(HOST_URL, USERNAME, PASSWORD, project_id, filter_name, is_public, column_data, display_fields)

    # Check response if coverage view is created
    if response.status_code == 201:
        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 (Success)
{"id":"1","name":"GUI Coverage"}
Output (Error)

 Your license is invalid or has expired

 Incompatible Jira Version

 No permission to create public/private views in Coverage View

 Name is invalid

 Json data is invalid

 Filter with name ''{0}'' already exists.

 Project is invalid or hasn't been assigned to the Coverage View plugin




Create coverage view


The following script will trigger the creation of a coverage view. In this example, a coverage view for the GUI requirements will be created.

Function
def create_coverage_view(host_url, username, password, project_key, name, is_public, columns):
    """
    This method trigger the creation of a coverage view
    Template parameters:
    [project_key] the project the view to be created
    Query parameters:
    [name] the name parameter of the view
    [is_public] the boolean parameter for the visibility of the view
    [columns] an array parameter of objects compose of name,
    type ("filter", "jql", or "issue types"), filter, and link types
    """
 
    # The REST API path to trigger the creation of a coverage view
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/coverage/' + project_key + '/createcoverageview?'
 
    # The field-value pair/s for the query string of the URI
    name_field_value = 'name=' + name
    is_public_field_value = '&isPublic=' + is_public
    columns_field_value = '&columns=' + columns
 
    # The query string to be added to the URI
    query_string = name_field_value + is_public_field_value + columns_field_value
 
    # Send a POST request to trigger the creation of a coverage view
    # 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 view will be created
# ['GUI Coverage'] the name parameter of the coverage
# ['true'] boolean parameter of the visibility of the view
# ['column'] the column parameter of the view that will be created
# an array of objects compose of name, type ("filter", "jql", or "issue types"), filter, and link types
column = '[{"name":"Column 1","type":"jql","filter":"issuetype in (bug, improvement)","linkTypes":[]},' \
         '{"name":"Column 2","type":"jql","filter":"issuetype = change","linkTypes":["relates to"]}]'
 
# Store the result of the POST request to [response]
response = create_coverage_view(HOST_URL, USERNAME, PASSWORD, 'SC', 'GUI Coverage', 'true', column)
 
# Check response if coverage view is created
if response.status_code == 201:
    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

View GUI Coverage has been successfully created