Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 13 additions & 1 deletion src/tooling/docs-assembler/Cli/RepositoryCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Documentation.Assembler.Navigation;
using Documentation.Assembler.Sourcing;
using Elastic.Documentation.Configuration.Assembler;
using Elastic.Documentation.Links;
using Elastic.Documentation.Tooling.Diagnostics.Console;
using Elastic.Markdown;
using Elastic.Markdown.Exporters;
Expand Down Expand Up @@ -106,7 +107,9 @@ public async Task<int> BuildAll(
}

var cloner = new AssemblerRepositorySourcer(logger, assembleContext);
var checkouts = cloner.GetAll().ToArray();
var checkoutResult = cloner.GetAll();
var checkouts = checkoutResult.Checkouts.ToArray();

if (checkouts.Length == 0)
throw new Exception("No checkouts found");

Expand All @@ -123,6 +126,15 @@ public async Task<int> BuildAll(
var builder = new AssemblerBuilder(logger, assembleContext, navigation, htmlWriter, pathProvider, historyMapper);
await builder.BuildAllAsync(assembleSources.AssembleSets, ctx);

if (checkoutResult.LinkRegistrySnapshot is { } linkRegistry)
Copy link
Member

Choose a reason for hiding this comment

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

Make this a method on AssemblerRepositorySourcer and use the read / write filesystems on AssemblerContext.

That way it will be easier to write tests for this at some point.

Copy link
Member Author

@reakaleek reakaleek May 27, 2025

Choose a reason for hiding this comment

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

09e1432

And here the git operations refactor I mentioned in our call: f39834d

{
await File.WriteAllTextAsync(
Path.Combine(assembleContext.OutputDirectory.FullName, "docs", CheckoutResult.LinkRegistrySnapshotFileName),
LinkRegistry.Serialize(linkRegistry),
ctx
);
}

var sitemapBuilder = new SitemapBuilder(navigation.NavigationItems, assembleContext.WriteFileSystem, assembleContext.OutputDirectory);
sitemapBuilder.Generate();

Expand Down
35 changes: 30 additions & 5 deletions src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Elastic.Documentation.Configuration.Assembler;
using Elastic.Documentation.Diagnostics;
using Elastic.Documentation.LinkIndex;
using Elastic.Documentation.Links;
using Elastic.Markdown.IO;
using Microsoft.Extensions.Logging;
using ProcNet;
Expand All @@ -25,7 +26,7 @@ public class AssemblerRepositorySourcer(ILoggerFactory logger, AssembleContext c

private RepositorySourcer RepositorySourcer => new(logger, context.CheckoutDirectory, context.ReadFileSystem, context.Collector);

public IReadOnlyCollection<Checkout> GetAll()
public CheckoutResult GetAll()
{
var fs = context.ReadFileSystem;
var repositories = Configuration.ReferenceRepositories.Values.Concat<Repository>([Configuration.Narrative]);
Expand All @@ -43,11 +44,19 @@ public IReadOnlyCollection<Checkout> GetAll()
};
checkouts.Add(checkout);
}

return checkouts;
var linkRegistrySnapshotPath = Path.Combine(context.CheckoutDirectory.FullName, CheckoutResult.LinkRegistrySnapshotFileName);
if (!fs.File.Exists(linkRegistrySnapshotPath))
throw new FileNotFoundException("Link-index snapshot not found. Run the clone-all command first.", linkRegistrySnapshotPath);
var linkRegistrySnapshotStr = File.ReadAllText(linkRegistrySnapshotPath);
var linkRegistry = LinkRegistry.Deserialize(linkRegistrySnapshotStr);
return new CheckoutResult
{
Checkouts = checkouts,
LinkRegistrySnapshot = linkRegistry
};
}

public async Task<IReadOnlyCollection<Checkout>> CloneAll(bool fetchLatest, Cancel ctx = default)
public async Task<CheckoutResult> CloneAll(bool fetchLatest, Cancel ctx = default)
{
_logger.LogInformation("Cloning all repositories for environment {EnvironmentName} using '{ContentSourceStrategy}' content sourcing strategy",
PublishEnvironment.Name,
Expand Down Expand Up @@ -91,7 +100,16 @@ await Task.Run(() =>
checkouts.Add(RepositorySourcer.CloneRef(repo.Value, gitRef, fetchLatest));
}, c);
}).ConfigureAwait(false);
return checkouts;
await File.WriteAllTextAsync(
Path.Combine(context.CheckoutDirectory.FullName, CheckoutResult.LinkRegistrySnapshotFileName),
LinkRegistry.Serialize(linkRegistry),
ctx
);
return new CheckoutResult
{
Checkouts = checkouts,
LinkRegistrySnapshot = linkRegistry
};
}
}

Expand Down Expand Up @@ -272,3 +290,10 @@ public void Write(Exception e) { }

public void Write(ConsoleOut consoleOut) { }
}

public record CheckoutResult
{
public static string LinkRegistrySnapshotFileName => "link-index.snapshot.json";
public required LinkRegistry LinkRegistrySnapshot { get; init; }
public required IReadOnlyCollection<Checkout> Checkouts { get; init; }
}
Loading