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/ProjectModel.cs b/TeamCityAnnouncer/ProjectModel.cs new file mode 100644 index 0000000..f095337 --- /dev/null +++ b/TeamCityAnnouncer/ProjectModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace TeamCityAnnouncer +{ + public class ProjectModel + { + public string ProjectName { get; private set; } + public string ProjectId { get; private set; } + public string BuildConfigName { get; private set; } + public string LastBuildTime { get; private set; } + public string LastBuildStatus { get; private set; } + public string LastBuildStatusText { get; private set; } + + public ProjectModel(string projectName, string projectId, string buildConfigName, string lastBuildTime, string lastBuildStatus, string lastBuildStatusText) + { + this.ProjectName = projectName; + this.ProjectId = projectId; + this.BuildConfigName = buildConfigName; + this.LastBuildTime = DateTime.ParseExact(lastBuildTime, "yyyyMMdd'T'HHmmss-ffff", System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy HH:mm:ss"); + this.LastBuildStatus = lastBuildStatus; + this.LastBuildStatusText = lastBuildStatusText; + } + } +} 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..8f8d0b7 --- /dev/null +++ b/TeamCityAnnouncer/TeamCityAnnouncer.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Jabbot; +using Jabbot.Sprockets.Core; +using TeamCitySharp; + +namespace TeamCityAnnouncer +{ + public class TeamCityAnnouncer : IAnnounce + { + public const string IpAddressOrHostNameOfCCServer = "teamcity.codebetter.com"; + public static readonly string[] Projects = { }; + public static List MappedProjects = new List(); + + private TeamCityClient _client; + + public TimeSpan Interval + { + get { return TimeSpan.FromMinutes(10); } + } + + private void NotifyRooms(Bot bot, ProjectModel project) + { + foreach (var room in bot.Rooms) + { + bot.Say( + string.Format("TeamCity Build Server: {0} / {1} - {2} ({3}) ", + project.BuildConfigName, + project.ProjectName, + project.LastBuildTime, + project.LastBuildStatus), room); + } + } + + private void Update(Bot bot, ProjectModel project) + { + if (Projects.Contains(project.ProjectName)) + { + if (MappedProjects.All(x => x.ProjectName != project.ProjectName)) + { + MappedProjects.Add(project); + NotifyRooms(bot, project); + } + else + { + var mappedProject = MappedProjects.FirstOrDefault(x => x.ProjectName == project.ProjectName); + if (mappedProject != null) + { + if (project.LastBuildTime != mappedProject.LastBuildTime) + { + MappedProjects.Remove(mappedProject); + MappedProjects.Add(project); + NotifyRooms(bot, project); + } + } + } + } + } + + public void Execute(Bot bot) + { + if (string.IsNullOrWhiteSpace(IpAddressOrHostNameOfCCServer) || !Projects.Any()) return; + + _client = new TeamCityClient(IpAddressOrHostNameOfCCServer); + _client.Connect("teamcitysharpuser", "qwerty"); + var allProjects = _client.AllProjects(); + var allBuildConfigs = _client.AllBuildConfigs(); + + foreach (var currentProject in allProjects) + { + var buildConfigs = allBuildConfigs.Where(buildConfig => currentProject.Id == buildConfig.Project.Id); + + foreach (var currentBuildConfig in buildConfigs) + { + var build = _client.LastBuildByBuildConfigId(currentBuildConfig.Id); + + var project = new ProjectModel(currentProject.Name, currentProject.Id, currentBuildConfig.Name, build.StartDate, + build.Status, build.StatusText); + Update(bot, project); + } + } + } + } +} diff --git a/TeamCityAnnouncer/TeamCityAnnouncer.csproj b/TeamCityAnnouncer/TeamCityAnnouncer.csproj new file mode 100644 index 0000000..0487eb5 --- /dev/null +++ b/TeamCityAnnouncer/TeamCityAnnouncer.csproj @@ -0,0 +1,74 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {577B79CF-B210-4ED1-8D1C-AF51BDAA2344} + Library + Properties + TeamCityAnnouncer + TeamCityAnnouncer + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EasyHttp.1.4.3.0\lib\net40\EasyHttp.dll + + + ..\packages\JsonFx.2.0.1106.2610\lib\net40\JsonFx.dll + + + + + + + + + + ..\packages\TeamCitySharp.0.3.1\lib\net40\TeamCitySharp.dll + + + + + + + + + + {478BFCF7-9397-49A7-AFD4-060B6B749E77} + Jabbot + + + + + + + + + \ 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