Skip to content

Commit

Permalink
Fix desalinizing messages in Cruise control API.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikgolda committed Jun 5, 2019
1 parent e3c1f24 commit 27e2366
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Soloplan.WhatsON.CruiseControl/CruiseControlProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ protected override async Task ExecuteQuery(CancellationToken cancellationToken,
/// <returns>Appropriate <see cref="ObservationState"/>.</returns>
private static ObservationState CcStatusToObservationStatus(CruiseControlJob projectData)
{
if (projectData.LastBuildStatus == CcBuildStatus.Success && projectData.Messages.All(msg => msg.Kind != MessageKind.FailingTasks && msg.Kind != MessageKind.Breakers && msg.Kind != MessageKind.BuildAbortedBy))
if (projectData.LastBuildStatus == CcBuildStatus.Success && projectData.MessageList.Messages.All(msg => msg.Kind != MessageKind.FailingTasks && msg.Kind != MessageKind.Breakers && msg.Kind != MessageKind.BuildAbortedBy))
{
return ObservationState.Success;
}

if (projectData.LastBuildStatus == CcBuildStatus.Failure || projectData.LastBuildStatus == CcBuildStatus.Exception || projectData.Messages.Any(msg => msg.Kind != MessageKind.FailingTasks && msg.Kind != MessageKind.Breakers))
if (projectData.LastBuildStatus == CcBuildStatus.Failure || projectData.LastBuildStatus == CcBuildStatus.Exception || projectData.MessageList.Messages.Any(msg => msg.Kind != MessageKind.FailingTasks && msg.Kind != MessageKind.Breakers))
{
return ObservationState.Failure;
}
Expand Down Expand Up @@ -194,9 +194,9 @@ private CruiseControlStatus CreateStatus(CruiseControlJob job)

private static void SetCulprits(CruiseControlJob job, CruiseControlStatus result)
{
if (job.Messages != null)
if (job.MessageList?.Messages != null)
{
var breakers = job.Messages.Where(msg => msg.Kind == MessageKind.Breakers);
var breakers = job.MessageList.Messages.Where(msg => msg.Kind == MessageKind.Breakers);
foreach (var breakersLine in breakers)
{
foreach (var breaker in breakersLine.Text.Split(',').Select(brk => brk.Trim()).Where(brk => !string.IsNullOrEmpty(brk)))
Expand Down
4 changes: 2 additions & 2 deletions src/Soloplan.WhatsON.CruiseControl/Model/CruiseControlJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public enum CcBuildStatus
[XmlType(AnonymousType = true)]
public class CruiseControlJob
{
[XmlArrayItem("message", IsNullable = false)]
public List<Message> Messages { get; set; }
[XmlElement("messages", IsNullable = false)]
public MessageList MessageList { get; set; }

[XmlAttribute("name")]
public string Name { get; set; }
Expand Down
13 changes: 12 additions & 1 deletion src/Soloplan.WhatsON.CruiseControl/Model/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Soloplan.WhatsON.CruiseControl.Model

[System.SerializableAttribute]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[XmlType("message")]
public class Message
{
[XmlAttributeAttribute("text")]
Expand All @@ -23,11 +23,22 @@ public class Message

public enum MessageKind
{
[XmlEnum("NotDefined")]
NotDefined = 0,

[XmlEnum("Breakers")]
Breakers = 1,

[XmlEnum("Fixer")]
Fixer = 2,

[XmlEnum("FailingTasks")]
FailingTasks = 3,

[XmlEnum("BuildStatus")]
BuildStatus = 4,

[XmlEnum("BuildAbortedBy")]
BuildAbortedBy = 5,
}
}
18 changes: 18 additions & 0 deletions src/Soloplan.WhatsON.CruiseControl/Model/MessageList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MessageList.cs" company="Soloplan GmbH">
// Copyright (c) Soloplan GmbH. All rights reserved.
// Licensed under the MIT License. See License-file in the project root for license information.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Soloplan.WhatsON.CruiseControl.Model
{
using System.Xml.Serialization;

[XmlRoot(ElementName= "messages", Namespace = "", IsNullable = false)]
public class MessageList
{
[XmlElement("message")]
public Message[] Messages { get; set; }
}
}

0 comments on commit 27e2366

Please sign in to comment.