@@ -7,40 +7,35 @@ namespace AzureDevopsTracker.Helpers
77{
88 public static class ReadJsonHelper
99 {
10+
1011 public static IEnumerable < WorkItemCustomField > ReadJson ( string workItemId , string jsonTexto )
1112 {
1213 try
1314 {
15+ JObject json = JObject . Parse ( jsonTexto ) ;
16+ JObject ? fields = json . SelectToken ( "resource.revision.fields" ) as JObject ;
17+ if ( fields == null )
18+ {
19+ return Enumerable . Empty < WorkItemCustomField > ( ) ;
20+ }
1421 var workItemCustomFields = new List < WorkItemCustomField > ( ) ;
15- foreach ( KeyValuePair < string , JToken > element in JObject . Parse ( jsonTexto ) )
22+
23+ foreach ( var property in fields . Properties ( ) )
1624 {
17- if ( element . Value is JObject )
18- ReadJsonObject ( workItemId , workItemCustomFields , ( JObject ) element . Value ) ;
19- else
20- GetWorkItemCustomField ( workItemCustomFields , workItemId , element . Key , element . Value . ToString ( ) ) ;
25+ if ( property . Name . StartsWith ( "Custom." ) )
26+ {
27+ string key = property . Name [ "Custom." . Length ..] ;
28+ string value = property . Value . ToString ( ) ;
29+ workItemCustomFields . Add ( new WorkItemCustomField ( workItemId , key , value ) ) ;
30+ }
2131 }
2232
2333 return workItemCustomFields ;
2434 }
2535 catch
2636 {
27- return Enumerable . Empty < WorkItemCustomField > ( ) ;
37+ return [ ] ;
2838 }
2939 }
30-
31- private static void ReadJsonObject ( string workItemId , List < WorkItemCustomField > workItemCustomFields , JObject objeto )
32- {
33- foreach ( KeyValuePair < string , JToken > item in objeto )
34- if ( item . Value is JObject )
35- ReadJsonObject ( workItemId , workItemCustomFields , ( JObject ) item . Value ) ;
36- else
37- GetWorkItemCustomField ( workItemCustomFields , workItemId , item . Key , item . Value . ToString ( ) ) ;
38- }
39-
40- private static void GetWorkItemCustomField ( List < WorkItemCustomField > workItemCustomFields , string workItemId , string key , string value )
41- {
42- if ( key is not null && ! key . ToLower ( ) . Contains ( "custom" ) ) return ;
43- workItemCustomFields . Add ( new WorkItemCustomField ( workItemId , key , value ) ) ;
44- }
4540 }
4641}
0 commit comments