diff --git a/src/TfsAdvanced.Updater/Models/Policy/PolicyType.cs b/src/TfsAdvanced.Updater/Models/Policy/PolicyType.cs index cbefc7f..14a7579 100644 --- a/src/TfsAdvanced.Updater/Models/Policy/PolicyType.cs +++ b/src/TfsAdvanced.Updater/Models/Policy/PolicyType.cs @@ -3,5 +3,6 @@ public class PolicyType { public string displayName { get; set; } + public string id { get; set; } } } diff --git a/src/TfsAdvanced.Updater/Models/Repositories/Repository.cs b/src/TfsAdvanced.Updater/Models/Repositories/Repository.cs index 23fdf1e..780f714 100644 --- a/src/TfsAdvanced.Updater/Models/Repositories/Repository.cs +++ b/src/TfsAdvanced.Updater/Models/Repositories/Repository.cs @@ -14,6 +14,5 @@ public class Repository public string remoteUrl { get; set; } public string url { get; set; } public ProjectLinks _links { get; set; } - public IEnumerable policyConfigurations { get; set; } } } \ No newline at end of file diff --git a/src/TfsAdvanced.Updater/Tasks/RepositoryUpdater.cs b/src/TfsAdvanced.Updater/Tasks/RepositoryUpdater.cs index b77e786..bc288f0 100644 --- a/src/TfsAdvanced.Updater/Tasks/RepositoryUpdater.cs +++ b/src/TfsAdvanced.Updater/Tasks/RepositoryUpdater.cs @@ -15,6 +15,8 @@ namespace TfsAdvanced.Updater.Tasks { public class RepositoryUpdater : UpdaterBase { + private const string MinimumReviewerPolicyId = "FA4E907D-C16B-4A4C-9DFA-4906E5D171DD"; + private readonly ProjectRepository projectRepository; private readonly RepositoryRepository repositoryRepository; private readonly UpdateStatusRepository updateStatusRepository; @@ -37,6 +39,10 @@ protected override void Update() IList repositories = GetAsync.FetchResponseList(requestData, $"{requestData.BaseAddress}/{project.Name}/_apis/git/repositories?api=1.0").Result; if (repositories == null) return; + + // policies are project scoped, so we only need to request once per project + var policyConfigurations = GetAsync.FetchResponseList(requestData, $"{requestData.BaseAddress}/defaultcollection/{project.Id}/_apis/policy/configurations?api-version=2.0-preview.1").Result; + Parallel.ForEach(repositories, new ParallelOptions {MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM}, repo => { try @@ -56,13 +62,21 @@ protected override void Update() Url = populatedRepository.project.url } }; - var policyConfigurations = GetAsync.FetchResponseList(requestData, $"{requestData.BaseAddress}/defaultcollection/{project.Id}/_apis/policy/configurations?api-version=2.0-preview.1").Result; - + foreach (var configuration in policyConfigurations) { - if (configuration.type.displayName == "Minimum number of reviewers") + if (configuration.type.id == MinimumReviewerPolicyId) { - repositoryDto.MinimumApproverCount = configuration.settings.minimumApproverCount; + foreach (var scope in configuration.settings.scope) + { + if (scope.repositoryId == repositoryDto.Id) + { + // NOTE: there could be multiple reviewer policies in a repo (per branch) + // so this may not be the correct level to store this setting + repositoryDto.MinimumApproverCount = configuration.settings.minimumApproverCount; + break; + } + } } } populatedRepositories.Add(repositoryDto);