Versions Compared

Key

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


Panel
titleContents

Table of Contents
maxLevel2
minLevel2

...

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_keyid, filter_name, is_public, column_data, columnsdisplay_fields):
    """
    This method trigger the creation of a coverage view
    Template parameters:
    [project_keyid] the project the view to be created
    Query parameters:
    [filter_name] the name parameter of the view
    [is_public] the boolean parameter for the visibility of the view
    [columnscolumn_data] an array parameter of objects composecomposed of name,column data
	[display_fields] the display type ("filter", "jql", or "issue types"), filter, and link typesfields for the view
    """

    # The REST API path to trigger the creation of a coverage view
    path_uri = '/rest/com.easesolutions.jira.plugins.requirementscoverage/1.0/coveragefilter/saveFilter'
+
project_key + '/createcoverageview?'
	# The request body
    #json_data The field-value pair/s for the query string of the URI= {'projectId': project_id,
         name_field_value = 'name=' + name    'name': is_public_field_value = '&isPublic=' +filter_name,
				 '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'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 + query_string, json=json_data, auth=HTTPBasicAuth(username, password))
    except requests.exceptions.RequestException as e:
        print e
Main
Code Block
languagepy
themeConfluence
linenumberstrue
# ['SC']    project_id key= parameter"10000"
where view will be createdfilter_name #= ['"GUI Coverage']"
the name parameter of theis_public 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"]}]'= "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, 'SC'project_id, 'GUI Coverage', 'true', column)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
languagetextjs
themeConfluence
View GUI Coverage has been successfully created{"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
title500
 No permission to create public/private views in Coverage View

Status
colourRed
title500
 Name is invalid

Status
colourRed
title500
 Json data is invalid

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

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