22import xml .etree .ElementTree as ET
33
44import os , sys
5+ import json
56
67from pprint import pprint
78
@@ -53,10 +54,12 @@ def parse_cobertura(xml_path):
5354 annotations .append ({
5455 "title" : "Coverage" ,
5556 "annotation_type" : "COVERAGE" ,
56- "summary" : "PASS" , # summary,
57+ "summary" : summary ,
5758 "severity" : "LOW" ,
58- "path" : "CurrentRelease/cpp/database.cpp" ,
59- "line" : 5
59+ "path" : file_path ,
60+ "line" : num ,
61+ "external_id" : "{}#{}" .format (file_path ,num )
62+
6063 })
6164 return annotations
6265
@@ -127,13 +130,11 @@ def create_code_coverage_report_in_bitbucket(filename, workspace, repo_slug, com
127130 "title" : "Coverage Report" ,
128131 "details" : "VectorCAST coverage results." ,
129132 "report_type" : "COVERAGE" ,
130- "result" : overall_coverage ,
131133 "reporter" : version ,
132134 "data" : data
133135 }
134136
135137 if verbose :
136- import json
137138 print (json .dumps (report_payload , indent = 2 ))
138139
139140 resp = requests .put (
@@ -145,8 +146,7 @@ def create_code_coverage_report_in_bitbucket(filename, workspace, repo_slug, com
145146 )
146147
147148 print ("Report creation status:" , resp .status_code )
148- if verbose :
149- print ("Response:" , resp .text )
149+ print ("Response:" , resp .text )
150150
151151
152152# Send annotations in batches of 100
@@ -160,7 +160,10 @@ def send_code_coverage_annoations(annotations, workspace, repo_slug, commit_hash
160160 headers = {"Accept" : "application/json" , "Content-Type" : "application/json" },
161161
162162 for i in range (0 , len (annotations ), 100 ):
163- batch = annotations [i :i + 100 ]
163+ batch = annotations [i :i + 100 ]
164+
165+ if verbose :
166+ print (json .dumps (annotations [1 :10 ]
164167
165168 resp = requests .post (
166169 url ,
@@ -169,7 +172,8 @@ def send_code_coverage_annoations(annotations, workspace, repo_slug, commit_hash
169172 headers = {"Accept" : "application/json" , "Content-Type" : "application/json" }
170173 )
171174
172- print (f"Batch { i // 100 + 1 } response:" , resp .status_code , resp .text )
175+ if verbose :
176+ print (f"Batch { i // 100 + 1 } response:" , resp .status_code , resp .text )
173177
174178
175179def run (filename , minimum_passing_coverage , verbose ):
0 commit comments