Пример #1
0
        public async void UpdateSlack(string almDomain, string almProject, List <string> almQueries, Dictionary <string, List <string> > groupsIDsForSubareas)
        {
            Dictionary <string, List <SLMessage> > messagesForGroupIDs = await GetMessagesForGroupIDs(groupsIDsForSubareas);

            if (almApiClient.Authenticate())
            {
                DateTime         lastPostDate         = ReadLastPostedDateTime(lastPostedDefectDateTimeFilePath);
                List <ALMDefect> almDefectsForQueries = await GetAlmDefectsForQueries(almDomain, almProject, almQueries, lastPostDate);

                bool     allDefectsPosted       = true;
                DateTime newestDefectModifyDate = DateTime.Now;
                if (almDefectsForQueries.Count != 0)
                {
                    newestDefectModifyDate = almDefectsForQueries.Max(defect => Convert.ToDateTime(defect.last_modified_date));
                    Dictionary <string, List <ALMDefect> > almDefectsForSubareas = OrganizeDefectsBySubareas(almDefectsForQueries, groupsIDsForSubareas.Keys.ToList());
                    bool defectsPosted = await PostDefects(almDefectsForSubareas, messagesForGroupIDs, groupsIDsForSubareas);

                    if (!defectsPosted)
                    {
                        allDefectsPosted = false;
                    }
                }
                else
                {
                    // No defects received from query? Or there is no connection to server? T_T
                    allDefectsPosted = false;
                }
                if (allDefectsPosted)
                {
                    WriteLastPostedDateTime(lastPostedDefectDateTimeFilePath, newestDefectModifyDate);
                }
            }
            else
            {
                // Failed to authenticate on ALM
            }
        }
        private async void HandleDefCommand(string[] parameters, SLRuntimeEventArgs e)
        {
            if (almApiClient.Authenticate())
            {
                if (parameters.Length == 2)
                {
                    string defectId = parameters[1];

                    List <ALMDefect> defects = await almApiClient.GetDefectsAsync(almDomain, almProject, "&query={id[" + defectId + "];}");

                    StringBuilder text = new StringBuilder("");
                    if (defects.Count > 0)
                    {
                        text.Append("Title: " + defects[0].name + "\n");
                        text.Append("State: " + defects[0].status + "\n");
                        text.Append("Dev: " + defects[0].owner_dev + "\n");
                        text.Append("QA Lead: " + defects[0].user_40_qalead + "\n");
                        slRuntimeApiClient.SendWithMessageType(1, e.channel, text.ToString(), true, true);
                    }
                    else
                    {
                        text.Append("Either such defect doesn't exist, either connection to ALM server is broken");
                        slRuntimeApiClient.SendWithMessageType(1, e.channel, text.ToString(), true, true);
                    }
                }
                else if (parameters.Length == 3)
                {
                    string userType = parameters[1];
                    if (userType.Equals("-d"))
                    {
                        string           developerQcName = parameters[2];
                        List <ALMDefect> defects         = await almApiClient.GetDefectsAsync(almDomain, almProject, "&query={planned-closing-ver[Not \"Obsolete\"];owner[" + developerQcName + "];status[Not \"Closed\"];}");

                        StringBuilder text = new StringBuilder("");
                        if (defects.Count > 0)
                        {
                            foreach (ALMDefect defect in defects)
                            {
                                text.Append(defect.id + " - ");
                                text.Append(defect.name + "\n");
                                slRuntimeApiClient.SendWithMessageType(1, e.channel, text.ToString(), true, true);
                                text.Clear();
                            }
                        }
                        else
                        {
                            text.Append("There is no 'Not Closed' defect on this developer, or developer name specified incorrectly");
                            slRuntimeApiClient.SendWithMessageType(1, e.channel, text.ToString(), true, true);
                        }
                    }
                    else if (userType.Equals("-ql"))
                    {
                        string           qaLeadQcName = parameters[2];
                        List <ALMDefect> defects      = await almApiClient.GetDefectsAsync(almDomain, almProject, "&query={planned-closing-ver[Not \"Obsolete\"];user-40[" + qaLeadQcName + "];status[Not \"Closed\"];}");

                        StringBuilder text = new StringBuilder("");
                        if (defects.Count > 0)
                        {
                            foreach (ALMDefect defect in defects)
                            {
                                text.Append(defect.id + " - ");
                                text.Append(defect.name + "\n");
                                slRuntimeApiClient.SendWithMessageType(1, e.channel, text.ToString(), true, true);
                                text.Clear();
                            }
                        }
                        else
                        {
                            text.Append("There is no 'Not Closed' defect on this qalead, or qalead name specified incorrectly");
                            slRuntimeApiClient.SendWithMessageType(1, e.channel, text.ToString(), true, true);
                        }
                    }
                }
            }
            else
            {
                slRuntimeApiClient.SendWithMessageType(14235325, e.channel, "Connection to ALM server is broken", true, true);
            }
        }