protected override void Update()
        {
            ConcurrentBag <Repository> populatedRepositories = new ConcurrentBag <Repository>();

            Parallel.ForEach(projectRepository.GetAll(), new ParallelOptions {
                MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
            }, project =>
            {
                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;
                }
                Parallel.ForEach(repositories, new ParallelOptions {
                    MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
                }, repo =>
                {
                    try
                    {
                        var populatedRepository = GetAsync.Fetch <TFSAdvanced.Updater.Models.Repositories.Repository>(requestData, $"{requestData.BaseAddress}/{project.Name}/_apis/git/repositories/{repo.name}?api=1.0").Result;

                        var repositoryDto = new Repository
                        {
                            Id             = populatedRepository.id,
                            Name           = populatedRepository.name,
                            PullRequestUrl = populatedRepository._links.pullRequests.href,
                            Url            = populatedRepository.remoteUrl,
                            Project        = new Project
                            {
                                Id   = populatedRepository.project.id,
                                Name = populatedRepository.project.name,
                                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")
                            {
                                repositoryDto.MinimumApproverCount = configuration.settings.minimumApproverCount;
                            }
                        }
                        populatedRepositories.Add(repositoryDto);
                    }
                    catch (Exception)
                    {
                    }
                });
            });
            var repositoryList = populatedRepositories.ToList();

            repositoryRepository.Update(repositoryList);
            updateStatusRepository.UpdateStatus(new UpdateStatus {
                LastUpdate = DateTime.Now, UpdatedRecords = repositoryList.Count, UpdaterName = nameof(RepositoryUpdater)
            });
        }
Beispiel #2
0
        protected override void Update()
        {
            DateTime startTime = DateTime.Now;

            base.Update();
            IList <TFSAdvanced.Models.DTO.PullRequest> stalePullRequests = PullRequestRepository.GetStale(startTime);

            if (stalePullRequests.Any())
            {
                Parallel.ForEach(stalePullRequests, new ParallelOptions {
                    MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
                }, pullRequest =>
                {
                    PullRequest updatedPullRequest = GetAsync.Fetch <PullRequest>(RequestData, pullRequest.ApiUrl).Result;
                    if (updatedPullRequest.status != "active")
                    {
                        PullRequestRepository.Remove(new[] { pullRequest });
                    }
                });
            }
        }
        protected override void Update()
        {
            var buildDefinitions = new ConcurrentBag <BuildDefinition>();

            Parallel.ForEach(projectRepository.GetAll(), new ParallelOptions {
                MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
            }, project =>
            {
                var definitions = GetAsync.FetchResponseList <TFSAdvanced.Updater.Models.Builds.BuildDefinition>(requestData, $"{requestData.BaseAddress}/{project.Name}/_apis/build/definitions?api=2.2").Result;
                if (definitions == null)
                {
                    logger.LogInformation($"Unable to get the definitiosn for the project {project.Name}");
                    return;
                }
                Parallel.ForEach(definitions, new ParallelOptions {
                    MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
                }, definition =>
                {
                    var populatedDefinition = GetAsync.Fetch <TFSAdvanced.Updater.Models.Builds.BuildDefinition>(requestData, definition.url).Result;
                    var repository          = repositoryRepository.GetById(populatedDefinition.repository.id);

                    buildDefinitions.Add(new BuildDefinition
                    {
                        DefaultBranch = populatedDefinition.repository.defaultBranch,
                        Folder        = populatedDefinition.path,
                        Id            = populatedDefinition.id,
                        Name          = populatedDefinition.name,
                        Url           = populatedDefinition._links.web.href,
                        Repository    = repository
                    });
                });
            });

            buildDefinitionRepository.Update(buildDefinitions);

            updateStatusRepository.UpdateStatus(new UpdateStatus {
                LastUpdate = DateTime.Now, UpdatedRecords = buildDefinitions.Count, UpdaterName = nameof(BuildDefinitionUpdater)
            });
        }
        protected override void Update()
        {
            var releases = new ConcurrentStack <ReleaseDefinition>();

            Parallel.ForEach(projectRepository.GetAll(), new ParallelOptions {
                MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
            }, project =>
            {
                var releaseDefinitions = GetAsync.FetchResponseList <Models.Releases.ReleaseDefinition>(requestData, $"{requestData.BaseReleaseManagerAddress}/{project.Id}/_apis/Release/definitions?api-version=3.0-preview.1").Result;
                if (releaseDefinitions != null)
                {
                    Parallel.ForEach(releaseDefinitions, new ParallelOptions {
                        MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
                    }, releaseDefinition =>
                    {
                        var populatedReleaseDefinition = GetAsync.Fetch <Models.Releases.ReleaseDefinition>(requestData, releaseDefinition.url).Result;
                        releases.Push(CreateReleaseDefinition(populatedReleaseDefinition));
                    });
                }
            });

            releaseDefinitionRepository.Update(releases);
        }
Beispiel #5
0
        protected override void Update()
        {
            var populatedRepositories = new ConcurrentBag <Repository>();

            Parallel.ForEach(projectRepository.GetAll(), new ParallelOptions {
                MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
            }, project =>
            {
                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", Logger).Result;
                if (repositories == null)
                {
                    return;
                }

                // policies are project scoped, so we only need to request once per project
                List <PolicyConfiguration> policyConfigurations = GetAsync.FetchResponseList <PolicyConfiguration>(requestData, $"{requestData.BaseAddress}/defaultcollection/{project.Id}/_apis/policy/configurations?api-version=2.0-preview.1", Logger).Result;

                Parallel.ForEach(repositories, new ParallelOptions {
                    MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
                }, repo =>
                {
                    try
                    {
                        TFSAdvanced.Updater.Models.Repositories.Repository populatedRepository = GetAsync.Fetch <TFSAdvanced.Updater.Models.Repositories.Repository>(requestData, $"{requestData.BaseAddress}/{project.Name}/_apis/git/repositories/{repo.name}?api=1.0").Result;

                        var repositoryDto = new Repository
                        {
                            Id             = populatedRepository.id,
                            Name           = populatedRepository.name,
                            PullRequestUrl = populatedRepository._links.pullRequests.href,
                            Url            = populatedRepository.remoteUrl,
                            Project        = new Project
                            {
                                Id   = populatedRepository.project.id,
                                Name = populatedRepository.project.name,
                                Url  = populatedRepository.project.url
                            }
                        };

                        foreach (PolicyConfiguration configuration in policyConfigurations)
                        {
                            if (configuration.type.id == MinimumReviewerPolicyId)
                            {
                                foreach (PolicyScope 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);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                });
            });
            List <Repository> repositoryList = populatedRepositories.ToList();

            repositoryRepository.Update(repositoryList);
            updateStatusRepository.UpdateStatus(new UpdateStatus {
                LastUpdate = DateTime.Now, UpdatedRecords = repositoryList.Count, UpdaterName = nameof(RepositoryUpdater)
            });
        }