コード例 #1
0
        private string ChangeCountsToString(BotElement bot, Dictionary <TfsGitChangeType, int> changeCounts)
        {
            var counters = new[] {
                new ChangeCounter(TfsGitChangeType.Add, bot.Text.ChangeCountAddFormat, 0),
                new ChangeCounter(TfsGitChangeType.Edit, bot.Text.ChangeCountEditFormat, 0),
                new ChangeCounter(TfsGitChangeType.Delete, bot.Text.ChangeCountDeleteFormat, 0),
                new ChangeCounter(TfsGitChangeType.Rename, bot.Text.ChangeCountRenameFormat, 0),
                new ChangeCounter(TfsGitChangeType.SourceRename, bot.Text.ChangeCountSourceRenameFormat, 0)
            };

            foreach (var changeCount in changeCounts)
            {
                // renamed files will also show up as Rename or Rename+Edit, so don't count them twice
                if (changeCount.Key == (TfsGitChangeType.Delete | TfsGitChangeType.SourceRename))
                {
                    continue;
                }

                foreach (var counter in counters.Where(c => changeCount.Key.HasFlag(c.Type)))
                {
                    counter.Count += changeCount.Value;
                }
            }

            return(string.Join(", ", counters.Where(c => c.Count > 0).Select(c => c.Format.FormatWith(new { c.Count }))));
        }
コード例 #2
0
        private static JObject CreateHipChatMessage(INotification notification, BotElement bot, string color)
        {
            dynamic jobject = new JObject();

            if (bot.GetSetting("messageFormat") == "text")
            {
                var lines = notification.ToMessage(bot, s => s);
                if (lines == null || !lines.Any())
                {
                    return(null);
                }
                jobject.message_format = "text";
                jobject.message        = string.Join("\n", lines);
            }
            else
            {
                var lines = notification.ToMessage(bot, HttpUtility.HtmlEncode);
                if (lines == null || !lines.Any())
                {
                    return(null);
                }
                jobject.message_format = "html";
                jobject.message        = string.Join("<br/>", lines);
            }
            jobject.color  = color;
            jobject.notify = bot.GetSetting("notify").Equals("true", StringComparison.OrdinalIgnoreCase);

            return(jobject);
        }
コード例 #3
0
        public override IList <string> ToMessage(BotElement bot, TextElement text, Func <string, string> transform)
        {
            var lines     = new List <string>();
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                DisplayName           = transform(DisplayName),
                ProjectName           = transform(ProjectName),
                AreaPath = transform(AreaPath),
                WiUrl,
                WiType = transform(WiType),
                WiId,
                WiTitle              = transform(WiTitle),
                UserName             = transform(UserName),
                Action               = text.CommentedOn,
                AssignedToUserName   = transform(AssignedToUserName),
                MappedAssignedToUser = bot.GetMappedUser(AssignedToUniqueName),
                MappedUser           = bot.GetMappedUser(UniqueName)
            };

            lines.Add(text.WorkItemchangedFormat.FormatWith(formatter));
            lines.Add(TextHelper.Truncate(Comment, Settings.DiscussionCommentMaxLength));

            return(lines);
        }
コード例 #4
0
        public override string ToString(BotElement bot, Func <string, string> transform)
        {
            string formattedTime = String.IsNullOrEmpty(bot.Text.DateTimeFormat) ? AuthorTime.ToString() : AuthorTime.ToString(bot.Text.DateTimeFormat);
            var    sb            = new StringBuilder();

            if (RefNames != null)
            {
                sb.AppendFormat("{0} ", transform(String.Concat(RefNames)));
            }

            sb.Append(bot.Text.CommitFormat.FormatWith(new
            {
                Action       = Type == CommitRowType.Commit ? bot.Text.Commit : bot.Text.RefPointer,
                CommitUri    = CommitUri,
                CommitId     = transform(CommitId.ToHexString(settings.HashLength)),
                ChangeCounts = (ChangeCounts != null) ? String.Join(", ", ChangeCounts.Select(c => ChangeCountToString(bot, c))) : "",
                AuthorTime   = formattedTime,
                Author       = transform(Author),
                AuthorName   = transform(AuthorName),
                AuthorEmail  = transform(AuthorEmail),
                Comment      = transform(Comment.Truncate(settings.CommentMaxLength))
            }));

            return(sb.ToString());
        }
