Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team City Announcer #68

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Jabbot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
27 changes: 27 additions & 0 deletions TeamCityAnnouncer/ProjectModel.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
36 changes: 36 additions & 0 deletions TeamCityAnnouncer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
85 changes: 85 additions & 0 deletions TeamCityAnnouncer/TeamCityAnnouncer.cs
Original file line number Diff line number Diff line change
@@ -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<ProjectModel> MappedProjects = new List<ProjectModel>();

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);
}
}
}
}
}
74 changes: 74 additions & 0 deletions TeamCityAnnouncer/TeamCityAnnouncer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{577B79CF-B210-4ED1-8D1C-AF51BDAA2344}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TeamCityAnnouncer</RootNamespace>
<AssemblyName>TeamCityAnnouncer</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EasyHttp">
<HintPath>..\packages\EasyHttp.1.4.3.0\lib\net40\EasyHttp.dll</HintPath>
</Reference>
<Reference Include="JsonFx">
<HintPath>..\packages\JsonFx.2.0.1106.2610\lib\net40\JsonFx.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="TeamCitySharp">
<HintPath>..\packages\TeamCitySharp.0.3.1\lib\net40\TeamCitySharp.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ProjectModel.cs" />
<Compile Include="TeamCityAnnouncer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Jabbot\Jabbot.csproj">
<Project>{478BFCF7-9397-49A7-AFD4-060B6B749E77}</Project>
<Name>Jabbot</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
6 changes: 6 additions & 0 deletions TeamCityAnnouncer/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EasyHttp" version="1.4.3.0" />
<package id="JsonFx" version="2.0.1106.2610" />
<package id="TeamCitySharp" version="0.3.1" />
</packages>