3
3
4
4
// @ts -check
5
5
6
- import { TryGetHTMLLinkNameAndUrlForArtifactLink } from " ./ArtifactLinkToURL" ;
7
- import { gFieldTypeEnum , gWorkItemRESTClient } from " ./Globals" ;
8
- import { EscapeHtml , FormatDate , GetIdentityAvatarHtml , GetIdentityName , RemoveStyle } from " ./Utils" ;
6
+ import { TryGetHTMLLinkNameAndUrlForArtifactLink } from ' ./ArtifactLinkToURL' ;
7
+ import { gWorkItemRESTClient } from ' ./Globals' ;
8
+ import { EscapeHtml , FormatDate , GetIdentityAvatarHtml , GetIdentityName , RemoveStyle } from ' ./Utils' ;
9
9
// @ts -ignore
10
10
import * as htmldiff from 'node-htmldiff' ;
11
11
12
+ // An enum that holds the known field types. E.g. FieldTypeEnum.Html === 4.
13
+ // It is basically https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-api/fieldtype,
14
+ // except that this documentation is incorrect (it shows the wrong numerical ids). (Apparently, the enum 'FieldType'
15
+ // exists several times in the API with different definitions, and the tool that creates the documentation cannot handle it?)
16
+ // The correct one is this:
17
+ // https://github.com/microsoft/azure-devops-node-api/blob/fa534aef7d79ab4a30ae2b8823654795b6eed1aa/api/interfaces/WorkItemTrackingInterfaces.ts#L460
18
+ import { FieldType as FieldTypeEnum } from 'azure-devops-extension-api/WorkItemTracking' ;
19
+
20
+
12
21
13
22
export async function GetTableInfosForEachRevisionUpdate ( revisionUpdates , fieldsPropertiesMap , currentProjectName )
14
23
{
@@ -243,7 +252,7 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
243
252
}
244
253
245
254
if ( fieldReferenceName === 'Microsoft.VSTS.TCM.Steps' ) {
246
- // The steps of a test case show up as a field of type 'gFieldTypeEnum .Html', which is lie. It does not contain valid html that
255
+ // The steps of a test case show up as a field of type 'FieldTypeEnum .Html', which is lie. It does not contain valid html that
247
256
// a browser can display. It seems to be simply XML, with each individual step description being (escaped) html.
248
257
// TODO: Can we still show a meaningful proper diff?
249
258
// https://devblogs.microsoft.com/devops/how-to-use-test-step-using-rest-client-helper/
@@ -254,7 +263,7 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
254
263
else if ( fieldReferenceName === 'Microsoft.VSTS.TCM.Parameters' ) {
255
264
// This field is used in 'shared parameter set' work items, which are work items that can be referenced by test case items.
256
265
// https://learn.microsoft.com/en-us/azure/devops/test/repeat-test-with-different-data?view=azure-devops#share-parameters-between-test-cases
257
- // The field type is reported as 'gFieldTypeEnum .Html', although in reality it is some general XML. For example:
266
+ // The field type is reported as 'FieldTypeEnum .Html', although in reality it is some general XML. For example:
258
267
// "<parameterSet><paramNames><param>someVar</param><param>var</param></paramNames><paramData lastId=\"1\"><dataRow id=\"1\"><kvp key=\"someVar\" value=\"test value\"/><kvp key=\"var\" value=\"another value\"/></dataRow></paramData></parameterSet>"
259
268
return '(Showing the diff of a shared parameter set is not supported.)' ;
260
269
}
@@ -265,11 +274,11 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
265
274
return '(Showing the diff of parameter values is not supported.)' ;
266
275
}
267
276
268
- // Azure DevOps (at least 2019) reports identities (e.g. the 'System.CreatedBy' field) as 'gFieldTypeEnum .String', but the 'isIdentity' flag is set.
277
+ // Azure DevOps (at least 2019) reports identities (e.g. the 'System.CreatedBy' field) as 'FieldTypeEnum .String', but the 'isIdentity' flag is set.
269
278
// An identity is probably an 'IdentityReference': https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-api/identityreference
270
279
let fieldType = fieldsPropertiesMap ?. [ fieldReferenceName ] ?. type ;
271
280
if ( fieldsPropertiesMap ?. [ fieldReferenceName ] ?. isIdentity ) {
272
- fieldType = gFieldTypeEnum . Identity ;
281
+ fieldType = FieldTypeEnum . Identity ;
273
282
}
274
283
// Note for picklists: It seems that they are used only for user-added fields. They appear as combo boxes.
275
284
// Similar to identities, picklists are also identified via an additional flag in the 'WorkItemField' interface. So PicklistString,
@@ -279,7 +288,7 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
279
288
// simply treat picklists as a string/integer/double.
280
289
281
290
switch ( fieldType ) {
282
- case gFieldTypeEnum . Html :
291
+ case FieldTypeEnum . Html :
283
292
return DiffHtmlText ( value . oldValue , value . newValue ) ;
284
293
285
294
// 'History' means the comments. Unfortunately, they are quite special: When a user adds a new comment, it shows
@@ -290,11 +299,11 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
290
299
// => We actually filter out the 'System.History' entry somewhere else. I think that apart from 'System.History',
291
300
// no other field can use the 'History' field type. Hence, this code here is probably dead. We have dedicated REST
292
301
// API requests somewhere else to get the history of comments.
293
- case gFieldTypeEnum . History :
302
+ case FieldTypeEnum . History :
294
303
return value . hasOwnProperty ( 'newValue' ) ? `<ins class="diffCls">${ RemoveStyle ( value . newValue ) } </ins>` : '' ;
295
304
296
- case gFieldTypeEnum . String :
297
- case gFieldTypeEnum . PlainText :
305
+ case FieldTypeEnum . String :
306
+ case FieldTypeEnum . PlainText :
298
307
{
299
308
// We simply feed htmldiff the values with escaped special characters, meaning that htmldiff should not see any HTML elements.
300
309
// Using a different diff-library (jsdiff or diff-match-patch) is not worth the additional dependency, since the only work item
@@ -309,27 +318,27 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
309
318
return diff ;
310
319
}
311
320
312
- case gFieldTypeEnum . Integer :
313
- case gFieldTypeEnum . PicklistInteger : // See note above: Shouldn't appear, but if it does, can be treated as integer.
314
- case gFieldTypeEnum . Double :
315
- case gFieldTypeEnum . PicklistDouble : // See note above: Shouldn't appear, but if it does, can be treated as double.
316
- case gFieldTypeEnum . PicklistString : // See note above: Shouldn't appear, but if it does, can be treated as string.
317
- case gFieldTypeEnum . Guid : // Guids are given as plain strings.
318
- case gFieldTypeEnum . Boolean :
319
- case gFieldTypeEnum . TreePath :
321
+ case FieldTypeEnum . Integer :
322
+ case FieldTypeEnum . PicklistInteger : // See note above: Shouldn't appear, but if it does, can be treated as integer.
323
+ case FieldTypeEnum . Double :
324
+ case FieldTypeEnum . PicklistDouble : // See note above: Shouldn't appear, but if it does, can be treated as double.
325
+ case FieldTypeEnum . PicklistString : // See note above: Shouldn't appear, but if it does, can be treated as string.
326
+ case FieldTypeEnum . Guid : // Guids are given as plain strings.
327
+ case FieldTypeEnum . Boolean :
328
+ case FieldTypeEnum . TreePath :
320
329
return ( value . hasOwnProperty ( 'oldValue' ) ? `<del class="diffCls">${ EscapeHtml ( value . oldValue ) } </del>` : '' )
321
330
+ ( value . hasOwnProperty ( 'newValue' ) ? `<ins class="diffCls">${ EscapeHtml ( value . newValue ) } </ins>` : '' ) ;
322
331
323
- case gFieldTypeEnum . DateTime :
332
+ case FieldTypeEnum . DateTime :
324
333
return ( value . hasOwnProperty ( 'oldValue' ) ? `<del class="diffCls">${ FormatDate ( value . oldValue ) } </del>` : '' )
325
334
+ ( value . hasOwnProperty ( 'newValue' ) ? `<ins class="diffCls">${ FormatDate ( value . newValue ) } </ins>` : '' ) ;
326
335
327
- case gFieldTypeEnum . Identity :
336
+ case FieldTypeEnum . Identity :
328
337
return ( value . hasOwnProperty ( 'oldValue' ) ? `<del class="diffCls">${ FormatIdentityForFieldDiff ( value . oldValue ) } </del>` : '' )
329
338
+ ( value . hasOwnProperty ( 'newValue' ) ? `<ins class="diffCls">${ FormatIdentityForFieldDiff ( value . newValue ) } </ins>` : '' ) ;
330
339
331
340
default :
332
- console . log ( `HistoryDiff: Unknown field type '${ fieldType } ' (${ gFieldTypeEnum ?. [ fieldType ] } ), oldValueType: ${ typeof value . oldValue } , newValueType: ${ typeof value . newValue } ` ) ;
341
+ console . log ( `HistoryDiff: Unknown field type '${ fieldType } ' (${ FieldTypeEnum ?. [ fieldType ] } ), oldValueType: ${ typeof value . oldValue } , newValueType: ${ typeof value . newValue } ` ) ;
333
342
return undefined ;
334
343
}
335
344
}
0 commit comments