From 27017833fd221be029737466faca8c22e53f584d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 23 Aug 2017 11:41:13 +0200 Subject: [PATCH 1/6] fixd rebase error --- .gitignore | 1 + BuildMonitor/BuildMonitor.csproj | 11 +-------- BuildMonitor/Content/Site.css | 4 ++++ .../Helpers/CustomBuildMonitorModelHandler.cs | 4 ++-- .../DefaultBuildMonitorModelHandler.cs | 24 ++++++++++++------- BuildMonitor/Models/Home/Build.cs | 2 ++ BuildMonitor/Views/Home/Index.cshtml | 2 +- BuildMonitor/Views/Shared/_BuildItem.cshtml | 1 + 8 files changed, 28 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 20b98aa..a267fb9 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ npm-debug.log *.ipr *.iws /.project +/packages \ No newline at end of file diff --git a/BuildMonitor/BuildMonitor.csproj b/BuildMonitor/BuildMonitor.csproj index 9767007..6822cec 100644 --- a/BuildMonitor/BuildMonitor.csproj +++ b/BuildMonitor/BuildMonitor.csproj @@ -213,16 +213,7 @@ - False - True - 50316 - / - http://localhost:64568/ - False - False - - - False + True diff --git a/BuildMonitor/Content/Site.css b/BuildMonitor/Content/Site.css index bc95011..c8e0017 100644 --- a/BuildMonitor/Content/Site.css +++ b/BuildMonitor/Content/Site.css @@ -56,9 +56,13 @@ html * { /* Build monitor --------------------------------------------------------------------------------- */ +.projectRow { + clear:both; +} .projectTitle { color: #777; margin-top: -12px; + display: inline-block; } .buildTitle { diff --git a/BuildMonitor/Helpers/CustomBuildMonitorModelHandler.cs b/BuildMonitor/Helpers/CustomBuildMonitorModelHandler.cs index 0232185..2cea9d1 100644 --- a/BuildMonitor/Helpers/CustomBuildMonitorModelHandler.cs +++ b/BuildMonitor/Helpers/CustomBuildMonitorModelHandler.cs @@ -64,8 +64,8 @@ private void AddBuilds(ref Project project, Group group) var buildStatusJsonString = RequestHelper.GetJson(url); buildStatusJson = JsonConvert.DeserializeObject(buildStatusJsonString ?? string.Empty); - build.Branch = buildStatusJson.branchName ?? "default"; - build.Status = GetBuildStatusForRunningBuild(build.Id); + build.Branch = (buildStatusJson != null) ? (buildStatusJson.branchName ?? "default") : "unknown"; + build.Status = GetBuildStatusForRunningBuild(build.Id); if (build.Status == BuildStatus.Running) { diff --git a/BuildMonitor/Helpers/DefaultBuildMonitorModelHandler.cs b/BuildMonitor/Helpers/DefaultBuildMonitorModelHandler.cs index 7618acf..f68f5c5 100644 --- a/BuildMonitor/Helpers/DefaultBuildMonitorModelHandler.cs +++ b/BuildMonitor/Helpers/DefaultBuildMonitorModelHandler.cs @@ -47,8 +47,8 @@ private void AddBuilds(ref Project project) var buildStatusJsonString = RequestHelper.GetJson(url); buildStatusJson = JsonConvert.DeserializeObject(buildStatusJsonString ?? string.Empty); - build.Branch = buildStatusJson.branchName ?? "default"; - build.Status = GetBuildStatusForRunningBuild(build.Id); + build.Branch = (buildStatusJson != null) ? (buildStatusJson.branchName ?? "default") : "unknown"; + build.Status = GetBuildStatusForRunningBuild(build.Id); if (build.Status == BuildStatus.Running) { @@ -58,6 +58,7 @@ private void AddBuilds(ref Project project) build.UpdatedBy = GetUpdatedBy(); build.LastRunText = GetLastRunText(); build.IsQueued = IsBuildQueued(build.Id); + build.StatusDescription = (string)buildStatusJson.statusText; if (build.Status == BuildStatus.Running) { @@ -100,23 +101,30 @@ private string GetUpdatedBy() { try { - if ((string)buildStatusJson.triggered.type == "user") + var triggerType = (string)buildStatusJson.triggered.type; + if (triggerType == "user") { return (string)buildStatusJson.triggered.user.name; } - else if ((string)buildStatusJson.triggered.type == "unknown") + + if (triggerType == "vcs" && buildStatusJson.lastChanges != null) { - return "TeamCity"; + var result = RequestHelper.GetJson(teamCityUrl + buildStatusJson.lastChanges.change[0].href); + var change = JsonConvert.DeserializeObject(result); + + return (string)change.user.name; } - else + + if (triggerType == "unknown") { - return "Unknown"; + return "TeamCity"; } } catch { - return "Unknown"; } + + return "Unknown"; } } } \ No newline at end of file diff --git a/BuildMonitor/Models/Home/Build.cs b/BuildMonitor/Models/Home/Build.cs index fec72a9..5bfceae 100644 --- a/BuildMonitor/Models/Home/Build.cs +++ b/BuildMonitor/Models/Home/Build.cs @@ -10,6 +10,8 @@ public class Build public string UpdatedBy { get; set; } public string LastRunText { get; set; } public bool IsQueued { get; set; } + public string StatusDescription { get; set; } + public string StatusText { diff --git a/BuildMonitor/Views/Home/Index.cshtml b/BuildMonitor/Views/Home/Index.cshtml index 32bd63c..d879504 100644 --- a/BuildMonitor/Views/Home/Index.cshtml +++ b/BuildMonitor/Views/Home/Index.cshtml @@ -10,7 +10,7 @@ continue; } -
+

