-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-times.html
105 lines (91 loc) · 5.65 KB
/
build-times.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
<!DOCTYPE html>
<html>
<head>
<script src="node_modules/vss-web-extension-sdk/lib/VSS.SDK.min.js"></script>
<script type="text/javascript">
VSS.init({
explicitNotifyLoaded: true,
usePlatformStyles: true
});
VSS.require(["TFS/Dashboards/WidgetHelpers", "TFS/Build/RestClient"],
function (WidgetHelpers, TFS_Build_WebApi, TFS_Charts) {
WidgetHelpers.IncludeWidgetStyles();
VSS.register("BuildTimesWidget", function () {
var projectId = VSS.getWebContext().project.id;
var getBuildBuildInfo = function (widgetSettings) {
var settings = JSON.parse(widgetSettings.customSettings.data);
if (!settings || !settings.buildDefinition) {
// Initialize display values
$("#no-build-selected-label").show();
$("#build-times-average").hide();
return WidgetHelpers.WidgetStatusHelper.Success();
}
if (parseInt(settings.buildDefinition) > 0) {
// Get most recent successful build details
// .getBuilds(project, definitions, queues, buildNumber, minFinishTime, maxFinishTime, requestedFor, reasonFilter, statusFilter, resultFilter, tagFilters, properties, type, top, continuationToken, maxBuildsPerDefinition, deletedFilter, queryOrder, branchName)
TFS_Build_WebApi.getClient().getBuilds(projectId, [parseInt(settings.buildDefinition)], null, null, null, null, null, null, "Completed", "PartiallySucceeded,Succeeded", null, null, null, 30, null, null, null, null, null)
.then(function (builds) {
console.debug(builds);
if (builds.length == 0) {
$("#no-build-results").show();
$("#build-times-average").hide();
} else {
var sumBuildTimeSeconds = builds
.map(build => build.finishTime - build.startTime)
.reduce((sum, buildTime) => sum + buildTime, 0) / 1000;
var averageBuildTimeSeconds = sumBuildTimeSeconds
/ builds.length;
console.debug(averageBuildTimeSeconds);
if (averageBuildTimeSeconds < 60) {
$('#build-times-average').text(Math.round(averageBuildTimeSeconds) + 's');
} else {
$('#build-times-average').text((averageBuildTimeSeconds / 60).toFixed(1) + 'm');
}
}
return WidgetHelpers.WidgetStatusHelper.Success();
},
function (error) {
return WidgetHelpers.WidgetStatusHelper.Failure(error.message);
}
);
}
// Get a client to make REST calls
return TFS_Build_WebApi.getClient().getDefinition(settings.buildDefinition, projectId)
.then(function (query) {
// Use the widget helper and return success as Widget Status
return WidgetHelpers.WidgetStatusHelper.Success();
}, function (error) {
// Use the widget helper and return failure as Widget Status
return WidgetHelpers.WidgetStatusHelper.Failure(error.message);
});
}
return {
load: function (widgetSettings) {
// Set title
$("h2.title").text(widgetSettings.name);
// Output diagnostics info to console
console.log('event: load called');
return getBuildBuildInfo(widgetSettings);
},
reload: function (widgetSettings) {
// Set title
$("h2.title").text(widgetSettings.name);
// Output diagnostics info to console
console.log('event: reload called');
return getBuildBuildInfo(widgetSettings);
}
}
});
VSS.notifyLoadSucceeded();
});
</script>
</head>
<body>
<div class="widget">
<h2 class="title">Build times</h2>
<label id="no-build-selected-label" hidden>No build definition selected</label>
<label id="no-build-results" hidden>No successful build results</label>
<div id="build-times-average" class="big-count" title="Average of last 30 succeeding or partially succeeding builds"></div>
</div>
</body>
</html>