@@ -53,23 +53,25 @@ public IEnumerable<int> GetAllTestCasesIds()
53
53
{
54
54
var query = $@ "Select [{ WorkItemFields . Id } ]
55
55
From WorkItems
56
- Where [System.WorkItemType] = '{ WorkItemTypes . TestCase } '" ;
57
-
56
+ Where [System.WorkItemType] = '{ WorkItemTypes . TestCase } '
57
+ AND [System.TeamProject] = '{ _azureDevopsSettings . Project } '" ;
58
+
58
59
var workItems = GetListOfWorkItemsWithQuery ( query ) ;
59
60
60
61
return workItems . Select ( reference => reference . Id ) ;
61
62
}
62
-
63
+
63
64
public IEnumerable < int > GetSyncedTestCasesIds ( )
64
65
{
65
66
66
67
var query = $@ "Select [{ WorkItemFields . Id } ]
67
68
From WorkItems
68
69
Where [System.WorkItemType] = '{ WorkItemTypes . TestCase } '
69
70
AND [{ WorkItemFields . State } ] <> '{ TestCaseState . Closed } '
70
- AND [{ WorkItemFields . Tags } ]
71
+ AND [System.TeamProject] = '{ _azureDevopsSettings . Project } '
72
+ AND [{ WorkItemFields . Tags } ]
71
73
Contains '{ Tags . GherkinSyncToolIdTagPrefix + _azureDevopsSettings . GherkinSyncToolId } '" ;
72
-
74
+
73
75
var workItems = GetListOfWorkItemsWithQuery ( query ) ;
74
76
75
77
return workItems . Select ( reference => reference . Id ) ;
@@ -146,8 +148,10 @@ private List<WorkItem> SendWorkItemBatch(List<WitBatchRequest> request)
146
148
147
149
if ( witBatchResponse . Code != 200 )
148
150
{
149
- Log . Error ( $ "Something went wrong with the test case synchronization. Title: { request [ i ] . GetFields ( ) [ WorkItemFields . Title ] } ") ;
150
- Log . Error ( $ "Status code: { witBatchResponse . Code } { Environment . NewLine } Body: { witBatchResponse . Body } ") ;
151
+ Log . Error (
152
+ $ "Something went wrong with the test case synchronization. Title: { request [ i ] . GetFields ( ) [ WorkItemFields . Title ] } ") ;
153
+ Log . Error (
154
+ $ "Status code: { witBatchResponse . Code } { Environment . NewLine } Body: { witBatchResponse . Body } ") ;
151
155
152
156
_context . IsRunSuccessful = false ;
153
157
continue ;
@@ -200,52 +204,39 @@ private IList<WorkItemReference> GetListOfWorkItemsWithQuery(string query)
200
204
{
201
205
var results = new List < WorkItemReference > ( ) ;
202
206
var workItemTrackingHttpClient = GetWorkItemTrackingHttpClient ( ) ;
203
- var counter = 10000 ;
204
207
var moreResults = true ;
205
-
208
+ var lastIdInList = 0 ;
209
+
206
210
while ( moreResults )
207
211
{
208
- // wiql - Work Item Query Language
209
- var wiql = new Wiql
212
+ var wiql = new Wiql ( )
210
213
{
211
214
Query = $@ "{ query }
212
- AND [{ WorkItemFields . Id } ] >= { counter - 10000 }
213
- AND [{ WorkItemFields . Id } ] < { counter } "
215
+ And [{ WorkItemFields . Id } ] > { lastIdInList }
216
+ ORDER BY [{ WorkItemFields . Id } ] ASC "
214
217
} ;
215
-
216
- var currentResults = workItemTrackingHttpClient . QueryByWiqlAsync ( wiql , _azureDevopsSettings . Project )
218
+
219
+ //Max number of workItems is 19999, until it gets fixed from the microsoft side
220
+ var currentResults = workItemTrackingHttpClient
221
+ . QueryByWiqlAsync ( wiql , _azureDevopsSettings . Project , top : 19999 )
217
222
. Result . WorkItems . ToList ( ) ;
218
-
219
- if ( ! currentResults . Any ( ) )
223
+
224
+ var currentResultsLength = currentResults . Count ;
225
+
226
+ if ( currentResultsLength < 19999 )
220
227
{
221
- try
222
- {
223
- results . AddRange ( workItemTrackingHttpClient . QueryByWiqlAsync ( new Wiql
224
- {
225
- Query = $@ "{ query } AND [{ WorkItemFields . Id } ] >= { counter } "
226
- } ) . Result . WorkItems . ToList ( ) ) ;
227
-
228
- moreResults = false ;
229
- }
230
- catch ( Exception e )
231
- {
232
- if ( e . ToString ( ) . Contains ( "VS402337" ) )
233
- {
234
- // If this exception persists, it means that there are more, than 20000 workItems left,
235
- // so increment and continue
236
- }
237
- else
238
- {
239
- throw ;
240
- }
241
- }
228
+ moreResults = false ;
242
229
}
243
- else
230
+
231
+ var lastItemInList = currentResults . LastOrDefault ( ) ;
232
+
233
+ if ( lastItemInList == null )
244
234
{
245
- results . AddRange ( currentResults ) ;
235
+ break ;
246
236
}
247
237
248
- counter += 10000 ;
238
+ lastIdInList = lastItemInList . Id ;
239
+ results . AddRange ( currentResults ) ;
249
240
}
250
241
251
242
return results ;
0 commit comments