From 1b18e03309414c9af52e6dfd5a3bd2918d946c50 Mon Sep 17 00:00:00 2001 From: Rodrigo Vidal Date: Mon, 16 Jan 2012 07:08:47 -0300 Subject: [PATCH 1/5] TeamCityAnnouncer project created and added TeamCitySharp reference --- TeamCityAnnouncer/Properties/AssemblyInfo.cs | 36 +++++++++++++ TeamCityAnnouncer/TeamCityAnnouncer.cs | 23 +++++++++ TeamCityAnnouncer/TeamCityAnnouncer.csproj | 54 ++++++++++++++++++++ TeamCityAnnouncer/packages.config | 6 +++ 4 files changed, 119 insertions(+) create mode 100644 TeamCityAnnouncer/Properties/AssemblyInfo.cs create mode 100644 TeamCityAnnouncer/TeamCityAnnouncer.cs create mode 100644 TeamCityAnnouncer/TeamCityAnnouncer.csproj create mode 100644 TeamCityAnnouncer/packages.config diff --git a/TeamCityAnnouncer/Properties/AssemblyInfo.cs b/TeamCityAnnouncer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1d964cc --- /dev/null +++ b/TeamCityAnnouncer/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TeamCityAnnouncer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("TeamCityAnnouncer")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("38f1adff-07f5-44f7-8743-b5ab198ea6ac")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TeamCityAnnouncer/TeamCityAnnouncer.cs b/TeamCityAnnouncer/TeamCityAnnouncer.cs new file mode 100644 index 0000000..d709dc9 --- /dev/null +++ b/TeamCityAnnouncer/TeamCityAnnouncer.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Jabbot.Sprockets.Core; +using Jabbot; + +namespace TeamCityAnnouncer +{ + public class TeamCityAnnouncer : IAnnounce + { + + public TimeSpan Interval + { + get { return TimeSpan.FromMinutes(10); } + } + + public void Execute(Bot bot) + { + + } + } +} diff --git a/TeamCityAnnouncer/TeamCityAnnouncer.csproj b/TeamCityAnnouncer/TeamCityAnnouncer.csproj new file mode 100644 index 0000000..0155c32 --- /dev/null +++ b/TeamCityAnnouncer/TeamCityAnnouncer.csproj @@ -0,0 +1,54 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + 38f1adff-07f5-44f7-8743-b5ab198ea6ac + Library + Properties + TeamCityAnnouncer + TeamCityAnnouncer + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TeamCityAnnouncer/packages.config b/TeamCityAnnouncer/packages.config new file mode 100644 index 0000000..51f8868 --- /dev/null +++ b/TeamCityAnnouncer/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From 25ec213abf1438438130a9531ef9b80c47622050 Mon Sep 17 00:00:00 2001 From: Rodrigo Vidal Date: Mon, 16 Jan 2012 07:51:49 -0300 Subject: [PATCH 2/5] TeamCity Announcer --- Jabbot.sln | 13 +++++ .../Extensions/TeamCitySharpEx.cs | 27 ++++++++++ TeamCityAnnouncer/TeamCityAnnouncer.cs | 52 +++++++++++++++++-- TeamCityAnnouncer/TeamCityAnnouncer.csproj | 24 ++++++++- 4 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 TeamCityAnnouncer/Extensions/TeamCitySharpEx.cs diff --git a/Jabbot.sln b/Jabbot.sln index 70a136f..457df48 100644 --- a/Jabbot.sln +++ b/Jabbot.sln @@ -66,6 +66,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CalculatorSprocket", "Exten EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GithubAnnouncements", "Extensions\GithubAnnouncements\GithubAnnouncements.csproj", "{9518C000-0F98-41B0-81E9-5E065CF5387E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamCityAnnouncer", "TeamCityAnnouncer\TeamCityAnnouncer.csproj", "{577B79CF-B210-4ED1-8D1C-AF51BDAA2344}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -247,6 +249,16 @@ Global {9518C000-0F98-41B0-81E9-5E065CF5387E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {9518C000-0F98-41B0-81E9-5E065CF5387E}.Release|Mixed Platforms.Build.0 = Release|Any CPU {9518C000-0F98-41B0-81E9-5E065CF5387E}.Release|x86.ActiveCfg = Release|Any CPU + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344}.Debug|Any CPU.Build.0 = Debug|Any CPU + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344}.Debug|x86.ActiveCfg = Debug|Any CPU + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344}.Release|Any CPU.ActiveCfg = Release|Any CPU + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344}.Release|Any CPU.Build.0 = Release|Any CPU + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -264,6 +276,7 @@ Global {1BCEA8B3-23C9-4087-9DC1-70EAC94D0787} = {7170D00A-149E-427F-A7F9-FBA91CE3F9D7} {6416F073-97F1-4DBB-B8D6-2011BE448D98} = {7170D00A-149E-427F-A7F9-FBA91CE3F9D7} {9518C000-0F98-41B0-81E9-5E065CF5387E} = {7170D00A-149E-427F-A7F9-FBA91CE3F9D7} + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344} = {7170D00A-149E-427F-A7F9-FBA91CE3F9D7} {3E8A88F3-737F-4F93-92EA-151B1FE3A44B} = {A3A6EC44-1F10-4427-98DC-CF13D11F8C79} EndGlobalSection EndGlobal diff --git a/TeamCityAnnouncer/Extensions/TeamCitySharpEx.cs b/TeamCityAnnouncer/Extensions/TeamCitySharpEx.cs new file mode 100644 index 0000000..a788db4 --- /dev/null +++ b/TeamCityAnnouncer/Extensions/TeamCitySharpEx.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TeamCitySharp; +using TeamCitySharp.DomainEntities; + +namespace TeamCityAnnouncer.Extensions +{ + static class TeamCitySharpEx + { + public static Build GetLastBuild(this TeamCityClient client, Project project) + { + var buildConfig = client.BuildConfigsByProjectId(project.Id).FirstOrDefault(); + var typeLocator = BuildTypeLocator.WithId(buildConfig.Id); + var buildLocator = BuildLocator.WithDimensions(typeLocator); + var builds = client.BuildsByBuildLocator(buildLocator); + return builds.FirstOrDefault(); + } + + public static DateTime FormattedStartDate(this Build build) + { + return DateTime.ParseExact(build.StartDate, "yyyyMMdd'T'HHmmss-ffff", null); + } + + } +} diff --git a/TeamCityAnnouncer/TeamCityAnnouncer.cs b/TeamCityAnnouncer/TeamCityAnnouncer.cs index d709dc9..9201b4c 100644 --- a/TeamCityAnnouncer/TeamCityAnnouncer.cs +++ b/TeamCityAnnouncer/TeamCityAnnouncer.cs @@ -1,23 +1,69 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using Jabbot.Sprockets.Core; using Jabbot; +using Jabbot.Sprockets.Core; +using TeamCitySharp; +using TeamCitySharp.DomainEntities; +using TeamCityAnnouncer.Extensions; namespace TeamCityAnnouncer { public class TeamCityAnnouncer : IAnnounce { + public const string ipAddressOrHostNameOfCCServer = "teamcity.codebetter.com"; + + public static readonly string[] Projects = { }; + public static Dictionary MappedProjects = new Dictionary(); public TimeSpan Interval { get { return TimeSpan.FromMinutes(10); } } + private void NotifyRooms(Bot bot, Project project, Build lastBuild) + { + foreach (var room in bot.Rooms) + { + bot.Say( + string.Format("CCNET Build Server: {0} / {1} - {2} ({3}) ", + project.WebUrl, + project.Name, + lastBuild.Status, + lastBuild.FormattedStartDate()), room); + } + } + public void Execute(Bot bot) { - + var client = new TeamCityClient(ipAddressOrHostNameOfCCServer); + client.Connect("teamcitysharpuser", "qwerty"); + var projects = client.AllProjects(); + + foreach (var project in projects) + { + if (Projects.Contains(project.Name)) + { + var mappedProject = MappedProjects.FirstOrDefault(x => x.Key.Name == project.Name); + if (mappedProject.Key == null) + { + var build = client.GetLastBuild(project); + MappedProjects.Add(project, build); + NotifyRooms(bot, project, build); + } + else + { + var mappedProjectBuild = mappedProject.Value; + var onlineProjectBuild = client.GetLastBuild(project); + if (mappedProjectBuild.StartDate != onlineProjectBuild.StartDate) + { + MappedProjects.Remove(mappedProject.Key); + MappedProjects.Add(project, onlineProjectBuild); + NotifyRooms(bot, project, onlineProjectBuild); + } + } + } + } } } } diff --git a/TeamCityAnnouncer/TeamCityAnnouncer.csproj b/TeamCityAnnouncer/TeamCityAnnouncer.csproj index 0155c32..7a7a332 100644 --- a/TeamCityAnnouncer/TeamCityAnnouncer.csproj +++ b/TeamCityAnnouncer/TeamCityAnnouncer.csproj @@ -5,7 +5,7 @@ AnyCPU 8.0.30703 2.0 - 38f1adff-07f5-44f7-8743-b5ab198ea6ac + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344} Library Properties TeamCityAnnouncer @@ -31,6 +31,12 @@ 4 + + ..\packages\EasyHttp.1.4.3.0\lib\net40\EasyHttp.dll + + + ..\packages\JsonFx.2.0.1106.2610\lib\net40\JsonFx.dll + @@ -38,11 +44,25 @@ + + ..\packages\TeamCitySharp.0.3.1\lib\net40\TeamCitySharp.dll + - + + + + + {478BFCF7-9397-49A7-AFD4-060B6B749E77} + Jabbot + + + + + +