コード例 #5
0
        internal static Message CreateMsTeamsMessage(INotification notification, BotElement bot)
        {
            var lines = notification.ToMessage(bot, s => s);

            if (lines == null || !lines.Any())
            {
                return(null);
            }

            var sb = new StringBuilder();

            sb.Append("#####"); // Not using message.Title for now. It's displayed too small, doesn't handle markdown and is not shown at all on Android client.
            sb.AppendLine(lines.First());
            foreach (var line in lines.Skip(1))
            {
                sb.Append("* ");
                sb.AppendLine(line);
            }
            var     color   = bot.GetSetting("standardColor").Substring(1);
            Message message = new Message()
            {
                Text = sb.ToString(), ThemeColor = color
            };

            return(message);
        }
        public Message ToSlackMessage(BuildCompletionNotification notification, BotElement bot, string channel)
        {
            var lines = notification.ToMessage(bot, s => s);
            var color = notification.IsSuccessful ? bot.GetSetting("successColor") : bot.GetSetting("errorColor");

            return(SlackHelper.CreateSlackMessage(lines, bot, channel, color));
        }
        public Message ToSlackMessage(WorkItemCommentNotification notification, BotElement bot, string channel)
        {
            string header = notification.ToMessage(bot, s => s).First();
            var    fields = new[] {
                new AttachmentField(bot.Text.Comment, notification.Comment, false)
            };

            return(SlackHelper.CreateSlackMessage(header, fields, bot, channel, bot.GetSetting("standardColor")));
        }
コード例 #8
0
        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")));
        }
コード例 #9
0
        public override IList <string> ToMessage(BotElement bot, TextElement text, Func <string, string> transform)
        {
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                ProjectUrl,
                ProjectName = transform(ProjectName),
            };

            return(new[] { text.ProjectCreatedFormat.FormatWith(formatter) });
        }
コード例 #10
0
        public override string ToString(BotElement bot, Func <string, string> transform)
        {
            var formatter = new
            {
                DisplayName = transform(DisplayName), RepoUri,
                ProjectName = transform(ProjectName),
                RepoName    = transform(RepoName),
                Pushed      = IsForcePush ? bot.Text.ForcePushed : bot.Text.Pushed,
                UserName    = transform(UserName)
            };

            return(bot.Text.PushFormat.FormatWith(formatter));
        }
コード例 #11
0
ファイル: IrcNotifier.cs プロジェクト: kria/TfsBot
        public void Notify(INotification notification, BotElement bot)
        {
            string servicEndpoint = bot.GetSetting("serviceEndpoint", "net.pipe://localhost/BotService");

            ChannelFactory <IBotService> factory = new ChannelFactory <IBotService>(new NetNamedPipeBinding(),
                                                                                    new EndpointAddress(servicEndpoint));
            IBotService service = factory.CreateChannel();

            foreach (string line in notification.ToMessage(bot))
            {
                service.SendMessage(line);
            }
        }
        private string FormatAction(BotElement bot)
        {
            switch (Vote)
            {
            case -10: return(bot.Text.VoteRejected);

            case 0: return(bot.Text.VoteRescinded);

            case 10: return(bot.Text.VoteApproved);

            default:
                return($"voted {Vote} on");
            }
        }
        public override IList <string> ToMessage(BotElement bot, Func <string, string> transform)
        {
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                DisplayName           = transform(DisplayName),
                UserName    = transform(UserName),
                ProjectName = transform(ProjectName),
                RepoUri,
                RepoName = transform(RepoName)
            };

            return(new[] { bot.Text.RepositoryCreatedFormat.FormatWith(formatter) });
        }
コード例 #14
0
        public IList <string> ToMessage(BotElement bot, Func <string, string> transform)
        {
            var lines = this.Select(r => r.ToString(bot, transform)).ToList();

            if (lines.Count > 0)
            {
                if (lines.Count < TotalLineCount)
                {
                    lines.Add(bot.Text.LinesSupressedFormat.FormatWith(new { Count = TotalLineCount - lines.Count }));
                }
            }

            return(lines);
        }
コード例 #15
0
        private string FormatAction(BotElement bot)
        {
            switch (Status)
            {
            case PullRequestStatus.Abandoned: return(bot.Text.Abandoned);

            case PullRequestStatus.Active: return(bot.Text.Reactivated);

            case PullRequestStatus.Completed: return(bot.Text.Completed);

            default:
                return($"updated status to {Status} for");
            }
        }
コード例 #16
0
        public override string ToString(BotElement bot, TextElement text, Func <string, string> transform)
        {
            var formatter = new
            {
                DisplayName = transform(DisplayName), RepoUri,
                ProjectName = transform(ProjectName),
                RepoName    = transform(RepoName),
                Pushed      = IsForcePush ? text.ForcePushed : text.Pushed,
                UserName    = transform(UserName),
                MappedUser  = bot.GetMappedUser(UniqueName)
            };

            return(text.PushFormat.FormatWith(formatter));
        }
