-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot.html
259 lines (212 loc) · 11.7 KB
/
snapshot.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link data-name="vs/editor/editor.main" rel="stylesheet"
href="node_modules/monaco-editor/min/vs/editor/editor.main.css">
<script src='https://code.jquery.com/jquery-1.11.3.min.js'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.0/moment.min.js" rossorigin="anonymous"></script>
<script src="lib/VSS.SDK.min.js"></script>
<style>
body {
background-color: rgb(0, 67, 117);
color: white;
margin: 10px;
font-family: "Segoe UI VSS (Regular)","-apple-system",BlinkMacSystemFont,"Segoe UI",sans-serif;
}
</style>
</head>
<body>
<div>
<input type="date" id="from" />
<input type="date" id="to" />
<input type="button" value="refresh" onclick="fetchWorkItems();"/>
<div id="result_count" style="display: inline;">loading ⌛</div>
<div id="disclaimer" style="float: right;">🍄experimental devops extention / camous</div>
</div>
<div id="monaco" style="width:100%;height:700px;border:1px solid grey">></div>
<script type="text/javascript">
var diffEditor = null;
$('#from').val(new Date(new Date().getTime() - 2* 24 * 60 * 60 * 1000).toISOString().slice(0,10));
$('#to').val(new Date().toISOString().slice(0,10));
var fields = [
'System.WorkItemType',
'System.State',
'System.Reason',
'System.CreatedDate',
'System.CreatedBy',
'System.ChangedDate',
'System.ChangedBy',
'System.CommentCount',
'System.Title',
'System.Description',
'Microsoft.VSTS.Scheduling.StoryPoints',
'System.AssignedTo',
'System.AreaPath',
'System.IterationPath',
'System.Tags'
];
VSS.init(
{
moduleLoaderConfig : {
paths : {
'vs' : 'node_modules/monaco-editor/min/vs'
}
}
}
);
fetchWorkItems();
function fetchWorkItems(){
$('#result_count').html('loading ⌛');
VSS.require(["vs/editor/editor.main","VSS/Service", "TFS/WorkItemTracking/RestClient"], function (monaco, VSS_Service, TFS_Wit_WebApi) {
var projectId = VSS.getWebContext().project.id;
var witClient = VSS_Service.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient);
var from = new Date($('#from').val());
var to = new Date($('#to').val());
// load workitems ID
witClient.queryByWiql({ query : 'Select [System.Id], [System.ChangedDate] FROM WorkItems Where [System.TeamProject] = @project AND [System.ChangedDate] > \'' + convertDate(from) + '\' AND [System.ChangedDate] <= \'' + convertDate(to) + '\''}, projectId).then(result => {
// only query full items if we have some workitems
if(result.workItems.length > 0){
var ids = result.workItems.flatMap(o => o.id);
var promises = [];
var promisescomments = [];
// REST API limited to 200 workitems at once
chunk(ids, 200).forEach(ids_chunk=> {
promises.push(
new Promise(resolve => {
witClient.getWorkItems(ids_chunk, fields).then((result_to) => {
// retrieve comments
result_to.filter(o=> o.fields['System.CommentCount'] > 0).forEach(o=>{
promisescomments.push(new Promise(resolve => {
witClient.getComments(projectId, o.id).then(data => {
resolve(data);
});
}));
});
// we remove ids which weren't existing at 'from' date for now querying them (otherwise devops generate HTTP 400)
result_to.forEach(o=> {
if(new Date(o.fields['System.CreatedDate']) > from){
ids_chunk.splice(ids_chunk.indexOf(o.id), 1);
}
})
if(ids.length == 0){
resolve({
from : [],
to : result_to
});
} else {
witClient.getWorkItems(ids_chunk, fields,from).then((result_from) => {
resolve({
from : result_from,
to : result_to
});
});
}
});
}));
});
Promise.all(promises).then( results => {
// concatenate results (if workitems count > 200)
var baseline = { from : [], to : []};
results.filter(o=> o.from != undefined && o.to != undefined).forEach(o => {
baseline.from = baseline.from.concat(o.from);
baseline.to = baseline.to.concat(o.to);
});
Promise.all(promisescomments).then( commentresults => {
// inject comments in snapshot, in results, we should have one result with to & from, other are comments
commentresults.forEach(o=> {
// all array rows are for the same workitem, grabbing the workitem from first
var workItemId = o.comments[0].workItemId;
baseline.to.find(o=> o.id == workItemId).comments = o.comments;
// we inject in 'from' snapshot all comments which were already created at that moment
var existingcomments = o.comments.filter(o=> o.modifiedDate < from);
if(existingcomments.length > 0){
baseline.from.find(o=> o.id == workItemId).comments = existingcomments;
}
});
if(diffEditor == null){
diffEditor = monaco.editor.createDiffEditor(document.getElementById("monaco"), {
renderSideBySide: false
});
}
var left = monaco.editor.createModel(stringifyWorkItems(baseline.from), "plaintext");
var right = monaco.editor.createModel(stringifyWorkItems(baseline.to), "plaintext");
diffEditor.setModel({
original: left,
modified: right
});
$('#result_count').html(result.workItems.length + ' item' + (result.workItems.length > 1 ? 's' : ''));
});
}).catch(ex=>{
console.error(ex);
});
} else {
$('#result_count').html('no changes');
}
});
});
}
function stringifyWorkItems(workitems){
var result = '';
workitems.forEach(o=> {
result += '🔵 ' + o.fields['System.Title'] + '\n';
result += '\t📐' + o.fields['System.WorkItemType'] + ' #' + o.id + ' (' + o.fields['System.State'] + ') \t' + o.url.replace('/_apis/wit/workItems/', '/_workitems/edit/') + '\n';
var createdon = moment(o.fields['System.CreatedDate']);
var modifiedon = moment(o.fields['System.ChangedDate'])
result += '\t📆 modified : ' + modifiedon.format('dddd D MMM') + ' (' + modifiedon.fromNow()+ ')' + '\t created ' + createdon.fromNow()+ '\n';
result += '\t💡' + o.fields['System.AreaPath'] + '\t' + o.fields['System.IterationPath'] + '\n\n';
var descriptiondiv = document.createElement("div");
// we have to remove in pure regex img tag before, otherwise innerHTML call would download them all
var descriptionraw = o.fields['System.Description'] || '';
var descriptionraw = descriptionraw.replace(/<img .*?>/g,'');
descriptiondiv.innerHTML = descriptionraw;
// remove some markdown default fields
if(descriptiondiv.querySelector('#__mdStyle') != null)
descriptiondiv.querySelector('#__mdStyle').remove();
if(descriptiondiv.querySelector('#__md') != null)
descriptiondiv.querySelector('#__md').remove();
var description = descriptiondiv.innerText || '';
// split with return line description by 80 chars
result += splitter('\t', description, 80).join('\n')+ '\n';
if(o.comments != undefined){
result += "\n\t💬 comments\n";
o.comments.forEach(o=> {
var modifiedon = moment(o.modifiedDate);
result += '\t\t◽' + o.modifiedBy.displayName + ' on ' + modifiedon.format('dddd D MMM') + ' (' + modifiedon.fromNow() + ')\n';
var commentdiv = document.createElement("div");
o.text = o.text.replace(/<img .*?>/g,''); // strip img before using div, otherwise they would be downloaded
commentdiv.innerHTML = o.text || '';
var comment = commentdiv.innerText || '';
result += splitter('\t\t', comment, 80).join('\n')+ '\n\n';
});
}
result += '\n\n';
});
return result;
}
function convertDate(date){
var formateddate = ("0" + (date.getMonth() + 1)).slice(-2) + '/' + ("0" + date.getDate()).slice(-2) + '/' + date.getFullYear().toString().slice(-2);
return formateddate;
}
function splitter(front, str, l){
var strs = [];
while(str.length > l){
var pos = str.substring(0, l).lastIndexOf(' ');
pos = pos <= 0 ? l : pos;
strs.push(front + str.substring(0, pos));
var i = str.indexOf(' ', pos)+1;
if(i < pos || i > pos+l)
i = pos;
str = str.substring(i);
}
strs.push(front + str);
return strs;
}
function chunk(arr, chunkSize) {
var R = [];
for (var i=0,len=arr.length; i<len; i+=chunkSize)
R.push(arr.slice(i,i+chunkSize));
return R;
}
</script>
</body>
</html>