Skip to content

Commit a5653eb

Browse files
committed
ADDED: Automation dashboard.
1 parent 4b939b1 commit a5653eb

23 files changed

+411
-16
lines changed

Diff for: AutomationMonitor.png

95.1 KB
Loading

Diff for: BuildMonitor.png

91.9 KB
Loading

Diff for: BuildMonitor/App_Data/Automation.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Settings>
3+
<Groups>
4+
<!-- TODO: Add your groups and jobs here, if you use the Automation Monitor dashboard. See the Automation.example.xml file for schema and samples. -->
5+
</Groups>
6+
</Settings>

Diff for: BuildMonitor/App_Data/Automation.example.config

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Settings>
3+
<Groups>
4+
<Group name="Backend">
5+
<Jobs>
6+
<Job id="TeamCity_Job_Id_1" text="Human friendly name to display" branch="optional-branch-name" environment="environment-name" />
7+
<Job id="TeamCity_Job_Id_2" text="Human friendly name to display" branch="optional-branch-name" environment="environment-name" />
8+
<Job id="TeamCity_Job_Id_3" text="Human friendly name to display" branch="optional-branch-name" environment="environment-name" />
9+
<Job id="TeamCity_Job_Id_4" text="Human friendly name to display" branch="optional-branch-name" environment="environment-name" />
10+
</Jobs>
11+
</Group>
12+
<Group name="Frontend">
13+
<Jobs>
14+
<Job id="TeamCity_Job_Id_5" text="Human friendly name to display" branch="optional-branch-name" environment="environment-name" />
15+
<Job id="TeamCity_Job_Id_6" text="Human friendly name to display" branch="optional-branch-name" environment="environment-name" />
16+
<Job id="TeamCity_Job_Id_7" text="Human friendly name to display" branch="optional-branch-name" environment="environment-name" />
17+
<Job id="TeamCity_Job_Id_8" text="Human friendly name to display" branch="optional-branch-name" environment="environment-name" />
18+
</Jobs>
19+
</Group>
20+
<Group name="Tests">
21+
<Jobs>
22+
<Job id="TeamCity_Job_Id_09" text="Human friendly name to display" branch="optional-branch-name" environment="environment-name" />
23+
<Job id="TeamCity_Job_Id_10" text="Human friendly name to display" branch="optional-branch-name" environment="environment-name" />
24+
</Jobs>
25+
</Group>
26+
</Groups>
27+
</Settings>

Diff for: BuildMonitor/App_Start/BundleConfig.cs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static void RegisterBundles(BundleCollection bundles)
99
bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"));
1010
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.validate*"));
1111
bundles.Add(new ScriptBundle("~/bundles/home").Include("~/Scripts/Project/common.js", "~/Scripts/Project/builds.js", "~/Scripts/Project/tests.js"));
12+
bundles.Add(new ScriptBundle("~/bundles/automation").Include("~/Scripts/Project/common.js", "~/Scripts/Project/automation.js"));
1213

1314
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include("~/Scripts/modernizr-*"));
1415
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include("~/Scripts/bootstrap.js", "~/Scripts/respond.js"));

Diff for: BuildMonitor/App_Start/SettingsConfig.cs

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
1-
using BuildMonitor.Models.Home.Settings;
2-
using System;
1+
using System;
32
using System.IO;
43
using System.Xml.Serialization;
4+
using AutomationSettings = BuildMonitor.Models.Automation.Settings.Settings;
5+
using HomeSettings = BuildMonitor.Models.Home.Settings.Settings;
56

67
namespace BuildMonitor
78
{
89
public static class SettingsConfig
910
{
1011
public static void Initialize()
12+
{
13+
LoadAutomationConfig();
14+
LoadBuildConfig();
15+
}
16+
17+
private static void LoadAutomationConfig()
18+
{
19+
string path = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/Automation.config";
20+
using (StreamReader reader = new StreamReader(path))
21+
{
22+
XmlSerializer serializer = new XmlSerializer(typeof(AutomationSettings));
23+
AutomationSettings.Current = (AutomationSettings)serializer.Deserialize(reader);
24+
}
25+
}
26+
27+
private static void LoadBuildConfig()
1128
{
1229
string path = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/Settings.xml";
13-
using (var reader = new StreamReader(path))
30+
using (StreamReader reader = new StreamReader(path))
1431
{
15-
var serializer = new XmlSerializer(typeof(Settings));
16-
Settings.Current = (Settings)serializer.Deserialize(reader);
17-
}
32+
XmlSerializer serializer = new XmlSerializer(typeof(HomeSettings));
33+
HomeSettings.Current = (HomeSettings)serializer.Deserialize(reader);
34+
}
1835
}
1936
}
2037
}

Diff for: BuildMonitor/BuildMonitor.csproj

