Skip to content

Commit

Permalink
Add filtering on text in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kria committed Oct 30, 2016
1 parent 9128942 commit 3998ced
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 11 deletions.
3 changes: 3 additions & 0 deletions TfsNotificationRelay/Configuration/EventRuleElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public class EventRuleElement : ConfigurationElement, IKeyedConfigurationElement
[ConfigurationProperty("environmentStatuses")]
public string EnvironmentStatuses => (string)this["environmentStatuses"];

[ConfigurationProperty("text")]
public string Text => (string)this["text"];

public IEnumerable<EnvironmentStatus> EnvironmentStatusesEnums { get; private set; }

protected override void PostDeserialize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public override EventRuleElement GetRuleMatch(string collection, IEnumerable<Eve
&& collection.IsMatchOrNoPattern(r.TeamProjectCollection)
&& ProjectName.IsMatchOrNoPattern(r.TeamProject)
&& TeamNames.IsMatchOrNoPattern(r.TeamName)
&& SourcePath.IsMatchOrNoPattern(r.SourcePath));
&& SourcePath.IsMatchOrNoPattern(r.SourcePath)
&& Comment.IsMatchOrNoPattern(r.Text));

return rule;
}
Expand Down
3 changes: 2 additions & 1 deletion TfsNotificationRelay/Notifications/CheckinNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public override EventRuleElement GetRuleMatch(string collection, IEnumerable<Eve
&& collection.IsMatchOrNoPattern(r.TeamProjectCollection)
&& Projects.Keys.IsMatchOrNoPattern(r.TeamProject)
&& TeamNames.IsMatchOrNoPattern(r.TeamName)
&& SubmittedItems.IsMatchOrNoPattern(r.SourcePath));
&& SubmittedItems.IsMatchOrNoPattern(r.SourcePath)
&& Comment.IsMatchOrNoPattern(r.Text));

return rule;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public override EventRuleElement GetRuleMatch(string collection, IEnumerable<Eve
&& collection.IsMatchOrNoPattern(r.TeamProjectCollection)
&& ProjectName.IsMatchOrNoPattern(r.TeamProject)
&& RepoName.IsMatchOrNoPattern(r.GitRepository)
&& TeamNames.IsMatchOrNoPattern(r.TeamName));
&& TeamNames.IsMatchOrNoPattern(r.TeamName)
&& Comment.IsMatchOrNoPattern(r.Text));

return rule;
}
Expand Down
6 changes: 6 additions & 0 deletions TfsNotificationRelay/Notifications/GitPush/CommitRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace DevCore.TfsNotificationRelay.Notifications.GitPush
{
Expand Down Expand Up @@ -77,6 +78,11 @@ private string ChangeCountsToString(TextElement text, Dictionary<TfsGitChangeTyp

return string.Join(", ", counters.Where(c => c.Count > 0).Select(c => c.Format.FormatWith(new {c.Count })));
}

public override bool IsMatch(string pattern)
{
return Comment != null && Regex.IsMatch(Comment, pattern);
}
}

public enum CommitRowType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public override EventRuleElement GetRuleMatch(string collection, IEnumerable<Eve
&& _teamNames.IsMatchOrNoPattern(r.TeamName)
&& _repoName.IsMatchOrNoPattern(r.GitRepository)
&& (string.IsNullOrEmpty(r.GitBranch) || _refs.Any(n => Regex.IsMatch(n.Name, r.GitBranch)))
&& (string.IsNullOrEmpty(r.GitTag) || _refs.Any(n => Regex.IsMatch(n.Name, r.GitTag))));
&& (string.IsNullOrEmpty(r.GitTag) || _refs.Any(n => Regex.IsMatch(n.Name, r.GitTag)))
&& (string.IsNullOrEmpty(r.Text) || this.Any(row => row.IsMatch(r.Text))));

return rule;
}
Expand Down
5 changes: 5 additions & 0 deletions TfsNotificationRelay/Notifications/NotificationRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ public abstract class NotificationRow
protected readonly static SettingsElement Settings = TfsNotificationRelaySection.Instance.Settings;

public abstract string ToString(BotElement bot, TextElement text, Func<string, string> transform);

