99using Elastic . Documentation . Configuration . Assembler ;
1010using Elastic . Documentation . Diagnostics ;
1111using Elastic . Documentation . LinkIndex ;
12+ using Elastic . Documentation . Links ;
1213using Elastic . Markdown . IO ;
1314using Microsoft . Extensions . Logging ;
1415using ProcNet ;
@@ -25,7 +26,7 @@ public class AssemblerRepositorySourcer(ILoggerFactory logger, AssembleContext c
2526
2627 private RepositorySourcer RepositorySourcer => new ( logger , context . CheckoutDirectory , context . ReadFileSystem , context . Collector ) ;
2728
28- public IReadOnlyCollection < Checkout > GetAll ( )
29+ public CheckoutResult GetAll ( )
2930 {
3031 var fs = context . ReadFileSystem ;
3132 var repositories = Configuration . ReferenceRepositories . Values . Concat < Repository > ( [ Configuration . Narrative ] ) ;
@@ -43,11 +44,19 @@ public IReadOnlyCollection<Checkout> GetAll()
4344 } ;
4445 checkouts . Add ( checkout ) ;
4546 }
46-
47- return checkouts ;
47+ var linkRegistrySnapshotPath = Path . Combine ( context . CheckoutDirectory . FullName , CheckoutResult . LinkRegistrySnapshotFileName ) ;
48+ if ( ! fs . File . Exists ( linkRegistrySnapshotPath ) )
49+ throw new FileNotFoundException ( "Link-index snapshot not found. Run the clone-all command first." , linkRegistrySnapshotPath ) ;
50+ var linkRegistrySnapshotStr = File . ReadAllText ( linkRegistrySnapshotPath ) ;
51+ var linkRegistry = LinkRegistry . Deserialize ( linkRegistrySnapshotStr ) ;
52+ return new CheckoutResult
53+ {
54+ Checkouts = checkouts ,
55+ LinkRegistrySnapshot = linkRegistry
56+ } ;
4857 }
4958
50- public async Task < IReadOnlyCollection < Checkout > > CloneAll ( bool fetchLatest , Cancel ctx = default )
59+ public async Task < CheckoutResult > CloneAll ( bool fetchLatest , Cancel ctx = default )
5160 {
5261 _logger . LogInformation ( "Cloning all repositories for environment {EnvironmentName} using '{ContentSourceStrategy}' content sourcing strategy" ,
5362 PublishEnvironment . Name ,
@@ -91,7 +100,16 @@ await Task.Run(() =>
91100 checkouts . Add ( RepositorySourcer . CloneRef ( repo . Value , gitRef , fetchLatest ) ) ;
92101 } , c ) ;
93102 } ) . ConfigureAwait ( false ) ;
94- return checkouts ;
103+ await File . WriteAllTextAsync (
104+ Path . Combine ( context . CheckoutDirectory . FullName , CheckoutResult . LinkRegistrySnapshotFileName ) ,
105+ LinkRegistry . Serialize ( linkRegistry ) ,
106+ ctx
107+ ) ;
108+ return new CheckoutResult
109+ {
110+ Checkouts = checkouts ,
111+ LinkRegistrySnapshot = linkRegistry
112+ } ;
95113 }
96114}
97115
@@ -272,3 +290,10 @@ public void Write(Exception e) { }
272290
273291 public void Write ( ConsoleOut consoleOut ) { }
274292}
293+
294+ public record CheckoutResult
295+ {
296+ public static string LinkRegistrySnapshotFileName => "link-index.snapshot.json" ;
297+ public required LinkRegistry LinkRegistrySnapshot { get ; init ; }
298+ public required IReadOnlyCollection < Checkout > Checkouts { get ; init ; }
299+ }
0 commit comments