Esempio n. 1
0
        /// <summary>
        /// Add reaction to the last comment
        /// </summary>
        /// <param name="teamProjectName"></param>
        /// <param name="workItemID"></param>
        /// <param name="reactionType"></param>
        private static void AddReactionToLastComment(string teamProjectName, int workItemID, CommentReactionType reactionType)
        {
            CommentList comments = WitClient.GetCommentsAsync(teamProjectName, workItemID).Result;

            var reaction = WitClient.CreateCommentReactionAsync(teamProjectName, workItemID, comments.Comments.ElementAt(0).Id, reactionType).Result;

            Console.WriteLine("{0} - {1}\n", reaction.Type, reaction.Count);
        }
Esempio n. 2
0
        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;
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        /// <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);
        }