Skip to content
Merged
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
5 changes: 5 additions & 0 deletions source/Calamari.Contracts/ArgoCD/FileHash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System;

namespace Octopus.Calamari.Contracts.ArgoCD;

public record FileHash(string FilePath, string Hash);
5 changes: 5 additions & 0 deletions source/Calamari.Contracts/ArgoCD/FileJsonPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System;

namespace Octopus.Calamari.Contracts.ArgoCD;

public record FileJsonPatch(string FilePath, string JsonPatch);
18 changes: 18 additions & 0 deletions source/Calamari.Contracts/ArgoCD/ServiceMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Octopus.Calamari.Contracts.ArgoCD;

public static class ServiceMessages
{
public static class ArgoCDFilesUpdated
{
public const string Name = "argocd-files-updated";

public static class Attributes
{
public const string GatewayId = "gatewayId";
public const string ApplicationName = "applicationName";
public const string Sources = "sources";
}
}
}
10 changes: 10 additions & 0 deletions source/Calamari.Contracts/ArgoCD/SourceFileChanges.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Octopus.Calamari.Contracts.ArgoCD;

public record SourceFileChanges(
string? CommitSha,
DateTimeOffset? CommitTimestamp,
int SourceIndex,
List<FileHash> ReplacedFiles,
List<FileJsonPatch> PatchedFiles);
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Calamari.Testing.Helpers;
using FluentAssertions;
using NUnit.Framework;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.Tests.ArgoCD
{
Expand Down
36 changes: 18 additions & 18 deletions source/Calamari/ArgoCD/ArgoCDFilesUpdatedReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.ServiceMessages;
using Calamari.Kubernetes;
using ArgoCDFilesUpdatedAttributes = Calamari.Kubernetes.SpecialVariables.ServiceMessages.ArgoCDFilesUpdated.Attributes;
using Octopus.Calamari.Contracts.ArgoCD;
using ArgoCDFilesUpdatedAttributes = Octopus.Calamari.Contracts.ArgoCD.ServiceMessages.ArgoCDFilesUpdated.Attributes;

namespace Calamari.ArgoCD
{
Expand All @@ -34,33 +35,32 @@ public void ReportFilesUpdated(GitCommitParameters gitCommitParameters, IReadOnl
{
{ ArgoCDFilesUpdatedAttributes.GatewayId, appResult.GatewayId },
{ ArgoCDFilesUpdatedAttributes.ApplicationName, appResult.ApplicationName.Value },
{ ArgoCDFilesUpdatedAttributes.Sources, JsonSerializer.Serialize(ConvertPathsToPosix(appResult.TrackedSourceDetails)) }
{ ArgoCDFilesUpdatedAttributes.Sources, JsonSerializer.Serialize(appResult.TrackedSourceDetails.Select(MapSource).ToList()) }
};

var message = new ServiceMessage(
SpecialVariables.ServiceMessages.ArgoCDFilesUpdated.Name,
ServiceMessages.ArgoCDFilesUpdated.Name,
parameters);

log.WriteServiceMessage(message);
}
}

List<TrackedSourceDetail> ConvertPathsToPosix(List<TrackedSourceDetail> inputs)
static SourceFileChanges MapSource(TrackedSourceDetail trackedSourceDetail)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decouple the service message source details from the TrackedSourceDetail (we will add more stuff to TrackedSourceDetail in a later PR)

{
return inputs.Select(usd => usd with
{
ReplacedFiles = usd.ReplacedFiles.Select(rf => rf with
{
FilePath = rf.FilePath.EnsurePosixDirectorySeparator()
})
.ToList(),
PatchedFiles = usd.PatchedFiles.Select(pf => pf with
{
FilePath = pf.FilePath.EnsurePosixDirectorySeparator()
})
.ToList()
})
.ToList();
return new SourceFileChanges(
trackedSourceDetail.CommitSha,
trackedSourceDetail.CommitTimestamp,
trackedSourceDetail.SourceIndex,
trackedSourceDetail.ReplacedFiles.Select(f => f with
{
FilePath = f.FilePath.EnsurePosixDirectorySeparator()
}).ToList(),
trackedSourceDetail.PatchedFiles.Select(f => f with
{
FilePath = f.FilePath.EnsurePosixDirectorySeparator()
}).ToList()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Calamari.Common.Plumbing.Extensions;
using Calamari.Common.Plumbing.FileSystem;
using Calamari.Common.Plumbing.Logging;
using Octopus.Calamari.Contracts.ArgoCD;
using Octopus.CoreUtilities.Extensions;

namespace Calamari.ArgoCD.Conventions.ManifestTemplating;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable enable
using System;
using System.Collections.Generic;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.ArgoCD.Conventions.ManifestTemplating;

Expand Down
1 change: 1 addition & 0 deletions source/Calamari/ArgoCD/Conventions/SourceUpdateResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using Calamari.ArgoCD.Git;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.ArgoCD.Conventions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Calamari.Common.Plumbing.FileSystem;
using Calamari.Common.Plumbing.Logging;
using Calamari.Kubernetes.Patching.JsonPatch;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.ArgoCD.Conventions.UpdateImageTag;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Calamari.Common.Plumbing.Logging;
using Calamari.Kubernetes.Patching;
using Calamari.Kubernetes.Patching.JsonPatch;
using Octopus.Calamari.Contracts.ArgoCD;
using YamlDotNet.RepresentationModel;

namespace Calamari.ArgoCD.Conventions.UpdateImageTag;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.ArgoCD.Conventions.UpdateImageTag;

Expand Down
5 changes: 1 addition & 4 deletions source/Calamari/ArgoCD/ProcessApplicationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
using System.Collections.Generic;
using System.Linq;
using Calamari.ArgoCD.Models;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.ArgoCD
{
public record FileHash(string FilePath, string Hash);

public record FileJsonPatch(string FilePath, string JsonPatch);

public record TrackedSourceDetail(
string? CommitSha,
DateTimeOffset? CommitTimestamp,
Expand Down
12 changes: 0 additions & 12 deletions source/Calamari/Kubernetes/SpecialVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,6 @@ public static class ManifestApplied
public const string ManifestAttribute = "manifest";
public const string NamespaceAttribute = "ns";
}

public static class ArgoCDFilesUpdated
{
public const string Name = "argocd-files-updated";

public static class Attributes
{
public const string GatewayId = "gatewayId";
public const string ApplicationName = "applicationName";
public const string Sources = "sources";
}
}
}
}
}