@@ -22,7 +22,7 @@ public class AdoPipelineTriggerService
2222 private readonly string _adoBaseUrl ;
2323
2424 // Cache for repository IDs and branch policies to avoid redundant API calls
25- private readonly Dictionary < string , ( string id , bool isDisabled ) > _repositoryCache = [ ] ;
25+ private readonly Dictionary < string , AdoRepository > _repositoryCache = [ ] ;
2626 private readonly Dictionary < string , AdoBranchPolicyResponse > _branchPolicyCache = [ ] ;
2727
2828 public AdoPipelineTriggerService ( AdoApi adoApi , OctoLogger log , string adoBaseUrl )
@@ -103,21 +103,21 @@ public async Task<bool> IsPipelineRequiredByBranchPolicy(string adoOrg, string t
103103
104104 try
105105 {
106- var ( repositoryId , isRepositoryDisabled ) = await GetRepositoryIdAndStatus ( adoOrg , teamProject , repoName , repoId , pipelineId ) ;
106+ var repoInfo = await GetRepositoryIdAndStatus ( adoOrg , teamProject , repoName , repoId , pipelineId ) ;
107107
108- if ( string . IsNullOrEmpty ( repositoryId ) )
108+ if ( string . IsNullOrEmpty ( repoInfo . Id ) )
109109 {
110110 return false ;
111111 }
112112
113- if ( isRepositoryDisabled )
113+ if ( repoInfo . IsDisabled )
114114 {
115115 var repoIdentifier = repoName ?? repoId ;
116116 _log . LogInformation ( $ "Repository { adoOrg } /{ teamProject } /{ repoIdentifier } is disabled. Branch policy check skipped for pipeline { pipelineId } - will use default trigger configuration.") ;
117117 return false ;
118118 }
119119
120- return await CheckBranchPoliciesForPipeline ( adoOrg , teamProject , repositoryId , repoName , repoId , pipelineId ) ;
120+ return await CheckBranchPoliciesForPipeline ( adoOrg , teamProject , repoInfo . Id , repoName , repoId , pipelineId ) ;
121121 }
122122 catch ( Exception ex ) when ( ex is HttpRequestException or TaskCanceledException or JsonException or ArgumentException or InvalidOperationException )
123123 {
@@ -126,23 +126,23 @@ public async Task<bool> IsPipelineRequiredByBranchPolicy(string adoOrg, string t
126126 }
127127 }
128128
129- private async Task < ( string repositoryId , bool isDisabled ) > GetRepositoryIdAndStatus ( string adoOrg , string teamProject , string repoName , string repoId , int pipelineId )
129+ private async Task < AdoRepository > GetRepositoryIdAndStatus ( string adoOrg , string teamProject , string repoName , string repoId , int pipelineId )
130130 {
131131 if ( ! string . IsNullOrEmpty ( repoId ) )
132132 {
133133 _log . LogVerbose ( $ "Using repository ID from pipeline definition for branch policy check: { repoId } ") ;
134- var ( _ , disabled ) = await GetRepositoryInfoWithCache ( adoOrg , teamProject , repoId , repoName ) ;
135- return ( repoId , disabled ) ;
134+ var repoInfoById = await GetRepositoryInfoWithCache ( adoOrg , teamProject , repoId , repoName ) ;
135+ return new AdoRepository { Id = repoId , Name = repoName , IsDisabled = repoInfoById . IsDisabled } ;
136136 }
137137
138- var ( id , disabledStatus ) = await GetRepositoryInfoWithCache ( adoOrg , teamProject , null , repoName ) ;
139- if ( string . IsNullOrEmpty ( id ) )
138+ var repoInfoByName = await GetRepositoryInfoWithCache ( adoOrg , teamProject , null , repoName ) ;
139+ if ( string . IsNullOrEmpty ( repoInfoByName . Id ) )
140140 {
141141 _log . LogWarning ( $ "Repository ID not found for { adoOrg } /{ teamProject } /{ repoName } . Branch policy check cannot be performed for pipeline { pipelineId } .") ;
142- return ( null , false ) ;
142+ return new AdoRepository { Id = null , Name = repoName , IsDisabled = false } ;
143143 }
144144
145- return ( id , disabledStatus ) ;
145+ return repoInfoByName ;
146146 }
147147
148148 private async Task < bool > CheckBranchPoliciesForPipeline ( string adoOrg , string teamProject , string repositoryId , string repoName , string repoId , int pipelineId )
@@ -485,7 +485,7 @@ private bool HasTriggerType(JToken originalTriggers, string triggerType)
485485 /// <summary>
486486 /// Gets the repository information (ID and disabled status) with caching to avoid redundant API calls for the same repository.
487487 /// </summary>
488- private async Task < ( string id , bool isDisabled ) > GetRepositoryInfoWithCache ( string adoOrg , string teamProject , string repoId , string repoName )
488+ private async Task < AdoRepository > GetRepositoryInfoWithCache ( string adoOrg , string teamProject , string repoId , string repoName )
489489 {
490490 var identifier = ! string . IsNullOrEmpty ( repoId ) ? repoId : repoName ;
491491 var cacheKey = $ "{ adoOrg . ToUpper ( ) } /{ teamProject . ToUpper ( ) } /{ identifier . ToUpper ( ) } ";
@@ -508,13 +508,13 @@ private bool HasTriggerType(JToken originalTriggers, string triggerType)
508508
509509 if ( ! string . IsNullOrEmpty ( repositoryId ) )
510510 {
511- var info = ( repositoryId , isDisabled ) ;
512- _repositoryCache [ cacheKey ] = info ;
511+ var repoInfo = new AdoRepository { Id = repositoryId , Name = identifier , IsDisabled = isDisabled } ;
512+ _repositoryCache [ cacheKey ] = repoInfo ;
513513 _log . LogVerbose ( $ "Cached repository information (ID: { repositoryId } , Disabled: { isDisabled } ) for { adoOrg } /{ teamProject } /{ identifier } ") ;
514- return info ;
514+ return repoInfo ;
515515 }
516516
517- return ( null , false ) ;
517+ return new AdoRepository { Id = null , Name = identifier , IsDisabled = false } ;
518518 }
519519 catch ( HttpRequestException ex ) when ( ex . Message . Contains ( "404" ) )
520520 {
@@ -523,9 +523,9 @@ private bool HasTriggerType(JToken originalTriggers, string triggerType)
523523 // Log as verbose since the caller will log a more specific warning about the disabled repository
524524 // Return (null, true) to indicate repository ID is unknown but repository is disabled
525525 _log . LogVerbose ( $ "Repository { adoOrg } /{ teamProject } /{ identifier } returned 404 - likely disabled or not found.") ;
526- ( string id , bool isDisabled ) info = ( null , true ) ; // Mark as disabled with null ID since identifier may be a name
527- _repositoryCache [ cacheKey ] = info ;
528- return info ;
526+ var repoInfo = new AdoRepository { Id = null , Name = identifier , IsDisabled = true } ; // Mark as disabled with null ID since identifier may be a name
527+ _repositoryCache [ cacheKey ] = repoInfo ;
528+ return repoInfo ;
529529 }
530530 catch ( HttpRequestException ex )
531531 {
0 commit comments