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 })))); }
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); }
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); }
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()); }
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"))); }
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 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) }); }
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)); }
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) }); }
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); }
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"); } }
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)); }
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)); }
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)); }
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) }); }
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()) })); }
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) }); }
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)); }
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 }); }
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) }); }
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 }); }
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) }); }
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"))); }
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); }
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 }); }
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 })); }