public virtual bool IsMatch(string pattern)
{
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public override IList<string> ToMessage(BotElement bot, TextElement text, Func<s

public override EventRuleElement GetRuleMatch(string collection, IEnumerable<EventRuleElement> eventRules)
{
var rule = GetRulesMatch(collection, eventRules).FirstOrDefault(r => r.Events.HasFlag(TfsEvents.PullRequestComment));

var rule = GetRulesMatch(collection, eventRules)
.FirstOrDefault(r => r.Events.HasFlag(TfsEvents.PullRequestComment) && Comment.IsMatchOrNoPattern(r.Text));

return rule;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public override EventRuleElement GetRuleMatch(string collection, IEnumerable<Eve
&& ProjectName.IsMatchOrNoPattern(r.TeamProject)
&& TeamNames.IsMatchOrNoPattern(r.TeamName)
&& WiType.IsMatchOrNoPattern(r.WorkItemType)
&& AreaPath.IsMatchOrNoPattern(r.AreaPath));
&& AreaPath.IsMatchOrNoPattern(r.AreaPath)
&& Comment.IsMatchOrNoPattern(r.Text));

return rule;
}
Expand Down
1 change: 1 addition & 0 deletions TfsNotificationRelay/TfsNotificationRelay.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<xs:attribute name="gitTag" type="xs:string" />
<xs:attribute name="environment" type="xs:string" />
<xs:attribute name="environmentStatuses" type="xs:string" />
<xs:attribute name="text" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
11 changes: 6 additions & 5 deletions TfsNotificationRelay/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
WorkItemCreated, WorkItemChanged, WorkItemComment, PullRequestCreated, PullRequestStatusUpdate, PullRequestReviewerVote,
GitCommitComment, PullRequestComment, ChangesetComment, ReleaseCreated, ReleaseEnvironmentCompleted, RepositoryRenamed, RepositoryDeleted, All
teamProjectCollection, teamProject, teamName, gitRepository, areaPath, workItemType, sourcePath and buildDefinition attributes take regex patterns.
teamProjectCollection, teamProject, teamName, text, gitRepository, gitBranch, gitTag, areaPath, workItemType, sourcePath,
buildDefinition, releaseDefinition and environment attributes take regex patterns.
workItemfields takes a comma-separated list of field reference names. See https://msdn.microsoft.com/en-us/library/ms194971.aspx
buildStatuses takes a comma-separated list of: None, InProgress, Succeeded, PartiallySucceeded, Failed, Stopped, NotStarted, All
releaseStatuses takes a comma separated list of: Succeeded, Rejected, Cancelled, All
For more info see the wiki at https://github.com/kria/TfsNotificationRelay/wiki
-->
<rule notify="true" events="All" teamProjectCollection="" teamProject="" teamName="" gitRepository="" gitBranch="" gitTag="" areaPath="" workItemType="" workItemfields="System.State, System.AssignedTo" sourcePath="" buildDefinition="" buildStatuses="All" releaseDefinition="" environment="" environmentStatuses="All" />
<rule notify="true" events="All" teamProjectCollection="" teamProject="" teamName="" text="" gitRepository="" gitBranch="" gitTag="" areaPath="" workItemType="" workItemfields="System.State, System.AssignedTo" sourcePath="" buildDefinition="" buildStatuses="All" releaseDefinition="" environment="" environmentStatuses="All" />
</eventRules>
</bot>

Expand Down Expand Up @@ -84,7 +85,7 @@
<add name="wiChangedDisplayFields" value="System.AreaPath, System.IterationPath, System.State, System.Reason, System.AssignedTo"/>
</botSettings>
<eventRules>
<rule notify="true" events="All" teamProjectCollection="" teamProject="" teamName="" gitRepository="" gitBranch="" gitTag="" areaPath="" workItemType="" workItemfields="System.State, System.AssignedTo" sourcePath="" buildDefinition="" buildStatuses="All" releaseDefinition="" environment="" environmentStatuses="All" />
<rule notify="true" events="All" teamProjectCollection="" teamProject="" teamName="" text="" gitRepository="" gitBranch="" gitTag="" areaPath="" workItemType="" workItemfields="System.State, System.AssignedTo" sourcePath="" buildDefinition="" buildStatuses="All" releaseDefinition="" environment="" environmentStatuses="All" />
</eventRules>
</bot>
-->
Expand All @@ -102,7 +103,7 @@
<add name="messageFormat" value="html" />
</botSettings>
<eventRules>
<rule notify="true" events="All" teamProjectCollection="" teamProject="" teamName="" gitRepository="" gitBranch="" gitTag="" areaPath="" workItemType="" workItemfields="System.State, System.AssignedTo" sourcePath="" buildDefinition="" buildStatuses="All" releaseDefinition="" environment="" environmentStatuses="All" />
<rule notify="true" events="All" teamProjectCollection="" teamProject="" teamName="" text="" gitRepository="" gitBranch="" gitTag="" areaPath="" workItemType="" workItemfields="System.State, System.AssignedTo" sourcePath="" buildDefinition="" buildStatuses="All" releaseDefinition="" environment="" environmentStatuses="All" />
</eventRules>
</bot>
-->
Expand All @@ -113,7 +114,7 @@
<add name="serviceEndpoint" value="net.pipe://localhost/BotService" />
</botSettings>
<eventRules>
<rule notify="true" events="All" teamProjectCollection="" teamProject="" teamName="" gitRepository="" gitBranch="" gitTag="" areaPath="" workItemType="" workItemfields="System.State, System.AssignedTo" sourcePath="" buildDefinition="" buildStatuses="All" releaseDefinition="" environment="" environmentStatuses="All" />
<rule notify="true" events="All" teamProjectCollection="" teamProject="" teamName="" text="" gitRepository="" gitBranch="" gitTag="" areaPath="" workItemType="" workItemfields="System.State, System.AssignedTo" sourcePath="" buildDefinition="" buildStatuses="All" releaseDefinition="" environment="" environmentStatuses="All" />
</eventRules>
</bot>
-->
Expand Down

0 comments on commit 3998ced

Please sign in to comment.