Skip to content

Commit

Permalink
Add ICommentNotification, truncation changes, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
kria committed Oct 18, 2015
1 parent e56c6e6 commit d97a6f2
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 13 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ TfsNotificationRelay is an extensible plugin for Team Foundation Server that sen
[![Build status](https://ci.appveyor.com/api/projects/status/f8tog2tftjbbotmr?svg=true)](https://ci.appveyor.com/project/kria/tfsnotificationrelay)

## Features

- [x] Notify multiple targets
- [x] Rule-based event filtering
- [x] Collection/project/repository regex filtering
Expand All @@ -14,13 +15,16 @@ TfsNotificationRelay is an extensible plugin for Team Foundation Server that sen

### Events

- [x] Build completion
- [x] XAML Build completion
- [x] vNext Build completion (*)
- [x] Build quality change
- [x] Work item update
- [x] Team project creation/deletion
- Git
- [x] Push
- [x] Pull request
- [x] Comment on commit (*)
- [x] Pull request (*)
- [x] Comment on pull request (*)
- [x] New repository
- [x] New branch/tag
- [x] Deleted branch/tag
Expand All @@ -29,6 +33,9 @@ TfsNotificationRelay is an extensible plugin for Team Foundation Server that sen
- [x] Force-push
- TFVC
- [x] Checkin
- [x] Comment on changeset (*)

*TFS 2015 only

## Screenshots

Expand Down
2 changes: 1 addition & 1 deletion TfsNotificationRelay.Slack/SlackNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Message ToSlackMessage(WorkItemChangedNotification notification, BotEleme
return SlackHelper.CreateSlackMessage(header, fields, bot, channel, bot.GetSetting("standardColor"), asUser);
}

public Message ToSlackMessage(WorkItemCommentNotification notification, BotElement bot, string channel, bool asUser)
public Message ToSlackMessage(ICommentNotification notification, BotElement bot, string channel, bool asUser)
{
string header = notification.ToMessage(bot, s => s).First();
var fields = new[] {
Expand Down
3 changes: 3 additions & 0 deletions TfsNotificationRelay/Configuration/SettingsElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class SettingsElement : ConfigurationElement
[ConfigurationProperty("commentMaxLength")]
public int CommentMaxLength => (int)this["commentMaxLength"];

[ConfigurationProperty("discussionCommentMaxLength")]
public int DiscussionCommentMaxLength => (int)this["discussionCommentMaxLength"];

[ConfigurationProperty("maxLines")]
public int MaxLines => (int)this["maxLines"];

Expand Down
2 changes: 1 addition & 1 deletion TfsNotificationRelay/EventHandlers/CheckinHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected override IEnumerable<INotification> CreateNotifications(TeamFoundation
ChangesetUrl = $"{baseUrl}_versionControl/changeset/{checkin.Changeset}",
ChangesetId = checkin.Changeset,
Projects = projects,
Comment = checkin.Comment,
Comment = TextHelper.Truncate(checkin.Comment, Settings.CommentMaxLength, true),
TeamNames = teamNames,
SubmittedItems = submittedItems
};
Expand Down
2 changes: 1 addition & 1 deletion TfsNotificationRelay/Notifications/GitPush/CommitRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override string ToString(BotElement bot, Func<string, string> transform)
Author = transform(Author),
AuthorName = transform(AuthorName),
AuthorEmail = transform(AuthorEmail),
Comment = transform(Comment.Truncate(Settings.CommentMaxLength))
Comment = transform(Comment.Truncate(Settings.CommentMaxLength, true))
}));

return sb.ToString();
Expand Down
20 changes: 20 additions & 0 deletions TfsNotificationRelay/Notifications/ICommentNotification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* TfsNotificationRelay - http://github.com/kria/TfsNotificationRelay
*
* Copyright (C) 2015 Kristian Adrup
*
* This file is part of TfsNotificationRelay.
*
* TfsNotificationRelay is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. See included file COPYING for details.
*/

namespace DevCore.TfsNotificationRelay.Notifications
{
public interface ICommentNotification : INotification
{
string Comment { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace DevCore.TfsNotificationRelay.Notifications
{
public class WorkItemCommentNotification : WorkItemNotification
public class WorkItemCommentNotification : WorkItemNotification, ICommentNotification
{
public string Comment { get; set; }
public string CommentHtml { get; set; }
Expand All @@ -40,8 +40,7 @@ public override IList<string> ToMessage(BotElement bot, Func<string, string> tra
Action = bot.Text.CommentedOn
};
lines.Add(bot.Text.WorkItemchangedFormat.FormatWith(formatter));

lines.Add(Comment);
lines.Add(TextHelper.Truncate(Comment, Settings.DiscussionCommentMaxLength));

return lines;
}
Expand Down
14 changes: 10 additions & 4 deletions TfsNotificationRelay/TextHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ namespace DevCore.TfsNotificationRelay
{
public static class TextHelper
{
public static string Truncate(this string text, int len)
public static string Truncate(this string text, int len, bool stopAtEol = false)
{
text = text.TrimEnd(Environment.NewLine.ToCharArray());
int pos = text.IndexOf('\n');
if (pos > 0 && pos <= len)
return text.Substring(0, pos);

int pos;
if (stopAtEol)
{
pos = text.IndexOf('\r');
if (pos == -1) pos = text.IndexOf('\n');
if (pos > 0 && pos <= len)
return text.Substring(0, pos);
}
if (text.Length <= len)
return text;
pos = text.LastIndexOf(' ', len);
Expand Down
1 change: 1 addition & 0 deletions TfsNotificationRelay/TfsNotificationRelay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<Compile Include="EventHandlers\RepositoryCreatedHandler.cs" />
<Compile Include="HtmlToText.cs" />
<Compile Include="Notifications\GitRef.cs" />
<Compile Include="Notifications\ICommentNotification.cs" />
<Compile Include="Notifications\PullRequestNotification.cs" />
<Compile Include="TextHelper.cs" />
<Compile Include="INotifier.cs" />
Expand Down
3 changes: 2 additions & 1 deletion TfsNotificationRelay/TfsNotificationRelay.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<xs:attribute name="logfile" type="xs:string" use="required" />
<xs:attribute name="stripUserDomain" type="xs:boolean" use="required" />
<xs:attribute name="commentMaxLength" type="xs:unsignedByte" use="required" />
<xs:attribute name="maxLines" type="xs:unsignedByte" use="required" />
<xs:attribute name="discussionCommentMaxLength" type="xs:unsignedInt" use="required" />
<xs:attribute name="maxLines" type="xs:unsignedInt" use="required" />
<xs:attribute name="hashLength" type="xs:unsignedByte" use="required" />
<xs:attribute name="identifyForcePush" type="xs:boolean" use="required" />
</xs:complexType>
Expand Down
1 change: 1 addition & 0 deletions TfsNotificationRelay/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
logfile=""
stripUserDomain="true"
commentMaxLength="72"
discussionCommentMaxLength="400"
maxLines="10"
hashLength="7"
identifyForcePush="true"
Expand Down

0 comments on commit d97a6f2

Please sign in to comment.