▪▪▪ @project.Name ▪▪▪

@foreach (var build in project.Builds) diff --git a/BuildMonitor/Views/Shared/_BuildItem.cshtml b/BuildMonitor/Views/Shared/_BuildItem.cshtml index d966641..7fc637e 100644 --- a/BuildMonitor/Views/Shared/_BuildItem.cshtml +++ b/BuildMonitor/Views/Shared/_BuildItem.cshtml @@ -4,6 +4,7 @@

@Model.Name

@Model.StatusText

+

@Model.StatusDescription

Branch @Model.Branch @if (!string.IsNullOrWhiteSpace(Model.Progress)) From d997143533a92c5e99f142fd34650d81109f575d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Borgen=20T=C3=B8rnvall?= Date: Wed, 23 Aug 2017 12:25:15 +0200 Subject: [PATCH 2/6] added .vs to gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a267fb9..88a40f3 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,6 @@ npm-debug.log *.ipr *.iws /.project -/packages \ No newline at end of file +/packages +.vs/ + From 3509d95ce28c2d18351828836900d3884b2bebc5 Mon Sep 17 00:00:00 2001 From: armitv Date: Wed, 23 Aug 2017 12:56:13 +0200 Subject: [PATCH 3/6] checking in config --- BuildMonitor/Web.config | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BuildMonitor/Web.config b/BuildMonitor/Web.config index 17e0a2b..bfdfdb1 100644 --- a/BuildMonitor/Web.config +++ b/BuildMonitor/Web.config @@ -11,9 +11,9 @@ - - - + + + From 0e01c93b42b98197e31cf8768dfdf8b5f540c148 Mon Sep 17 00:00:00 2001 From: armitv Date: Wed, 23 Aug 2017 14:33:09 +0200 Subject: [PATCH 4/6] Adding Get Octopus data method --- BuildMonitor/BuildMonitor.csproj | 1 + BuildMonitor/Controllers/HomeController.cs | 15 +++++--- BuildMonitor/Helpers/OctopusHandler.cs | 40 ++++++++++++++++++++++ BuildMonitor/Web.config | 6 +++- 4 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 BuildMonitor/Helpers/OctopusHandler.cs diff --git a/BuildMonitor/BuildMonitor.csproj b/BuildMonitor/BuildMonitor.csproj index 6822cec..45a0f91 100644 --- a/BuildMonitor/BuildMonitor.csproj +++ b/BuildMonitor/BuildMonitor.csproj @@ -132,6 +132,7 @@ + diff --git a/BuildMonitor/Controllers/HomeController.cs b/BuildMonitor/Controllers/HomeController.cs index a162578..cefc0f5 100644 --- a/BuildMonitor/Controllers/HomeController.cs +++ b/BuildMonitor/Controllers/HomeController.cs @@ -9,12 +9,14 @@ namespace BuildMonitor.Controllers { public class HomeController : Controller { - private readonly IBuildMonitorModelHandler modelHandler; + private readonly IBuildMonitorModelHandler _modelHandler; + private readonly IOctopusHandler _octopusHandler; public HomeController() { - modelHandler = new DefaultBuildMonitorModelHandler(); + _modelHandler = new DefaultBuildMonitorModelHandler(); //modelHandler = new CustomBuildMonitorModelHandler(); + _octopusHandler = new OctopusHandler(); RequestHelper.Username = ConfigurationManager.AppSettings["teamcity_username"]; RequestHelper.Password = ConfigurationManager.AppSettings["teamcity_password"]; @@ -22,13 +24,18 @@ public HomeController() public ActionResult Index() { - var model = modelHandler.GetModel(); + var model = _modelHandler.GetModel(); return View(model); } + public string GetOctopus() + { + return _octopusHandler.GetJson(); + } + public JsonResult GetBuilds() { - var model = modelHandler.GetModel(); + var model = _modelHandler.GetModel(); var builds = model.Projects.SelectMany(p => p.Builds).ToList(); diff --git a/BuildMonitor/Helpers/OctopusHandler.cs b/BuildMonitor/Helpers/OctopusHandler.cs new file mode 100644 index 0000000..e5a8fc8 --- /dev/null +++ b/BuildMonitor/Helpers/OctopusHandler.cs @@ -0,0 +1,40 @@ +using System.Configuration; +using System.IO; +using System.Net; +using System.Web.Helpers; +using System.Web.Mvc; +using BuildMonitor.Models.Home; +using Newtonsoft.Json.Linq; + +namespace BuildMonitor.Helpers +{ + public class OctopusHandler : IOctopusHandler + { + public string GetJson() + { + return HttpGet(); + } + + public string HttpGet() + { + var octopusKey = ConfigurationManager.AppSettings["octopus_api_key"]; + var octopusUrl = ConfigurationManager.AppSettings["octopus_api_url"]; + + WebClient client = new WebClient(); + client.Headers.Add("X-Octopus-ApiKey", octopusKey); + Stream data = client.OpenRead(octopusUrl); + if (data == null) return" "; + StreamReader reader = new StreamReader(data); + string s = reader.ReadToEnd(); + data.Close(); + reader.Close(); + + return s; + } + } + + public interface IOctopusHandler + { + string GetJson(); + } +} \ No newline at end of file diff --git a/BuildMonitor/Web.config b/BuildMonitor/Web.config index bfdfdb1..f74dc62 100644 --- a/BuildMonitor/Web.config +++ b/BuildMonitor/Web.config @@ -19,7 +19,11 @@ - + + + + + From 1bebd7ba1764498b890949bae39b7e08ff283c37 Mon Sep 17 00:00:00 2001 From: Morten Kartevoll Date: Wed, 23 Aug 2017 16:13:15 +0200 Subject: [PATCH 5/6] Created necessary models for octopuspart --- BuildMonitor/BuildMonitor.csproj | 5 +++++ BuildMonitor/Controllers/HomeController.cs | 8 +++++++- BuildMonitor/Helpers/OctopusHandler.cs | 14 ++++++++++++++ BuildMonitor/Models/Home/MainMonitorViewMod.cs | 8 ++++++++ BuildMonitor/Models/Home/OctopusEnvironment.cs | 18 ++++++++++++++++++ BuildMonitor/Models/Home/OctopusItem.cs | 14 ++++++++++++++ .../Models/Home/OctopusMonitorViewModel.cs | 15 +++++++++++++++ BuildMonitor/Models/Home/OctopusProject.cs | 16 ++++++++++++++++ BuildMonitor/Views/Home/Index.cshtml | 4 ++-- 9 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 BuildMonitor/Models/Home/MainMonitorViewMod.cs create mode 100644 BuildMonitor/Models/Home/OctopusEnvironment.cs create mode 100644 BuildMonitor/Models/Home/OctopusItem.cs create mode 100644 BuildMonitor/Models/Home/OctopusMonitorViewModel.cs create mode 100644 BuildMonitor/Models/Home/OctopusProject.cs diff --git a/BuildMonitor/BuildMonitor.csproj b/BuildMonitor/BuildMonitor.csproj index 45a0f91..4bd6476 100644 --- a/BuildMonitor/BuildMonitor.csproj +++ b/BuildMonitor/BuildMonitor.csproj @@ -136,6 +136,11 @@ + + + + + diff --git a/BuildMonitor/Controllers/HomeController.cs b/BuildMonitor/Controllers/HomeController.cs index cefc0f5..5f8b22d 100644 --- a/BuildMonitor/Controllers/HomeController.cs +++ b/BuildMonitor/Controllers/HomeController.cs @@ -25,7 +25,13 @@ public HomeController() public ActionResult Index() { var model = _modelHandler.GetModel(); - return View(model); + var octoViewModel = _octopusHandler.GetModel(); + var mainModel = new MainMonitorViewMod() + { + BuildMonitor = model, + OctopusMonitor = octoViewModel + }; + return View(mainModel); } public string GetOctopus() diff --git a/BuildMonitor/Helpers/OctopusHandler.cs b/BuildMonitor/Helpers/OctopusHandler.cs index e5a8fc8..279d8c8 100644 --- a/BuildMonitor/Helpers/OctopusHandler.cs +++ b/BuildMonitor/Helpers/OctopusHandler.cs @@ -4,17 +4,30 @@ using System.Web.Helpers; using System.Web.Mvc; using BuildMonitor.Models.Home; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace BuildMonitor.Helpers { public class OctopusHandler : IOctopusHandler { + private dynamic json; public string GetJson() { return HttpGet(); } + public OctopusMonitorViewModel GetModel() + { + json = JsonConvert.DeserializeObject(GetJson()); + + /*var a = json.Projects[0].Name; + var b = json.bananasplit;*/ + var model = new OctopusMonitorViewModel(); + + return model; + } + public string HttpGet() { var octopusKey = ConfigurationManager.AppSettings["octopus_api_key"]; @@ -36,5 +49,6 @@ public string HttpGet() public interface IOctopusHandler { string GetJson(); + OctopusMonitorViewModel GetModel(); } } \ No newline at end of file diff --git a/BuildMonitor/Models/Home/MainMonitorViewMod.cs b/BuildMonitor/Models/Home/MainMonitorViewMod.cs new file mode 100644 index 0000000..312acaa --- /dev/null +++ b/BuildMonitor/Models/Home/MainMonitorViewMod.cs @@ -0,0 +1,8 @@ +namespace BuildMonitor.Models.Home +{ + public class MainMonitorViewMod + { + public BuildMonitorViewModel BuildMonitor { get; set; } + public OctopusMonitorViewModel OctopusMonitor { get; set; } + } +} \ No newline at end of file diff --git a/BuildMonitor/Models/Home/OctopusEnvironment.cs b/BuildMonitor/Models/Home/OctopusEnvironment.cs new file mode 100644 index 0000000..8b1bfa5 --- /dev/null +++ b/BuildMonitor/Models/Home/OctopusEnvironment.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; + +namespace BuildMonitor.Models.Home +{ + public class OctopusEnvironment + { + public String Name { get; set; } + public String Id { get; set; } + public List OctopusItems { get; set; } + + public OctopusEnvironment() + { + OctopusItems = new List(); + } + + } +} \ No newline at end of file diff --git a/BuildMonitor/Models/Home/OctopusItem.cs b/BuildMonitor/Models/Home/OctopusItem.cs new file mode 100644 index 0000000..641dd53 --- /dev/null +++ b/BuildMonitor/Models/Home/OctopusItem.cs @@ -0,0 +1,14 @@ +using System; + +namespace BuildMonitor.Models.Home +{ + public class OctopusItem + { + public String Id { get; set; } + public String ProjectId { get; set; } + public String EnvironmentId { get; set; } + public String State { get; set; } + public String ReleaseVersion { get; set; } + + } +} \ No newline at end of file diff --git a/BuildMonitor/Models/Home/OctopusMonitorViewModel.cs b/BuildMonitor/Models/Home/OctopusMonitorViewModel.cs new file mode 100644 index 0000000..490a6ba --- /dev/null +++ b/BuildMonitor/Models/Home/OctopusMonitorViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace BuildMonitor.Models.Home +{ + public class OctopusMonitorViewModel + { + public List OctopusProjects { get; set; } + + public OctopusMonitorViewModel() + { + OctopusProjects = new List(); + } + } +} \ No newline at end of file diff --git a/BuildMonitor/Models/Home/OctopusProject.cs b/BuildMonitor/Models/Home/OctopusProject.cs new file mode 100644 index 0000000..bfd2451 --- /dev/null +++ b/BuildMonitor/Models/Home/OctopusProject.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace BuildMonitor.Models.Home +{ + public class OctopusProject + { + public String Id { get; set; } + public String Name { get; set; } + public List OctopusEnvironments { get; set; } + public OctopusProject() + { + OctopusEnvironments = new List(); + } + } +} \ No newline at end of file diff --git a/BuildMonitor/Views/Home/Index.cshtml b/BuildMonitor/Views/Home/Index.cshtml index d879504..df1273a 100644 --- a/BuildMonitor/Views/Home/Index.cshtml +++ b/BuildMonitor/Views/Home/Index.cshtml @@ -1,9 +1,9 @@ -@model BuildMonitor.Models.Home.BuildMonitorViewModel +@model BuildMonitor.Models.Home.MainMonitorViewMod @{ ViewBag.Title = "Build Monitor"; } -@foreach (var project in Model.Projects) +@foreach (var project in Model.BuildMonitor.Projects) { if (project.Builds.Count == 0) { From 436a82b553dac6a6ce7be5deb9eddabae9557ecc Mon Sep 17 00:00:00 2001 From: Morten Kartevoll Date: Thu, 24 Aug 2017 13:05:23 +0200 Subject: [PATCH 6/6] Changed octopusitem, and populated the model --- BuildMonitor/Helpers/OctopusHandler.cs | 46 +++++++++++++++++-- .../Models/Home/OctopusEnvironment.cs | 8 +--- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/BuildMonitor/Helpers/OctopusHandler.cs b/BuildMonitor/Helpers/OctopusHandler.cs index 279d8c8..39c7e3b 100644 --- a/BuildMonitor/Helpers/OctopusHandler.cs +++ b/BuildMonitor/Helpers/OctopusHandler.cs @@ -1,5 +1,8 @@ -using System.Configuration; +using System; +using System.Collections.Generic; +using System.Configuration; using System.IO; +using System.Linq; using System.Net; using System.Web.Helpers; using System.Web.Mvc; @@ -20,11 +23,44 @@ public string GetJson() public OctopusMonitorViewModel GetModel() { json = JsonConvert.DeserializeObject(GetJson()); - - /*var a = json.Projects[0].Name; - var b = json.bananasplit;*/ var model = new OctopusMonitorViewModel(); + var projects = json.Projects; + foreach (var project in projects) + { + var octopusProject = new OctopusProject + { + Id = project.Id, + Name = project.Name + }; + + List environmentList = json.Environments.ToObject>(); + List currentEnvironmentList = project.EnvironmentIds.ToObject>(); + List itemList = json.Items.ToObject>(); + + octopusProject.OctopusEnvironments.AddRange(environmentList + .Where(e => currentEnvironmentList.Contains(e.Id.ToString())) + .Select(e => new OctopusEnvironment() + { + Id = e.Id, + Name = e.Name, + OctopusItem = itemList + .Select(i => new OctopusItem() + { + EnvironmentId = i.EnvironmentId, + Id = i.Id, + ProjectId = i.ProjectId, + State = i.State, + ReleaseVersion = i.ReleaseVersion + }) + .FirstOrDefault(i => (i.ProjectId.Equals(project.Id.ToString()) && i.EnvironmentId.Equals( e.Id.ToString()))) + })); + + model.OctopusProjects.Add(octopusProject); + } + + + return model; } @@ -36,7 +72,7 @@ public string HttpGet() WebClient client = new WebClient(); client.Headers.Add("X-Octopus-ApiKey", octopusKey); Stream data = client.OpenRead(octopusUrl); - if (data == null) return" "; + if (data == null) return " "; StreamReader reader = new StreamReader(data); string s = reader.ReadToEnd(); data.Close(); diff --git a/BuildMonitor/Models/Home/OctopusEnvironment.cs b/BuildMonitor/Models/Home/OctopusEnvironment.cs index 8b1bfa5..ab5407a 100644 --- a/BuildMonitor/Models/Home/OctopusEnvironment.cs +++ b/BuildMonitor/Models/Home/OctopusEnvironment.cs @@ -7,12 +7,6 @@ public class OctopusEnvironment { public String Name { get; set; } public String Id { get; set; } - public List OctopusItems { get; set; } - - public OctopusEnvironment() - { - OctopusItems = new List(); - } - + public OctopusItem OctopusItem { get; set; } } } \ No newline at end of file