@@ -57,23 +57,34 @@ protected async Task<LinkIndex> FetchLinkIndex(Cancel ctx)
5757 protected async Task < LinkIndexEntry > GetLinkIndexEntry ( string repository , Cancel ctx )
5858 {
5959 var linkIndex = await FetchLinkIndex ( ctx ) ;
60- if ( linkIndex . Repositories . TryGetValue ( repository , out var repositoryLinks ) )
61- return repositoryLinks . First ( ) . Value ;
62- throw new Exception ( $ "Repository { repository } not found in link index" ) ;
60+ if ( ! linkIndex . Repositories . TryGetValue ( repository , out var repositoryLinks ) )
61+ throw new Exception ( $ "Repository { repository } not found in link index" ) ;
62+ return GetNextContentSourceLinkIndexEntry ( repositoryLinks , repository ) ;
6363 }
6464
65- protected async Task < LinkReference > Fetch ( string repository , Cancel ctx )
65+ protected static LinkIndexEntry GetNextContentSourceLinkIndexEntry ( IDictionary < string , LinkIndexEntry > repositoryLinks , string repository )
66+ {
67+ var linkIndexEntry =
68+ ( repositoryLinks . TryGetValue ( "main" , out var link )
69+ ? link
70+ : repositoryLinks . TryGetValue ( "master" , out link ) ? link : null )
71+ ?? throw new Exception ( $ "Repository { repository } found in link index, but no main or master branch found") ;
72+ return linkIndexEntry ;
73+ }
74+
75+ protected async Task < LinkReference > Fetch ( string repository , string [ ] keys , Cancel ctx )
6676 {
6777 var linkIndex = await FetchLinkIndex ( ctx ) ;
6878 if ( ! linkIndex . Repositories . TryGetValue ( repository , out var repositoryLinks ) )
6979 throw new Exception ( $ "Repository { repository } not found in link index") ;
7080
71- if ( repositoryLinks . TryGetValue ( "main" , out var linkIndexEntry ) )
72- return await FetchLinkIndexEntry ( repository , linkIndexEntry , ctx ) ;
73- if ( repositoryLinks . TryGetValue ( "master" , out linkIndexEntry ) )
74- return await FetchLinkIndexEntry ( repository , linkIndexEntry , ctx ) ;
75- throw new Exception ( $ "Repository { repository } not found in link index" ) ;
81+ foreach ( var key in keys )
82+ {
83+ if ( repositoryLinks . TryGetValue ( key , out var linkIndexEntry ) )
84+ return await FetchLinkIndexEntry ( repository , linkIndexEntry , ctx ) ;
85+ }
7686
87+ throw new Exception ( $ "Repository found in link index however none of: '{ string . Join ( ", " , keys ) } ' branches found") ;
7788 }
7889
7990 protected async Task < LinkReference > FetchLinkIndexEntry ( string repository , LinkIndexEntry linkIndexEntry , Cancel ctx )
0 commit comments