Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Panel

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.

Expand
Function
Code Block
languagepy
themeConfluence
linenumberstrue
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
Code Block
languagepy
themeConfluence
linenumberstrue
    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)
Code Block
languagejs
themeConfluence
{"id":"1","name":"GUI Coverage"}
Output (Error)
Panel

Status
colourRed
title403
 Your license is invalid or has expired

Status
colourRed
title403/401
 Incompatible Jira Version

Status
colourRed
title500400
 No permission to create public/private views in Coverage View

Status
colourRed
title500400
 Name is invalid

Status
colourRed
title500400
 Json data is invalid

Status
colourRed
title500400
 Filter with name ''{0}'' already exists.

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



...