Skip to content

Commit

Permalink
Overhaul configuration system to handle new features.
Browse files Browse the repository at this point in the history
- Add support for multiple bots and channels.
- Refactor event handling.
- Add team project creation/deletion handler.
  • Loading branch information
kria committed Aug 31, 2014
1 parent 5249cf2 commit 6725eb3
Show file tree
Hide file tree
Showing 29 changed files with 942 additions and 1,175 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ Tfs2Slack is a plugin for Team Foundation Server 2013 that sends notifications t

## Features and TODO

- [x] Notify multiple Slack organizations and channels
- [x] Event type filtering
- [x] Configurable notification format
- [x] Link to events in TFS
- [ ] Multi-channel
- [ ] Team project/repository filtering

### Events

- [x] Build completion
- [x] Team project creation/deletion
- Git
- [x] Push
- [x] New branch/tag
Expand All @@ -31,10 +33,13 @@ Tfs2Slack is a plugin for Team Foundation Server 2013 that sends notifications t
## Installation

If you don't already have one, add an Incoming WebHooks integration under Configure Integrations in Slack.
Download the latest [release](https://github.com/kria/Tfs2Slack/releases) or clone and build the source yourself.
Open `DevCore.Tfs2Slack.dll.config` and set at least your full unique Webhook URL in `SlackWebhookUrl`. There are more setting and formats in there that should be somewhat self-explanatory.
Download the latest [release][0] or clone and build the source yourself.
Open `DevCore.Tfs2Slack.dll.config` and set at least your full unique Webhook URL in `slackWebhookUrl`. There are [more settings and formats][1] in there that should be somewhat self-explanatory.
Install the Tfs2Slack plugin by dropping `DevCore.Tfs2Slack.dll`, `DevCore.Tfs2Slack.dll.config` and `Newtonsoft.Json.dll` in *C:\Program Files\Microsoft Team Foundation Server 12.0\Application Tier\Web Services\bin\Plugins* on the server.

[0]: https://github.com/kria/Tfs2Slack/releases
[1]: https://github.com/kria/Tfs2Slack/blob/master/Tfs2Slack/app.config

## TFS 2013 version support

Because of a breaking API change in TFS 2013 Update 2, the plugin as is only works for TFS 2013 update 2 (and possibly later).
Expand Down
40 changes: 0 additions & 40 deletions Tfs2Slack/BuildHandler.cs

This file was deleted.

73 changes: 73 additions & 0 deletions Tfs2Slack/Configuration/BotElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Tfs2Slack - http://github.com/kria/Tfs2Slack
*
* Copyright (C) 2014 Kristian Adrup
*
* This file is part of Tfs2Slack.
*
* Tfs2Slack 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.
*/

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevCore.Tfs2Slack.Configuration
{
public class BotElement : ConfigurationElement
{
[ConfigurationProperty("name", IsRequired = true, IsKey = true)]
public string Name
{
get { return (string)this["name"]; }
}

[ConfigurationProperty("slackWebhookUrl")]
public string SlackWebhookUrl
{
get { return (string)this["slackWebhookUrl"]; }
}

[ConfigurationProperty("slackChannels", IsRequired = true)]
public string SlackChannels
{
get { return (string)this["slackChannels"]; }
}

[ConfigurationProperty("slackUsername")]
public string SlackUsername
{
get { return (string)this["slackUsername"]; }
}

[ConfigurationProperty("slackIconEmoji")]
public string SlackIconEmoji
{
get { return (string)this["slackIconEmoji"]; }
}

[ConfigurationProperty("slackIconUrl")]
public string SlackIconUrl
{
get { return (string)this["slackIconUrl"]; }
}

[ConfigurationProperty("slackColor")]
public string SlackColor
{
get { return (string)this["slackColor"]; }
}

[ConfigurationProperty("notifyOn")]
public TfsEvents NotifyOn
{
get { return (TfsEvents)this["notifyOn"]; }
}
}
}
49 changes: 49 additions & 0 deletions Tfs2Slack/Configuration/BotElementCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Tfs2Slack - http://github.com/kria/Tfs2Slack
*
* Copyright (C) 2014 Kristian Adrup
*
* This file is part of Tfs2Slack.
*
* Tfs2Slack 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.
*/

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevCore.Tfs2Slack.Configuration
{
public class BotElementCollection : ConfigurationElementCollection,
IEnumerable<BotElement>
{
protected override ConfigurationElement CreateNewElement()
{
return new BotElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((BotElement)element).Name;
}
public BotElement this[int index]
{
get { return (BotElement)BaseGet(index); }
}

public new IEnumerator<BotElement> GetEnumerator()
{
int count = base.Count;
for (int i = 0; i < count; i++)
{
yield return base.BaseGet(i) as BotElement;
}
}

}
}
42 changes: 42 additions & 0 deletions Tfs2Slack/Configuration/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Tfs2Slack - http://github.com/kria/Tfs2Slack
*
* Copyright (C) 2014 Kristian Adrup
*
* This file is part of Tfs2Slack.
*
* Tfs2Slack 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.
*/

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DevCore.Tfs2Slack.Configuration
{
public class ConfigurationHelper
{
public static T GetConfigurationSection<T>(Assembly assembly, string sectionName) where T : ConfigurationSection
{
ResolveEventHandler resolver = (s, a) => { return assembly; };
AppDomain.CurrentDomain.AssemblyResolve += resolver;

string configPath = new Uri(assembly.CodeBase).LocalPath + ".config";
var configuration = ConfigurationManager.OpenMappedExeConfiguration(
new ExeConfigurationFileMap() { ExeConfigFilename = configPath },
ConfigurationUserLevel.None);
var section = configuration.GetSection(sectionName) as T;

AppDomain.CurrentDomain.AssemblyResolve -= resolver;

return section;
}
}
}
49 changes: 49 additions & 0 deletions Tfs2Slack/Configuration/SettingsElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Tfs2Slack - http://github.com/kria/Tfs2Slack
*
* Copyright (C) 2014 Kristian Adrup
*
* This file is part of Tfs2Slack.
*
* Tfs2Slack 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.
*/

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevCore.Tfs2Slack.Configuration
{
public class SettingsElement : ConfigurationElement
{
[ConfigurationProperty("logfile")]
public string Logfile
{
get { return (string)this["logfile"]; }
}

[ConfigurationProperty("stripUserDomain")]
public bool StripUserDomain
{
get { return (bool)this["stripUserDomain"]; }
}

[ConfigurationProperty("commentMaxLength")]
public int CommentMaxLength
{
get { return (int)this["commentMaxLength"]; }
}

[ConfigurationProperty("maxLines")]
public int MaxLines
{
get { return (int)this["maxLines"]; }
}
}
}
32 changes: 32 additions & 0 deletions Tfs2Slack/Configuration/StringElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Tfs2Slack - http://github.com/kria/Tfs2Slack
*
* Copyright (C) 2014 Kristian Adrup
*
* This file is part of Tfs2Slack.
*
* Tfs2Slack 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.
*/

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevCore.Tfs2Slack.Configuration
{
public class StringElement : ConfigurationElement
{
[ConfigurationProperty("value")]
public string Value
{
get { return (string)this["value"]; }
set { this["value"] = value; }
}
}
}
Loading

0 comments on commit 6725eb3

Please sign in to comment.