Skip to content

Commit 17c116d

Browse files
author
Glenn Snyder
committed
adding example to retrieve components having snippet matches
1 parent 57a42cb commit 17c116d

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import json
5+
import logging
6+
import sys
7+
8+
from blackduck.HubRestApi import HubInstance, object_id
9+
10+
parser = argparse.ArgumentParser("Retrieve components that have snippet matches")
11+
parser.add_argument("project_name")
12+
parser.add_argument("version")
13+
parser.add_argument("-u", "--unconfirmed", action='store_true', help="Use this option to list all the components have un-confirmed snippet matches. Without this option only components with confirmed snippet matches will be included.")
14+
15+
args = parser.parse_args()
16+
17+
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', stream=sys.stderr, level=logging.DEBUG)
18+
logging.getLogger("requests").setLevel(logging.WARNING)
19+
logging.getLogger("urllib3").setLevel(logging.WARNING)
20+
21+
hub = HubInstance()
22+
23+
version = hub.get_project_version_by_name(args.project_name, args.version)
24+
25+
project_id = version['_meta']['href'].split("/")[-3]
26+
version_id = object_id(version)
27+
28+
url = version['_meta']['href'] + "/components?filter=bomMatchType:snippet"
29+
if args.unconfirmed:
30+
url = url + "&filter=bomMatchReviewStatus:not_reviewed"
31+
32+
response = hub.execute_get(url)
33+
34+
components = response.json().get('items', [])
35+
36+
for component in components:
37+
matched_files_url = hub.get_link(component, "matched-files")
38+
response = hub.execute_get(matched_files_url)
39+
component['matched-files'] = response.json().get('items', [])
40+
41+
print(json.dumps(components))

0 commit comments

Comments
 (0)