コード例 #17
0
        public static Message CreateSlackMessage(IEnumerable <string> lines, BotElement bot, string channel, string color, bool asUser)
        {
            if (lines == null || !lines.Any())
            {
                return(null);
            }

            string header = lines.First();
            var    fields = from line in lines.Skip(1) select new AttachmentField()
            {
                Value = line, IsShort = false
            };

            return(CreateSlackMessage(header, fields, bot, channel, color, asUser));
        }
コード例 #18
0
        public static Slack.Message CreateSlackMessage(IEnumerable <string> lines, BotElement bot, string channel, string color)
        {
            if (lines == null || lines.Count() == 0)
            {
                return(null);
            }

            string header = lines.First();
            var    fields = from line in lines.Skip(1) select new AttachmentField()
            {
                Value = line, IsShort = false
            };

            return(CreateSlackMessage(header, fields.ToList(), bot, channel, color));
        }
コード例 #19
0
        public override IList <string> ToMessage(BotElement bot, Func <string, string> transform)
        {
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                DisplayName           = transform(DisplayName),
                ChangesetUrl,
                ChangesetId,
                Comment      = transform(Comment),
                UserName     = transform(UserName),
                ProjectLinks = FormatProjectLinks(bot, transform)
            };

            return(new[] { bot.Text.CheckinFormat.FormatWith(formatter) });
        }
コード例 #20
0
        public string ToString(BotElement bot, Func <string, string> transform)
        {
            string pattern = Type == GitRefType.Tag ? bot.Text.TagFormat : bot.Text.BranchFormat;
            var    sb      = new StringBuilder();

            if (Type == GitRefType.Branch && IsNew)
            {
                sb.Append("+");
            }
            sb.Append(Name);

            return(pattern.FormatWith(new
            {
                Name = transform(sb.ToString())
            }));
        }
コード例 #21
0
        public override IList <string> ToMessage(BotElement bot, TextElement text, Func <string, string> transform)
        {
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                DisplayName           = transform(DisplayName),
                UserName    = transform(UserName),
                ProjectName = transform(ProjectName),
                ProjectUrl,
                RepoUri,
                RepoName   = transform(RepoName),
                MappedUser = bot.GetMappedUser(UniqueName)
            };

            return(new[] { GetFormat(text).FormatWith(formatter) });
        }
コード例 #22
0
        public static Message CreateSlackMessage(IEnumerable <string> lines, BotElement bot, string channel, bool asUser)
        {
            if (lines == null || !lines.Any())
            {
                return(null);
            }
            var sb = new StringBuilder();

            sb.AppendLine(lines.First());
            foreach (var line in lines.Skip(1))
            {
                sb.Append(">");
                sb.AppendLine(line);
            }

            return(CreateSlackMessage(sb.ToString(), null, bot, channel, null, asUser));
        }
コード例 #23
0
        public override IList <string> ToMessage(BotElement bot, Func <string, string> transform)
        {
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                DisplayName           = transform(DisplayName),
                ChangesetUrl,
                ChangesetId,
                Comment     = transform(Comment),
                UserName    = transform(UserName),
                ProjectName = transform(ProjectName),
                ProjectUrl,
                CreatorUserName   = transform(CreatorUserName),
                MappedCreatorUser = bot.GetMappedUser(CreatorUniqueName),
                MappedUser        = bot.GetMappedUser(UniqueName)
            };

            return(new[] { bot.Text.ChangesetCommentFormat.FormatWith(formatter), Comment });
        }
コード例 #24
0
        public override IList <string> ToMessage(BotElement bot, Func <string, string> transform)
        {
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                DisplayName           = transform(DisplayName),
                ProjectName           = transform(ProjectName),
                RepoUri,
                RepoName = transform(RepoName),
                PrId,
                PrUrl,
                PrTitle          = transform(PrTitle),
                UserName         = transform(UserName),
                SourceBranchName = transform(SourceBranch.Name),
                TargetBranchName = transform(TargetBranch.Name)
            };

            return(new[] { bot.Text.PullRequestCreatedFormat.FormatWith(formatter) });
        }
コード例 #25
0
        public override IList <string> ToMessage(BotElement bot, TextElement text, Func <string, string> transform)
        {
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                DisplayName           = transform(DisplayName),
                ProjectName           = transform(ProjectName),
                RepoUri,
                RepoName = transform(RepoName),
                CommitId = transform(CommitId.ToHexString(Settings.HashLength)),
                CommitUri,
                Comment          = transform(Comment),
                UserName         = transform(UserName),
                PusherUserName   = transform(PusherUserName),
                MappedPusherUser = bot.GetMappedUser(PusherUniqueName),
                MappedUser       = bot.GetMappedUser(UniqueName)
            };

            return(new[] { text.CommitCommentFormat.FormatWith(formatter), Comment });
        }
