Skip to content

Commit

Permalink
Move policy logic up one level to prevent repeat requests
Browse files Browse the repository at this point in the history
  • Loading branch information
hross committed Nov 17, 2017
1 parent cca5c08 commit a521056
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/TfsAdvanced.Updater/Models/Policy/PolicyType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public class PolicyType
{
public string displayName { get; set; }
public string id { get; set; }
}
}
1 change: 0 additions & 1 deletion src/TfsAdvanced.Updater/Models/Repositories/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ public class Repository
public string remoteUrl { get; set; }
public string url { get; set; }
public ProjectLinks _links { get; set; }
public IEnumerable<PolicyConfiguration> policyConfigurations { get; set; }
}
}
22 changes: 18 additions & 4 deletions src/TfsAdvanced.Updater/Tasks/RepositoryUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +39,10 @@ protected override void Update()
IList<TFSAdvanced.Updater.Models.Repositories.Repository> repositories = GetAsync.FetchResponseList<TFSAdvanced.Updater.Models.Repositories.Repository>(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<PolicyConfiguration>(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
Expand All @@ -56,13 +62,21 @@ protected override void Update()
Url = populatedRepository.project.url
}
};
var policyConfigurations = GetAsync.FetchResponseList<PolicyConfiguration>(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);
Expand Down

0 comments on commit a521056

Please sign in to comment.