You can use the Coverity on Polaris API to triage your project issue status with the
following cURL, Python, and Java API examples.
cURL: Get the Triage Status for a Project
- Get the project given a name or ID, including its branches; then extract the project and branch IDs.
$ curl -X GET \ 'https://subdomain.cop.blackduck.com/api/common/ v0/projects?filter[project][name][$eq]={{project-name}}&include[project] []=branches&page[limit]=&page[offset]=0' \ -H 'Accept: application/vnd.api+json' \ -H 'Authorization: Bearer {JWT}' - Get the revisions for the branch, and extract a revision ID.
$ curl -X GET \ 'https://subdomain.cop.blackduck.com/api/ common/v0/revisions?filter[revision][branch][id][$eq]={{branchid}}&page[limit]=10&page[offset]=0' \ -H 'Accept: application/vnd.api+json' \ -H 'Authorization: Bearer {JWT}' - Get the run for the project and revision, and extract the run ID.
$ curl -X GET \ 'https://subdomain.cop.blackduck.com/api/common/v0/ runs?filter[run][project][id][$eq]={{project-id}}&filter[run][revision][id] [$eq]={{revision-id}}&page[limit]=10&page[offset]=0' \ -H 'Accept: application/vnd.api+json' \ -H 'Authorization: Bearer {JWT}' - Get a list of issues for the project and run, and extract an issue key.
$ curl -X GET \ 'https://subdomain.cop.blackduck.com/api/query/v1/issues? project-id={{project-id}}&run-id[]={{run-id}}&page[limit]=10&page[offset]=0' \ -H 'Accept: application/vnd.api+json' \ -H 'Authorization: Bearer {JWT}' - Get the triage for each of the issue keys for the project.
$ curl -X GET \ 'https://subdomain.cop.blackduck.com/api/ triage-query/v0/triage-current?filter[triage-current][project-id] [$eq]={{project-id}}&filter[triage-current][issue-key][$eq]={{issuekey}}&page[limit]=10&page[offset]=0' \ -H 'Accept: application/vnd.api+json' \ -H 'Authorization: Bearer {JWT}'
Python: Get the Triage Status for a Project
import json
from http.client import HTTPSConnection, HTTPResponse
polaris = HTTPSConnection('subdomain.cop.blackduck.com')
jwt = ''
json_api_resource_headers = {
'Content-Type': "application/vnd.api+json",
'Accept': "application/vnd.api+json",
'Authorization': 'Bearer ' + jwt
}
project_name = ''
# step 1 get the project given a name (or ID), including its branches. Extract the project and branch IDs
polaris.request("GET", f"/api/common/v0/projects?filter[project][name][$eq]={project_name}&include[project][]=branches&page[limit]=1&page[offset]=0",
None, json_api_resource_headers)
projects_response = polaris.getresponse()
print(f'Project: \n{json.dumps(projects_response.read(), indent=4)}')
project_id = ''
branch_id = ''
# step 2 get the revisions for the branch, extract a revision ID
polaris.request("GET", f"/api/common/v0/revisions?filter[revision][branch][id][$eq]={branch_id}&page[limit]=1&page[offset]=0",
None, json_api_resource_headers)
revisions_response = polaris.getresponse()
print(f'Latest revision: \n{json.dumps(revisions_response.read(), indent=4)}')
revision_id = ''
# step 3 get the run for the project and revision, extract the run ID
polaris.request("GET", f"/api/common/v0/runs?filter[run][project][id][$eq]={project_id}&filter[run][revision][id][$eq]={revision_id}&page[limit]=1&page[offset]=0",
None, json_api_resource_headers)
runs_response = polaris.getresponse()
print(f'Latest run: \n{json.dumps(runs_response.read(), indent=4)}')
run_id = ''
# step 4 get a list of issues for the project and run, extract an issue key
polaris.request("GET", f"/api/query/v1/issues?project-id={project_id}&run-id[]={run_id}&page[limit]=1&page[offset]=0",
None, json_api_resource_headers)
issues_response = polaris.getresponse()
print(f'First listed issue: \n{json.dumps(issues_response.read(), indent=4)}')
issue_key = ''
# step 5 get the triage for each of the issue keys for the project
triages_response = polaris.getresponse()
polaris.request("GET", f"/api/triage-query/v0/triage-current?filter[triage-current][project-id][$eq]={project_id}&filter[triage-current][issue-key][$eq]={issue_key}&page[limit]=1&page[offset]=0",
None, json_api_resource_headers)
print(f'Issue triage: \n{json.dumps(triages_response.read(), indent=4)}')
Java: Get the Triage Status for a Project
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
final static String JSON_API_STRING = "application/vnd.api+json";
String jwt = "";
String host = "https://subdomain.cop.blackduck.com";
OkHttpClient client = new OkHttpClient();
String projectName = "";
// step 1 get the project given a name (or ID), including its branches. Extract the project and branch IDs
Request getProjectWithIncludedBranchesRequest = new Request.Builder()
.url(host+"/api/common/v0/projects?filter[project][name][$eq]="+projectName+"&include[project][]=branches&page[limit]=1&page[offset]=0")
.get()
.addHeader("Accept", JSON_API_STRING)
.addHeader("Authorization", "Bearer "+jwt)
.build();
Response getProjectWithIncludedBranchesResponse = client.newCall(getProjectWithIncludedBranchesRequest).execute();
String projectId = "";
String branchId = "";
// step 2 get the revisions for the branch, extract a revision ID
Request getRevisionsRequest = new Request.Builder()
.url(host+"/api/common/v0/revisions?filter[revision][branch][id][$eq]="+branchId+"&page[limit]=1&page[offset]=0")
.get()
.addHeader("Accept", JSON_API_STRING)
.addHeader("Authorization", "Bearer "+jwt)
.build();
Response getRevisionsResponse = client.newCall(getRevisionsRequest).execute();
String revisionId = "";
// step 3 get the run for the project and revision, extract the run ID
Request getRunsRequest = new Request.Builder()
.url(host+"/api/common/v0/runs?filter[run][project][id][$eq]="+projectId+"&filter[run][revision][id][$eq]="+revisionId+"&page[limit]=1&page[offset]=0")
.get()
.addHeader("Accept", JSON_API_STRING)
.addHeader("Authorization", "Bearer "+jwt)
.build();
Response getRunsResponse = client.newCall(getRunsRequest).execute();
String runId = "";
// step 4 get a list of issues for the project and run, extract an issue key
Request getProjectRunIssuesRequest = new Request.Builder()
.url(host+"/api/query/v1/issues?project-id="+projectId+"&run-id[]="+runId+"&page[limit]=1&page[offset]=0")
.get()
.addHeader("Accept", JSON_API_STRING)
.addHeader("Authorization", "Bearer "+jwt)
.build();
Response getProjectRunIssuesResponse = client.newCall(getProjectRunIssuesRequest).execute();
String issueKey = "";
// step 5 get the triage for each of the issue keys for the project
Request getIssueTriageRequest = new Request.Builder()
.url(host+"/api/triage-query/v0/triage-current?filter[triage-current][project-id][$eq]="+projectId+"&filter[triage-current][issue-key][$eq]="+issueKey+"&page[limit]=1&page[offset]=0")
.get()
.addHeader("Accept", JSON_API_STRING)
.addHeader("Authorization", "Bearer "+jwt)
.build();
Response getIssueTriageResponse = client.newCall(getIssueTriageRequest).execute();