+12
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<Compile Include="App_Start\FilterConfig.cs" />
131131
<Compile Include="App_Start\RouteConfig.cs" />
132132
<Compile Include="App_Start\SettingsConfig.cs" />
133+
<Compile Include="Controllers\AutomationController.cs" />
133134
<Compile Include="Controllers\TestsController.cs" />
134135
<Compile Include="Helpers\BuildMonitorModelHandlerBase.cs" />
135136
<Compile Include="Helpers\BuildsCache.cs" />
@@ -138,6 +139,13 @@
138139
<Compile Include="Helpers\RequestHelper.cs" />
139140
<Compile Include="Helpers\DefaultBuildMonitorModelHandler.cs" />
140141
<Compile Include="Helpers\TestsHelper.cs" />
142+
<Compile Include="Models\Automation\Settings\Group.cs" />
143+
<Compile Include="Models\Automation\Settings\Job.cs" />
144+
<Compile Include="Models\Automation\Settings\Settings.cs" />
145+
<Compile Include="Models\Automation\ViewModels\Gauge.cs" />
146+
<Compile Include="Models\Automation\ViewModels\Dashboard.cs" />
147+
<Compile Include="Models\Automation\ViewModels\Section.cs" />
148+
<Compile Include="Models\Automation\ViewModels\TestRunResultsResponse.cs" />
141149
<Compile Include="Models\Home\HiddenJob.cs" />
142150
<Compile Include="Models\Home\Settings\Group.cs" />
143151
<Compile Include="Models\Home\Settings\Job.cs" />
@@ -159,6 +167,8 @@
159167
<Compile Include="Properties\AssemblyInfo.cs" />
160168
</ItemGroup>
161169
<ItemGroup>
170+
<Content Include="App_Data\Automation.example.config" />
171+
<Content Include="App_Data\Automation.config" />
162172
<Content Include="App_Data\Settings.example.xml" />
163173
<Content Include="App_Data\Settings.xml" />
164174
<Content Include="Content\bootstrap.css" />
@@ -182,6 +192,7 @@
182192
<Content Include="Scripts\jquery.validate.unobtrusive.js" />
183193
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
184194
<Content Include="Scripts\Project\common.js" />
195+
<Content Include="Scripts\Project\automation.js" />
185196
<Content Include="Scripts\Project\tests.js" />
186197
<Content Include="Scripts\Project\builds.js" />
187198
<Content Include="Scripts\modernizr-2.6.2.js" />
@@ -204,6 +215,7 @@
204215
<Content Include="Views\Shared\_BuildItem.cshtml" />
205216
<Content Include="Web.AppSettings.config" />
206217
<Content Include="Views\Home\_Tests.cshtml" />
218+
<Content Include="Views\Automation\Index.cshtml" />
207219
</ItemGroup>
208220
<ItemGroup>
209221
<Folder Include="Views\Tests\" />

Diff for: BuildMonitor/Content/Site.css

+14
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ html * {
7171
margin-top: -5px;
7272
}
7373

