public Message ToSlackMessage(WorkItemChangedNotification notification, BotElement bot, string channel)
        {
            string header = notification.ToMessage(bot, s => s).First();
            var    fields = new[] {
                new AttachmentField(bot.Text.State, notification.State, true),
                new AttachmentField(bot.Text.AssignedTo, notification.AssignedTo, true)
            };

            return(SlackHelper.CreateSlackMessage(header, fields, bot, channel, bot.GetSetting("standardColor")));
        }
        public Message ToSlackMessage(WorkItemChangedNotification notification, BotElement bot, string channel)
        {
            string header = notification.ToMessage(bot, s => s).First();

            var fields = new List <AttachmentField>();

            var searchType       = notification.IsNew ? SearchFieldsType.Core : SearchFieldsType.Changed;
            var displayFieldsKey = notification.IsNew ? "wiCreatedDisplayFields" : "wiChangedDisplayFields";

            foreach (var fieldId in bot.GetCsvSetting(displayFieldsKey, Defaults.WorkItemFields))
            {
                var field = notification.GetUnifiedField(fieldId, searchType);
                if (field != null)
                {
                    var fieldrep = notification.IsNew ? field.NewValue : bot.Text.WorkItemFieldTransitionFormat.FormatWith(field);
                    fields.Add(new AttachmentField(field.Name, fieldrep, true));
                }
            }

            return(SlackHelper.CreateSlackMessage(header, fields, bot, channel, bot.GetSetting("standardColor")));
        }
Exemplo n.º 3
0
        internal static Message CreateMsTeamsMessage(WorkItemChangedNotification notification, BotElement bot)
        {
            string heading = notification.ToMessage(bot, s => s).First();

            var facts = new List <Fact>();

            var searchType       = notification.IsNew ? SearchFieldsType.Core : SearchFieldsType.Changed;
            var displayFieldsKey = notification.IsNew ? "wiCreatedDisplayFields" : "wiChangedDisplayFields";

            foreach (var fieldId in bot.GetCsvSetting(displayFieldsKey, Defaults.WorkItemFields))
            {
                var field = notification.GetUnifiedField(fieldId, searchType);
                if (field != null)
                {
                    var fieldrep = notification.IsNew ? field.NewValue : bot.Text.WorkItemFieldTransitionFormat.FormatWith(field);
                    facts.Add(new Fact(field.Name, fieldrep));
                }
            }

            return(CreateMsTeamsMessage(heading, facts, bot.GetSetting("standardColor")));
        }
        protected override INotification CreateNotification(TeamFoundationRequestContext requestContext, WorkItemChangedEvent ev, int maxLines)
        {
            var identityService = requestContext.GetService <TeamFoundationIdentityService>();
            var identity        = identityService.ReadIdentity(requestContext, IdentitySearchFactor.Identifier, ev.ChangerSid);
            var notification    = new WorkItemChangedNotification()
            {
                TeamProjectCollection = requestContext.ServiceHost.Name,
                IsNew               = ev.ChangeType == ChangeTypes.New,
                UniqueName          = identity.UniqueName,
                DisplayName         = identity.DisplayName,
                WiUrl               = ev.DisplayUrl,
                WiType              = ev.CoreFields.StringFields.Single(f => f.ReferenceName == "System.WorkItemType").NewValue,
                WiId                = ev.CoreFields.IntegerFields.Single(f => f.ReferenceName == "System.Id").NewValue,
                WiTitle             = ev.WorkItemTitle,
                ProjectName         = ev.PortfolioProject,
                IsStateChanged      = ev.ChangedFields.StringFields.Any(f => f.ReferenceName == "System.State"),
                IsAssignmentChanged = ev.ChangedFields.StringFields.Any(f => f.ReferenceName == "System.AssignedTo"),
                State               = ev.CoreFields.StringFields.Single(f => f.ReferenceName == "System.State").NewValue,
                AssignedTo          = ev.CoreFields.StringFields.Single(f => f.ReferenceName == "System.AssignedTo").NewValue
            };

            return(notification);
        }
