public void AddComment() { // Get a work item WorkItem wi = WitClient.GetWorkItemAsync(this.WorkItemsAdded.First()).Result; // Get the current last comment of the work item WorkItemComments comments = WitClient.GetCommentsAsync(wi.Id.Value).Result; var originalCommentCount = comments.Count; // Create a JSON patch document with an entry updating System.History JsonPatchDocument patchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.History", Value = "Added a comment" } }; // Update the work item with the patch document var result = WitClient.UpdateWorkItemAsync(patchDocument, wi.Id.Value).Result; // Get the current last comment of the work item var updatedComments = WitClient.GetCommentsAsync(result.Id.Value).Result; var updatedCommentCount = updatedComments.Count; // Show that the current last comment is different than the original last comment Console.WriteLine($"There were {originalCommentCount} comments"); Console.WriteLine($"There are now {updatedCommentCount} comments"); Console.WriteLine(); }
public CommentsWindow(WorkItem workItem, WorkItemComments comments) : base("[#" + workItem.Id + "] " + workItem.Title() + " - " + "Comments") { X = 0; Y = 2; // Leave one row for the toplevel menu Width = Dim.Fill(); Height = Dim.Fill(); ColorScheme = Program.ColorScheme; var items = comments.Comments .SelectMany(c => new[] { Environment.NewLine + c.RevisedBy.Name + " " + c.RevisedDate.ToLongTimeString() + " " + c.RevisedDate.ToLongDateString(), Html.Clean(c.Text).WordWrap(Console.WindowWidth - 2), string.Empty }) .ToList(); var list = new TextView { Width = Dim.Fill(), Height = Dim.Fill(), ColorScheme = Program.ColorScheme, CanFocus = true, Text = string.Join(Environment.NewLine, items) }; Add(list); }
public async Task <IActionResult> GetWorkItemComments(int id) { var uriLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_Uri"); Uri accountUri = new Uri(uriLookup.Lvalue); var tokenLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_AccessToken"); String personalAccessToken = tokenLookup.Lvalue; // Create a connection to the account VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken)); // Get an instance of the work item tracking client WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { // Get the specified work item WorkItemComments comments = witClient.GetCommentsAsync(id).Result; return(Ok(comments)); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { throw vssex; } throw aex; } }
public string download(string orgName, string personalAccessToken, string projectName, int workItemId) { var uri = new Uri("https://dev.azure.com/" + orgName); var credentials = new VssBasicCredential("", personalAccessToken); var connection = new VssConnection(uri, credentials); var workItemTrackingHttpClient = connection.GetClient <WorkItemTrackingHttpClient>(); WorkItem workItem = workItemTrackingHttpClient.GetWorkItemAsync(projectName, workItemId, null, null, WorkItemExpand.All, null).Result; string workItemString = determineWorkItemString(workItem); WorkItemComments workItemComments = workItemTrackingHttpClient.GetCommentsAsync(projectName, workItemId).Result; string workItemCommentsString = determineWorkItemCommentsString(workItemComments); List <WorkItemUpdate> workItemUpdates = workItemTrackingHttpClient.GetUpdatesAsync(projectName, workItemId).Result; string workItemCommentUpdatesString = determineWorkItemCommentsUpdatesString(workItemUpdates); return(workItemString + workItemCommentsString + workItemCommentUpdatesString); }
public WorkItemComments GetPageOfWorkItemComments() { int id = Convert.ToInt32(Context.GetValue <WorkItem>("$newWorkItem").Id); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>(); WorkItemComments result = workItemTrackingClient.GetCommentsAsync(id, 1).Result; Console.WriteLine("Total Revision Count: {0}", result.TotalCount); Console.WriteLine("From Revision Count: {0}", result.FromRevisionCount); Console.WriteLine("Comments..."); foreach (var comment in result.Comments) { Console.WriteLine("{0}", comment.Text); Console.WriteLine(); } return(result); }
static string determineWorkItemCommentsString(WorkItemComments workItemComments) { if (workItemComments == null) { return(""); } IList <string> strs = new List <string>(); strs.Add("WorkItemComments: "); strs.Add(createBlanks(4) + "TotalCount: " + workItemComments.TotalCount); strs.Add(createBlanks(4) + "Count: " + workItemComments.Count); if (!string.IsNullOrWhiteSpace(workItemComments.Url)) { strs.Add(createBlanks(4) + "Url: " + workItemComments.Url); } strs.AddRange(linksToStringList(4, workItemComments.Links)); strs.AddRange(commentsToStringList(4, workItemComments.Comments)); return(mergeStringListItems(strs)); }
/// <summary> /// /// </summary> /// <param name="azureDevOpsUri">URI as a string</param> /// <param name="personalAccessToken">Personal Access Token as a string</param> /// <param name="azureDevOpsWiqlString">The DevOps Query as a string</param> /// <param name="fields">The specific fields to show as an array</param> /// <returns></returns> public List <WorkItemInstance> GetAllWorkItemsFromAzureDevOps(string azureDevOpsUri, string personalAccessToken, string azureDevOpsWiqlString, string[] fields) { List <WorkItemInstance> workItemsAndCommentsList = new List <WorkItemInstance>(); try { //Set the Uri and Access token Uri devOpsUri = new Uri(azureDevOpsUri); VssBasicCredential credentials = new VssBasicCredential("", personalAccessToken); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(devOpsUri, credentials)) { //Retrieve the work items based on the Wiql string provided WorkItemQueryResult workItemQueryResult = WorkItemResponse(devOpsUri, credentials, azureDevOpsWiqlString); var selectedWorkItemIDs = workItemQueryResult.WorkItems.Select(workItemReference => workItemReference.Id).ToList(); var retrievedWorkItems = workItemTrackingHttpClient.GetWorkItemsAsync(selectedWorkItemIDs, fields, workItemQueryResult.AsOf).Result; foreach (WorkItem workItem in retrievedWorkItems) { int workItemId = (int)workItem.Id; List <WorkItemStateChange> WorkItemStateChangesList = new List <WorkItemStateChange>(); List <WorkItemUpdate> updates = workItemTrackingHttpClient.GetUpdatesAsync(workItemId).Result; foreach (var WorkItemStateChange in updates) { WorkItemStateChange myWorkItemStateChange = new WorkItemStateChange(); myWorkItemStateChange.WorkItemStateChangeId = WorkItemStateChange.Id.ToString(); myWorkItemStateChange.Revision = WorkItemStateChange.Rev.ToString(); myWorkItemStateChange.RevisedBy = WorkItemStateChange.RevisedBy.Name; if (WorkItemStateChange.Fields != null && WorkItemStateChange.Fields.ContainsKey("System.Reason")) { WorkItemFieldUpdate workItemUpdateReason = (WorkItemFieldUpdate)WorkItemStateChange.Fields["System.Reason"]; myWorkItemStateChange.ReasonOldValue = workItemUpdateReason.OldValue != null?workItemUpdateReason.OldValue.ToString() : "OLD VALUE IS NULL"; myWorkItemStateChange.ReasonNewValue = workItemUpdateReason.NewValue != null?workItemUpdateReason.NewValue.ToString() : "NEW VALUE IS NULL"; myWorkItemStateChange.RevisedDate = WorkItemStateChange.RevisedDate.ToShortDateString(); WorkItemStateChangesList.Add(myWorkItemStateChange); } } WorkItemInstance adoWorkItemInstanceClass = new WorkItemInstance(); adoWorkItemInstanceClass.WorkItemUpdateList = WorkItemStateChangesList; //Get the WorkItemId add it to the main record adoWorkItemInstanceClass.WorkItemId = workItem.Fields["System.Id"].ToString(); //Add the work item to the class adoWorkItemInstanceClass.AdoWorkItem = workItem; WorkItemComments workItemComments = workItemTrackingHttpClient.GetCommentsAsync(workItem.Id.Value).Result; //adoWorkItemInstanceClass.AdoCommentsList = new List<WorkItemComment>(); List <WorkItemComment> commentsList = new List <WorkItemComment>(); foreach (WorkItemComment commentItem in workItemComments.Comments) { //Add the comment to the list commentsList.Add(commentItem); } //Add the comments list to the WorkItemInstance class adoWorkItemInstanceClass.AdoCommentsList = commentsList; workItemsAndCommentsList.Add(adoWorkItemInstanceClass); } } } catch (AggregateException aggException) { WorkItemInstance aggExceptionWorkItem = new WorkItemInstance(); aggExceptionWorkItem.ErrorMessage = aggException.InnerException.ToString(); workItemsAndCommentsList.Add(aggExceptionWorkItem); } catch (VssException vssException) { WorkItemInstance vssExceptionWorkItem = new WorkItemInstance(); vssExceptionWorkItem.ErrorMessage = vssException.InnerException.ToString(); workItemsAndCommentsList.Add(vssExceptionWorkItem); } //Output is the Work Items and their comments return(workItemsAndCommentsList); }