コード例 #26
0
        public override IList <string> ToMessage(BotElement bot, TextElement text, Func <string, string> transform)
        {
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                ProjectName           = transform(ProjectName),
                ReleaseDefinition     = transform(ReleaseDefinition),
                ReleaseStatus         = transform(ReleaseStatus.ToString()),
                ReleaseUrl,
                ReleaseName          = transform(ReleaseName),
                ReleaseReason        = transform(ReleaseReason.ToString()),
                CreatedBy            = transform(CreatedByUniqueName),
                CreatedByDisplayName = transform(CreatedByDisplayName),
                DisplayName          = transform(CreatedByDisplayName),
                CreatedOn,
                UserName   = transform(UserName),
                MappedUser = bot.GetMappedUser(CreatedByUniqueName)
            };

            return(new[] { text.ReleaseCreatedFormat.FormatWith(formatter) });
        }
コード例 #27
0
        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")));
        }
コード例 #28
0
        public override IList <string> ToMessage(BotElement bot, Func <string, string> transform)
        {
            var lines     = new List <string>();
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                DisplayName           = transform(DisplayName),
                ProjectName           = transform(ProjectName),
                WiUrl,
                WiType = transform(WiType),
                WiId,
                WiTitle = transform(WiTitle),
                IsStateChanged,
                IsAssignmentChanged,
                AssignedTo           = transform(AssignedTo),
                State                = transform(State),
                UserName             = transform(UserName),
                Action               = FormatAction(bot),
                AssignedToUserName   = transform(AssignedToUserName),
                MappedAssignedToUser = bot.GetMappedUser(AssignedToUniqueName),
                MappedUser           = bot.GetMappedUser(UniqueName)
            };

            lines.Add(bot.Text.WorkItemchangedFormat.FormatWith(formatter));

            var searchType       = IsNew ? SearchFieldsType.Core : SearchFieldsType.Changed;
            var displayFieldsKey = IsNew ? "wiCreatedDisplayFields" : "wiChangedDisplayFields";
            var pattern          = IsNew ? "{name}: {newValue}" : "{name}: " + bot.Text.WorkItemFieldTransitionFormat;

            foreach (var fieldId in bot.GetCsvSetting(displayFieldsKey, Defaults.WorkItemFields))
            {
                var field = GetUnifiedField(fieldId, searchType);
                if (field != null)
                {
                    lines.Add(pattern.FormatWith(field));
                }
            }

            return(lines);
        }
コード例 #29
0
        public override IList <string> ToMessage(BotElement bot, TextElement text, Func <string, string> transform)
        {
            var formatter = new
            {
                TeamProjectCollection = transform(TeamProjectCollection),
                DisplayName           = transform(DisplayName),
                ProjectName           = transform(ProjectName),
                RepoUri,
                RepoName = transform(RepoName),
                PrId,
                PrUrl,
                PrTitle           = transform(PrTitle),
                UserName          = transform(UserName),
                SourceBranchName  = transform(SourceBranch.Name),
                TargetBranchName  = transform(TargetBranch.Name),
                CreatorUserName   = transform(CreatorUserName),
                MappedCreatorUser = bot.GetMappedUser(CreatorUniqueName),
                MappedUser        = bot.GetMappedUser(UniqueName)
            };

            return(new[] { text.PullRequestCommentFormat.FormatWith(formatter), Comment });
        }
コード例 #30
0
        private static string ChangeCountToString(BotElement bot, KeyValuePair <TfsGitChangeType, int> changeCount)
        {
            string format = null;

            switch (changeCount.Key)
            {
            case TfsGitChangeType.Add: format = bot.Text.ChangeCountAddFormat; break;

            case TfsGitChangeType.Delete: format = bot.Text.ChangeCountDeleteFormat; break;

            case TfsGitChangeType.Edit: format = bot.Text.ChangeCountEditFormat; break;

            case TfsGitChangeType.Rename: format = bot.Text.ChangeCountRenameFormat; break;

            case TfsGitChangeType.SourceRename: format = bot.Text.ChangeCountSourceRenameFormat; break;

            default:
                Logger.Log("Unknown combo: " + changeCount.Key);
                format = bot.Text.ChangeCountUnknownFormat;
                break;
            }
            return(format.FormatWith(new { Count = changeCount.Value }));
        }