Exemplo n.º 5
0
        protected override IEnumerable <INotification> CreateNotifications(TeamFoundationRequestContext requestContext, WorkItemChangedEvent ev, int maxLines)
        {
            var notifications = new List <INotification>();

            var identityService = requestContext.GetService <TeamFoundationIdentityService>();
            var identity        = identityService.ReadIdentity(requestContext, IdentitySearchFactor.Identifier, ev.ChangerSid);

            if (ev.CoreFields == null)
            {
                throw new TfsNotificationRelayException("ev.CoreFields is null");
            }
            if (ev.CoreFields.StringFields == null)
            {
                throw new TfsNotificationRelayException("ev.CoreFields.StringFields is null");
            }
            if (ev.CoreFields.IntegerFields == null)
            {
                throw new TfsNotificationRelayException("ev.CoreFields.IntegerFields is null");
            }

            var typeField = ev.CoreFields.StringFields.SingleOrDefault(f => f.ReferenceName == "System.WorkItemType");

            if (typeField == null)
            {
                throw new TfsNotificationRelayException("missing System.WorkItemType");
            }
            string type = typeField.NewValue;

            var idField = ev.CoreFields.IntegerFields.Single(f => f.ReferenceName == "System.Id");

            if (idField == null)
            {
                throw new TfsNotificationRelayException("missing System.Id");
            }
            int id = idField.NewValue;

            if (ev.TextFields != null)
            {
                var comment = ev.TextFields.FirstOrDefault(f => f.ReferenceName == "System.History" && !String.IsNullOrEmpty(f.Value));
                if (comment != null)
                {
                    var commentNotification = new WorkItemCommentNotification()
                    {
                        TeamProjectCollection = requestContext.ServiceHost.Name,
                        UniqueName            = identity.UniqueName,
                        DisplayName           = identity.DisplayName,
                        WiUrl       = ev.DisplayUrl,
                        WiType      = type,
                        WiId        = id,
                        WiTitle     = ev.WorkItemTitle,
                        ProjectName = ev.PortfolioProject,
                        AreaPath    = ev.AreaPath,
                        CommentHtml = comment.Value,
                        Comment     = TextHelper.HtmlToText(comment.Value)
                    };

                    notifications.Add(commentNotification);
                }
            }

            var changeNotification = new WorkItemChangedNotification()
            {
                TeamProjectCollection = requestContext.ServiceHost.Name,
                IsNew               = ev.ChangeType == ChangeTypes.New,
                UniqueName          = identity.UniqueName,
                DisplayName         = identity.DisplayName,
                WiUrl               = ev.DisplayUrl,
                WiType              = type,
                WiId                = id,
                WiTitle             = ev.WorkItemTitle,
                ProjectName         = ev.PortfolioProject,
                AreaPath            = ev.AreaPath,
                IsStateChanged      = ev.ChangedFields != null && ev.ChangedFields.StringFields != null && ev.ChangedFields.StringFields.Any(f => f.ReferenceName == "System.State"),
                IsAssignmentChanged = ev.ChangedFields != null && ev.ChangedFields.StringFields != null && ev.ChangedFields.StringFields.Any(f => f.ReferenceName == "System.AssignedTo"),
                State               = ev.CoreFields.StringFields.GetFieldValue("System.State", f => f.NewValue),
                AssignedTo          = ev.CoreFields.StringFields.GetFieldValue("System.AssignedTo", f => f.NewValue),
                CoreFields          = ev.CoreFields,
                ChangedFields       = ev.ChangedFields
            };

            notifications.Add(changeNotification);

            return(notifications);
        }
