Skip to content

Commit 5bc9937

Browse files
committed
fixed read_scan_status.py
1 parent a5a738d commit 5bc9937

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

blackduck/HubRestApi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class HubInstance(object):
111111
from .Versions import ( add_version_as_component, remove_version_as_component )
112112
from .Scans import (
113113
delete_codelocation, delete_unmapped_codelocations, download_project_scans,
114-
get_codelocation_scan_summaries, get_codelocations, get_scan_locations, upload_scan
114+
get_codelocation_scan_summaries, get_codelocations, get_codelocations_internal, get_scan_locations, upload_scan
115115
)
116116
from .Components import (
117117
_get_components_url, find_component_info_for_protex_component, get_component_by_id,

blackduck/Scans.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ def get_codelocations(self, limit=100, unmapped=False, parameters={}):
6363
jsondata['totalCount'] = len(jsondata['items'])
6464
return jsondata
6565

66+
def get_codelocations_internal(self, limit=100, unmapped=False, parameters={}):
67+
parameters['limit'] = limit
68+
paramstring = self._get_parameter_string(parameters)
69+
headers = self.get_headers()
70+
url = self.get_apibase() + "/codelocations" + paramstring
71+
headers['Accept'] = 'application/vnd.blackducksoftware.internal-1+json'
72+
response = requests.get(url, headers=headers, verify = not self.config['insecure'])
73+
jsondata = response.json()
74+
if unmapped:
75+
jsondata['items'] = [s for s in jsondata['items'] if 'mappedProjectVersion' not in s]
76+
jsondata['totalCount'] = len(jsondata['items'])
77+
return jsondata
78+
6679
def get_codelocation_scan_summaries(self, code_location_id = None, code_location_obj = None, limit=100):
6780
'''Retrieve the scans (aka scan summaries) for the given location. You can give either
6881
code_location_id or code_location_obj. If both are supplied, precedence is to use code_location_obj

examples/read_scan_status.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
batch_size=500
1515

16-
codelocations = hub.get_codelocations(limit=1, offset=1)
16+
codelocations = hub.get_codelocations(limit=1)
1717
total_count = codelocations['totalCount']
1818

1919
status = {"in_progress": 0, "unstarted": 0, "completed": 0, "error": 0, "skipped": 0}
2020

2121
for i in status.keys():
22-
codelocations = hub.get_codelocations_internal(limit=1, offset=0, parameters={"filter": "codeLocationStatus:{}".format(i)})
22+
codelocations = hub.get_codelocations_internal(limit=1, parameters={"filter": "codeLocationStatus:{}".format(i)})
2323
status[i] = codelocations['totalCount']
2424

2525
print (total_count, status)

0 commit comments

Comments
 (0)