private void FetchPullrequestsForRepository(List <PullRequest> resultingPrs, string repositoryName, string projectName) { var sw = Stopwatch.StartNew(); var totalTime = TimeSpan.FromMilliseconds(0); Parallel.ForEach(Input.Members, member => { _progressReporter.Report($"Looking for {member.DisplayName} pull requests in {projectName}/{repositoryName}"); var pullRequestsQuery = PullRequestQuery.New(Input.Query.StartDate) .WithFilter(IsPullRequestMatch) .WithParameter("creatorId", member.Id.ToString()) .WithParameter("status", "all"); var pullRequests = _vstsRepository.GetPullRequests(projectName, repositoryName, pullRequestsQuery) .GetAwaiter() .GetResult(); _logger.LogInformation("Fetched pull requests for '{Member}'. Time: {OperationTime}", member.Email, sw.Elapsed); totalTime += sw.Elapsed; sw.Restart(); _progressReporter.Report($"Found {pullRequests.Count()} pull requests from {member.DisplayName} in {projectName}/{repositoryName}.", GetProgressStep()); lock (_locker) { resultingPrs.AddRange(pullRequests); } }); sw.Stop(); _logger.LogInformation("Finished fetching pull requests for '{Repository}'. Time: {OperationTime}", repositoryName, totalTime); }
private async Task <IEnumerable <PullRequest> > GetPullRequests(VSTSRepository repositoryInfo, VSTSProject project) { var query = PullRequestQuery.New(Input.Query.StartDate) .WithFilter(p => p.CreationDate >= Input.Query.StartDate && p.CreationDate <= Input.Query.EndDate) .WithParameter("status", "all"); return(await _vstsRepository.GetPullRequests(project.Name, repositoryInfo.Name, query)); }
private void FetchPullrequests() { var isDisabled = _repository.GetFieldValue <Settings, bool>(_ => true, s => s.PullRequestsSettings.DisablePullRequestsJob); if (isDisabled) { _logger.LogWarning("Pull requests job is disabled in settings."); return; } var teamMembers = GetTeamMembers(); var profiles = _repository.GetAll <Profile>(); var repositories = _repository.GetAll <VSTSRepository>(); var projects = _repository.GetAll <VSTSProject>(); foreach (var teamMember in teamMembers) { var memberRepositoriesAndProjects = profiles.Where(p => p.Members.Contains(teamMember.Id)) .SelectMany(p => p.Repositories) .Select(r => { var repository = repositories.Single(ar => ar.Id == r); var project = projects.Single(p => p.Id == repository.Project); return(repository, project); }); var retrievedPullRequests = new List <PullRequest>(); foreach (var repositoryAndProject in memberRepositoriesAndProjects) { var query = PullRequestQuery.New(teamMember.LastPullRequestsFetchDate) .WithFilter(IsPullRequestMatch) .WithParameter("creatorId", teamMember.Id.ToString()) .WithParameter("status", "all"); var pullRequests = _vstsClient.GetPullRequests(repositoryAndProject.project.Name, repositoryAndProject.repository.Name, query) .GetAwaiter() .GetResult(); retrievedPullRequests.AddRange(pullRequests); } if (teamMember.PullRequests == null) { teamMember.PullRequests = Enumerable.Empty <PullRequest>(); } var newPullrequests = retrievedPullRequests.Except(teamMember.PullRequests); _logger.LogInformation("Found {newPullRequestsNumber} pullrequests for '{TeamMember}'", newPullrequests.Count(), teamMember.Email); teamMember.PullRequests = teamMember.PullRequests.Union(newPullrequests); teamMember.LastPullRequestsFetchDate = DateTime.UtcNow; _repository.CreateOrUpdateAsync(teamMember) .GetAwaiter() .GetResult(); } }