Exemplo n.º 6
0
        protected override IEnumerable <INotification> CreateNotifications(TeamFoundationRequestContext requestContext, WorkItemChangedEvent ev, int maxLines)
        {
            var notifications = new List <INotification>();

            var identityService = requestContext.GetService <TeamFoundationIdentityService>();
            var identity        = identityService.ReadIdentity(requestContext, IdentitySearchFactor.Identifier, ev.ChangerSid);

            if (ev.CoreFields == null)
            {
                throw new TfsNotificationRelayException("ev.CoreFields is null");
            }
            if (ev.CoreFields.StringFields == null)
            {
                throw new TfsNotificationRelayException("ev.CoreFields.StringFields is null");
            }
            if (ev.CoreFields.IntegerFields == null)
            {
                throw new TfsNotificationRelayException("ev.CoreFields.IntegerFields is null");
            }

            var typeField = ev.CoreFields.StringFields.SingleOrDefault(f => f.ReferenceName == "System.WorkItemType");

            if (typeField == null)
            {
                throw new TfsNotificationRelayException("missing System.WorkItemType");
            }
            string type = typeField.NewValue;

            var idField = ev.CoreFields.IntegerFields.Single(f => f.ReferenceName == "System.Id");

            if (idField == null)
            {
                throw new TfsNotificationRelayException("missing System.Id");
            }
            int id = idField.NewValue;

            var    assignedToString     = ev.CoreFields.StringFields.GetFieldValue("System.AssignedTo", f => f.NewValue);
            string assignedToUniqueName = null;
            string assignedTo           = null;

            if (!string.IsNullOrEmpty(assignedToString))
            {
                UserField assignedToField = null;
                if (UserField.TryParse(assignedToString, out assignedToField) && assignedToField.Identifier != Guid.Empty)
                {
                    assignedTo = assignedToField.DisplayName;
                    var assignedToIdentity = identityService.ReadIdentities(requestContext, new[] { assignedToField.Identifier }).First();
                    assignedToUniqueName = assignedToIdentity.UniqueName;
                }
            }

            var teamNames = GetUserTeamsByProjectUri(requestContext, ev.ProjectNodeId, identity.Descriptor).ToList();

            var comment = ev.TextFields?.FirstOrDefault(f => f.ReferenceName == "System.History" && !string.IsNullOrEmpty(f.Value));

            if (comment != null)
            {
                var commentNotification = new WorkItemCommentNotification()
                {
                    TeamProjectCollection = requestContext.ServiceHost.Name,
                    UniqueName            = identity.UniqueName,
                    DisplayName           = identity.DisplayName,
                    WiUrl                = ev.DisplayUrl,
                    WiType               = type,
                    WiId                 = id,
                    WiTitle              = ev.WorkItemTitle,
                    ProjectName          = ev.PortfolioProject,
                    AreaPath             = ev.AreaPath,
                    AssignedTo           = assignedTo,
                    AssignedToUniqueName = assignedToUniqueName,
                    CommentHtml          = comment.Value,
                    Comment              = TextHelper.HtmlToText(comment.Value),
                    TeamNames            = teamNames
                };

                notifications.Add(commentNotification);
            }

            var changeNotification = new WorkItemChangedNotification()
            {
                TeamProjectCollection = requestContext.ServiceHost.Name,
                IsNew                = ev.ChangeType == ChangeTypes.New,
                UniqueName           = identity.UniqueName,
                DisplayName          = identity.DisplayName,
                WiUrl                = ev.DisplayUrl,
                WiType               = type,
                WiId                 = id,
                WiTitle              = ev.WorkItemTitle,
                ProjectName          = ev.PortfolioProject,
                AreaPath             = ev.AreaPath,
                IsStateChanged       = ev.ChangedFields?.StringFields?.Any(f => f.ReferenceName == "System.State") ?? false,
                IsAssignmentChanged  = ev.ChangedFields?.StringFields?.Any(f => f.ReferenceName == "System.AssignedTo") ?? false,
                State                = ev.CoreFields.StringFields.GetFieldValue("System.State", f => f.NewValue),
                AssignedTo           = assignedTo,
                AssignedToUniqueName = assignedToUniqueName,
                CoreFields           = ev.CoreFields,
                ChangedFields        = ev.ChangedFields,
                TeamNames            = teamNames
            };

            notifications.Add(changeNotification);

            return(notifications);
        }