-
Notifications
You must be signed in to change notification settings - Fork 0
/
htmlReportTab.html
152 lines (136 loc) · 6.92 KB
/
htmlReportTab.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html>
<head>
<!-- <script src="node_modules/vss-web-extension-sdk/lib/VSS.SDK.min.js"></script> -->
<script src="lib/VSS.SDK.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js"></script>
<!-- <script src="https://cdn.vsassets.io/v/M165_20210910.4/_scripts/TFS/min/VSS.SDK.min.js"></script> -->
<style>
body {
font-family: Arial, sans-serif; /* Change the font family */
background-color: #f4f4f4; /* Background color of the page */
}
#htmlContent {
max-height: 500px;
overflow: auto;
padding: 10px;
border: 1px solid #ccc;
margin: 10px 10px 30px 10px; /* Added space at the bottom */
font-size: 0.9em;
background-color: #fff; /* Background color of the table */
color: #333; /* Text color */
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); /* Optional: adds shadow for depth */
}
table {
border-collapse: collapse; /* Optional: for table styling */
width: 100%; /* Optional: for table styling */
}
th, td {
text-align: left; /* Optional: aligns text to the left in table cells */
padding: 8px; /* Optional: adds padding inside table cells */
}
tr:nth-child(even) {
background-color: #f2f2f2; /* Optional: zebra striping for table rows */
}
th {
background-color: #4CAF50; /* Header background color */
color: white; /* Header text color */
}
</style>
</head>
<body>
<div id="htmlContent">Loading...</div>
<script>
VSS.init({
explicitNotifyLoaded: true,
usePlatformScripts: true,
usePlatformStyles: true
});
VSS.ready(function () {
var buildLogicExecuted = false;
var vssConfig = VSS.getConfiguration();
vssConfig.onBuildChanged(function (build) {
if (!buildLogicExecuted && build && build.id) {
var buildId = build.id;
var projectId = VSS.getWebContext().project.id;
console.log("Build ID: " + buildId);
buildLogicExecuted = true; // Set the flag to true to avoid re-execution
// VSS.require(["TFS/Build/BuildRestClient"], function (_BuildClient) {
// var client = _BuildClient.getClient();
// client.getArtifacts(projectId, buildId).then(function (artifacts) {
// // process the artifacts
// var htmlReportArtifact = artifacts.find(artifact => artifact.name === "htmlReport");
// if (htmlReportArtifact) {
// // Fetch file output.html from htmlReport artifact
// client.getArtifactContentZip(projectId, buildId, htmlReportArtifact.name, "output.html").then(function (content) {
// // Convert the binary content to a text string and display it
// var htmlContent = new TextDecoder('utf-8').decode(new Uint8Array(content));
// document.getElementById("htmlContent").innerHTML = htmlContent;
// VSS.notifyLoadSucceeded();
// }).catch(function (err) {
// console.error('Error fetching artifact content', err);
// });
// } else {
// console.error('HTML report artifact not found');
// }
// }).catch(function (err) {
// console.error(err);
// document.getElementById("htmlContent").innerText = "Error loading report: " + err.message;
// VSS.notifyLoadFailed(err.message);
// });
// });
VSS.getAccessToken().then(function (token) {
const accessToken = token.token;
const appId = token.appId;
console.log("app_id")
console.log(appId)
console.log("token")
console.log(accessToken)
buildArtifacts = fetchBuildArtifacts(projectId, buildId, accessToken);
}).catch(function (err) {
console.error(err);
document.getElementById("htmlContent").innerText = "Error loading report: " + err.message;
VSS.notifyLoadFailed(err.message);
});
}
function fetchBuildArtifacts(projectId, buildId, accessToken) {
const apiUrl = `https://dev.azure.com/${VSS.getWebContext().collection.name}/${projectId}/_apis/build/builds/${buildId}/artifacts?artifactName=html_report&api-version=7.1&%24format=zip`;
fetch(apiUrl, {
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`
},
redirect: 'follow' // Ensure redirects are followed
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
console.log("response")
console.log(response)
return response.blob(); // Get the response as a blob
})
.then(blob => {
console.log("blob")
console.log(blob)
var jszip = new JSZip();
return jszip.loadAsync(blob); // Load the blob into JSZip
})
.then(zip => {
console.log("zip")
console.log(zip)
// Assuming the file is located at 'html_report/output.html' in the zip
return zip.file("html_report/output.html").async("string");
})
.then(htmlContent => {
// Use the HTML content as needed
document.getElementById("htmlContent").innerHTML = htmlContent;
})
.catch(error => console.error('Error:', error));
}
});
VSS.notifyLoadSucceeded(); // Notify that the extension load is complete
});
</script>
</body>
</html>