-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.html
121 lines (102 loc) · 4.53 KB
/
context.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
<html>
<head>
<title>Pull Request Status</title>
<script src="node_modules/vss-web-extension-sdk/lib/VSS.SDK.js"></script>
<style>
h2 {
font-weight: 400;
}
pre {
font-size: 14px;
line-height: 1.3em;
}
</style>
</head>
<body style="padding-left: 20px; padding-top: 20px; overflow-y: auto; background-color: #eee">
<h2>Pull Request Status</h2>
<div id="grid-container"></div>
<script type="text/javascript">
VSS.init({explicitNotifyLoaded: true, usePlatformScripts: true, usePlatformStyles: true })
VSS.ready(function () {
var context = VSS.getWebContext();
var configuration = VSS.getConfiguration();
var repoId = configuration.repositoryId;
var prId = configuration.pullRequestId;
//Used for tab contributions
if (VSS.getContribution().type === "ms.vss-web.tab") {
VSS.register("statusExtension", {
pageTitle: function(state){
return "Pull Request Status";
},
isDisabled: function(state) {
return false;
},
isInvisible: function(state){
return false;
}
});
}
});
VSS.require(["VSS/Service", "TFS/VersionControl/GitRestClient", "VSS/Controls", "VSS/Controls/Grids"],
function (VssService, TfsGitClient, Controls, Grids) {
//Gather the context of the current PR
var configuration = VSS.getConfiguration();
var repoId = configuration.repositoryId;
var prId = configuration.pullRequestId;
var iterations;
//Get the client
var gitClient = VssService.getClient(TfsGitClient.GitHttpClient);
//Get all of the statuses without iterating
gitClient.getPullRequestStatuses(repoId, prId).then(
function(statuses) {
//Initialize the grid
var gridSource = [];
var gridOptions = {
height: "400px",
source: gridSource,
columns: [
{ text: "IterationID", width: 150, index: "id" },
{ text: "Status", width: 150, index: "status" },
{ text: "Name", width: 150, index: "name" },
{ text: "Description", width: 150, index: "description" },
{ text: "URL", width: 150, index: "url" },
]
};
//Create a grid to display the statuses
var grid = Controls.create(Grids.Grid, $("#grid-container"), gridOptions);
//Get the status for each iteration
statuses.forEach( function(status) {
//decode the state enum
var friendlyStatus;
switch(status.state){
case 1:
friendlyStatus = "Pending";
break;
case 2:
friendlyStatus = "Succeeded";
break;
case 3:
friendlyStatus = "Failed";
break;
default:
friendlyStatus = "Error";
}
//add it to the grid source
gridSource.push({
id: status.iterationId,
status: friendlyStatus,
name: status.context.name,
description: status.description,
url: status.targetUrl
});
//Update the grid
grid.setDataSource(gridSource);
});
}
);
VSS.notifyLoadSucceeded();
}
);
</script>
</body>
</html>