private async Task <TfsInfo> ProcessWorkItemRevisions(WorkItemReference workItemRef) { var revisions = await this.workItemClient.GetRevisionsAsync( workItemRef.Id, expand : WorkItemExpand.Fields); string lastState = null; var revs = new WorkItemRevisionBuilder(); foreach (var workItemRev in revisions) { var state = workItemRev.State(); if (state != null && lastState != state) { lastState = state; await ProcessWorkItemRevision(workItemRev, revs); } } if (revs.States.Count > 1) { var sbTemp = new StringBuilder(); for (int i = 0; i < revs.States.Count; i++) { sbTemp.Append(revs.States[i].Summary); if (i + 1 < revs.States.Count) { sbTemp.AppendLine(); } revs.TfsInfo.Transitions = sbTemp.ToString().Trim(); } revs.TfsInfo.TransitionCount = revs.States.Count; } lock (this.lockObject) { this.processedCount++; var progress = new ReportProgress { Message = $"{revs.TfsInfo.Title}", WorkItemsProcessed = this.processedCount, TotalCount = this.totalCount }; this.broadcastService.ReportProgress(progress); } return(revs.TfsInfo); }
public WorkItem FindWorkItem(int number, string repo) { string pat = _options.Value.ADO_Pat; string org = _options.Value.ADO_Org; string project = _options.Value.ADO_Project; Uri baseUri = new Uri("https://dev.azure.com/" + org); VssCredentials clientCredentials = new VssCredentials(new VssBasicCredential("username", pat)); VssConnection connection = new VssConnection(baseUri, clientCredentials); WorkItemTrackingHttpClient client = connection.GetClient <WorkItemTrackingHttpClient>(); WorkItem result = null; Wiql wiql = new Wiql() { Query = "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] FROM workitems WHERE [System.TeamProject] = @project AND [System.Title] CONTAINS '(GitHub Issue #" + number + ")' AND [System.Tags] CONTAINS 'GitHub Issue' AND [System.Tags] CONTAINS '" + repo + "'" }; try { WorkItemQueryResult queryResult = client.QueryByWiqlAsync(wiql, project).Result; WorkItemReference workItem = null; workItem = queryResult.WorkItems.Count() > 0 ? queryResult.WorkItems.First() : null; result = workItem != null?client.GetWorkItemAsync(workItem.Id, null, null, WorkItemExpand.All).Result : null; } catch (Exception) { result = null; } finally { clientCredentials = null; connection = null; client = null; } return(result); }
public void UpdateProjectTestCases() { // Retrieve list of postman test cases in Wrapper project List <MethodInfo> testMethods = GetTestMethods(Assembly.GetAssembly(typeof(PostmanWrapper))); // Create/update postman test cases in ADO project foreach (MethodInfo mi in testMethods) { int workItemId = -1; foreach (CustomAttributeData cad in mi.CustomAttributes) { if (cad.ConstructorArguments.Count == 2 && cad.ConstructorArguments[0].Value.ToString() == "AdoId") { workItemId = int.Parse(cad.ConstructorArguments[1].Value.ToString()); break; } } if (workItemId > 0) { Wiql query = new Wiql() { Query = string.Format("SELECT [Id] FROM workitems WHERE [System.TeamProject] = '{0}' AND [System.WorkItemType] = '{1}' AND [System.Id] = '{2}'", project, ADOTestCaseWorkItemType(), workItemId) }; WorkItemQueryResult result = witClient.QueryByWiqlAsync(query, project).Result; if (result.WorkItems.Count() == 0) { throw new Exception(string.Format("Linked Test Case with prescribed id {0} could not be found", workItemId)); } WorkItemReference wir = result.WorkItems.First(); WorkItem wi = witClient.GetWorkItemAsync(workItemId).Result; JsonPatchDocument patchDoc = GetPatchDocumentAutomation(mi, wi); if (patchDoc.Count > 0) { Task <WorkItem> item = witClient.UpdateWorkItemAsync(patchDoc, project, wir.Id); item.GetAwaiter().GetResult(); Console.WriteLine("Update manually linked Test Case : " + workItemId); } else { Console.WriteLine("Manually linked Test Case already up to date : " + workItemId); } } else { Wiql query = new Wiql() { Query = string.Format("SELECT [Id] FROM workitems WHERE [System.TeamProject] = '{0}' AND [System.WorkItemType] = '{1}' AND [System.Title] = '{2}' AND [Microsoft.VSTS.TCM.AutomatedTestType] = '{3}'", project, ADOTestCaseWorkItemType(), ADOTestCaseTitle(mi), ADOTestCaseAutomatedTestType()) }; WorkItemQueryResult result = witClient.QueryByWiqlAsync(query, project).Result; if (result.WorkItems.Count() == 0) { JsonPatchDocument patchDoc = GetPatchDocumentFull(mi, null); Task <WorkItem> item = witClient.CreateWorkItemAsync(patchDoc, project, ADOTestCaseWorkItemType()); var res = item.GetAwaiter().GetResult(); workItemId = (int)res.Id; Console.WriteLine("Create automatically linked Test Case : " + workItemId); } else if (result.WorkItems.Count() == 1) { WorkItemReference wir = result.WorkItems.First(); workItemId = wir.Id; WorkItem wi = witClient.GetWorkItemAsync(workItemId).Result; JsonPatchDocument patchDoc = GetPatchDocumentFull(mi, wi); if (patchDoc.Count > 0) { Task <WorkItem> item = witClient.UpdateWorkItemAsync(patchDoc, project, wir.Id); item.GetAwaiter().GetResult(); Console.WriteLine("Update automatically linked Test Case : " + workItemId); } else { Console.WriteLine("Automatically linked Test Case already up to date : " + workItemId); } } else { // For now, we ignore multiple instances of the same test case representation in ADO. // Most likely multiple instances exist in ADO because the test case has been copied. } } } }
public SingleMigrationWorkItem(WorkItemReference actualItemRef) { WorkItemRef = actualItemRef; Fields = new Dictionary <string, object>(); }