74+
.automation-gauge .buildTitle {
75+
text-align: center;
76+
margin-bottom: 20px;
77+
}
78+
7479
.buildInfo {
7580
margin-top: -8px;
7681
margin-bottom: -3px;
@@ -87,6 +92,11 @@ html * {
8792
margin-bottom: 2px;
8893
}
8994

95+
.automation-gauge .buildInfoBranch {
96+
margin-top: 15px;
97+
text-align: center;
98+
}
99+
90100
.buildInfoProgressHighlight {
91101
-webkit-animation-name: pulsate; /* Chrome, Safari, Opera */
92102
-webkit-animation-duration: 1s; /* Chrome, Safari, Opera */
@@ -245,4 +255,8 @@ html * {
245255
height: 450px;
246256
float: left;
247257
opacity: 0.8;
258+
}
259+
260+
.pie-chart{
261+
height: 300px;
248262
}

Diff for: BuildMonitor/Controllers/AutomationController.cs

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Globalization;
5+
using System.Web.Mvc;
6+
using BuildMonitor.Helpers;
7+
using BuildMonitor.Models.Automation.Settings;
8+
using BuildMonitor.Models.Automation.ViewModels;
9+
using BuildMonitor.Models.Tests;
10+
11+
namespace BuildMonitor.Controllers
12+
{
13+
public class AutomationController : Controller
14+
{
15+
public ActionResult Index()
16+
{
17+
Dashboard dashboard = this.GetInitialViewModel();
18+
return this.View(dashboard);
19+
}
20+
21+
[HttpGet]
22+
public JsonResult TestRunResults(string buildConfigurationId)
23+
{
24+
// Get the raw data.
25+
TestRunResult testRunResult = TestsHelper.GetLatestRunResult(buildConfigurationId);
26+
27+
// Transform to the structure that is expected by the client.
28+
object[] testRunResultResponse =
29+
{
30+
new object[] { "Status", "Count" },
31+
new object[] { "Passed: " + testRunResult.PassedCount, testRunResult.PassedCount },
32+
new object[] { "Failed: " + testRunResult.FailedCount, testRunResult.FailedCount },
33+
new object[] { "Ignored: " + testRunResult.IgnoredCount, testRunResult.IgnoredCount }
34+
};
35+
36+
TestRunResultsResponse response = new TestRunResultsResponse
37+
{
38+
UpdatedText = "Updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
39+
TestResults = testRunResultResponse
40+
};
41+
42+
// Transform the result to JSON.
43+
return Json(response, JsonRequestBehavior.AllowGet);
44+
}
45+
46+
private Dashboard GetInitialViewModel()
47+
{
48+
string teamCityUrl = ConfigurationManager.AppSettings["teamcity_api_url"];
49+
50+
Dashboard dashboard = new Dashboard
51+
{
52+
Sections = new List<Section>()
53+
};
54+
55+
foreach (Group group in Settings.Current.Groups)
56+
{
57+
Section section = new Section
58+
{
59+
Title = group.Name,
60+
Gauges = new List<Gauge>()
61+
};
62+
63+
foreach (Job job in group.Jobs)
64+
{
65+
Gauge gauge = new Gauge
66+
{
67+
Title = job.Text,
68+
BuildConfigurationId = job.Id,
69+
DetailsUrl = String.Format(CultureInfo.InvariantCulture, "{0}/viewType.html?buildTypeId={1}", teamCityUrl, job.Id),
70+
Environment = job.Environment
71+
};
72+
section.Gauges.Add(gauge);
73+
}
74+
75+
dashboard.Sections.Add(section);
76+
}
77+
78+
return dashboard;
79+
}
80+
}
81+
}

Diff for: BuildMonitor/Helpers/TestsHelper.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,16 @@ public static TestRunResult[] GetHistoryRunResults()
4646
return result;
4747
}
4848

49+
4950
public static TestRunResult GetLatestRunResult()
5051
{
51-
BuildSummary latestBuildSummary = TestsHelper.GetLatestFinishedBuild(Settings.Current.Tests.Id);
52+
return TestsHelper.GetLatestRunResult(Settings.Current.Tests.Id);
53+
}
54+
55+
56+
public static TestRunResult GetLatestRunResult(string buildConfigurationId)
57+
{
58+
BuildSummary latestBuildSummary = TestsHelper.GetLatestFinishedBuild(buildConfigurationId);
5259
BuildDetails latestBuild = TestsHelper.GetBuildDetails(latestBuildSummary.Id);
5360

5461
return new TestRunResult

Diff for: BuildMonitor/Models/Automation/Settings/Group.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
using System.Xml.Serialization;
3+
4+
namespace BuildMonitor.Models.Automation.Settings
5+
{
6+
public class Group
7+
{
8+
[XmlAttribute("name")]
9+
public string Name { get; set; }
10+
11+
public List<Job> Jobs { get; set; }
12+
}
13+
}

Diff for: BuildMonitor/Models/Automation/Settings/Job.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Xml.Serialization;
2+
3+
namespace BuildMonitor.Models.Automation.Settings
4+
{
5+
public class Job
6+
{
7+
[XmlAttribute("id")]
8+
public string Id { get; set; }
9+
10+
[XmlAttribute("text")]
11+
public string Text { get; set; }
12+
13+
[XmlAttribute("branch")]
14+
public string Branch { get; set; }
15+
16+
[XmlAttribute("environment")]
17+
public string Environment { get; set; }
18+
}
19+
}

Diff for: BuildMonitor/Models/Automation/Settings/Settings.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace BuildMonitor.Models.Automation.Settings
4+
{
5+
public class Settings
6+
{
7+
public static Settings Current { get; set; }
8+
9+
public List<Group> Groups { get; set; }
10+
}
11+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace BuildMonitor.Models.Automation.ViewModels
4+
{
5+
public class Dashboard
6+
{
7+
public List<Section> Sections { get; set; }
8+
}
9+
}

Diff for: BuildMonitor/Models/Automation/ViewModels/Gauge.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace BuildMonitor.Models.Automation.ViewModels
2+
{
3+
public class Gauge
4+
{
5+
public string Title { get; set; }
6+
7+
public string BuildConfigurationId { get; set; }
8+
9+
public string Environment { get; set; }
10+
11+
public string DetailsUrl { get; set; }
12+
}
13+
}

Diff for: BuildMonitor/Models/Automation/ViewModels/Section.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace BuildMonitor.Models.Automation.ViewModels
4+
{
5+
public class Section
6+
{
7+
public string Title { get; set; }
8+
9+
public List<Gauge> Gauges { get; set; }
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace BuildMonitor.Models.Automation.ViewModels
2+
{
3+
public class TestRunResultsResponse
4+
{
5+
public object[] TestResults { get; set; }
6+
7+
public string UpdatedText { get; set; }
8+
}
9+
}

0 commit comments

Comments
 (0)