protected override void Update() { ConcurrentBag <PullRequest> allPullRequests = new ConcurrentBag <PullRequest>(); Parallel.ForEach(repositoryRepository.GetAll(), new ParallelOptions { MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM }, repository => { if (string.IsNullOrEmpty(repository.PullRequestUrl)) { return; } var pullRequests = GetAsync.FetchResponseList <TFSAdvanced.Updater.Models.PullRequests.PullRequest>(requestData, repository.PullRequestUrl).Result; if (pullRequests == null) { return; } Parallel.ForEach(pullRequests, new ParallelOptions { MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM }, pullRequest => { try { CommitLink commitId = null; if (pullRequest.lastMergeCommit != null) { commitId = pullRequest.lastMergeCommit; } else if (pullRequest.lastMergeSourceCommit != null) { commitId = pullRequest.lastMergeSourceCommit; } if (commitId == null) { logger.LogWarning($"Unable to get last merge commit for the pullrequest ({pullRequest.pullRequestId}) {pullRequest.description}"); return; } if (string.IsNullOrEmpty(commitId.commitId)) { logger.LogWarning($"Unable to get the last commitID for the pull request ({pullRequest.pullRequestId}) {pullRequest.description}"); return; } var build = buildRepository.GetBuildBySourceVersion(repository, commitId.commitId); var pullRequestDto = BuildPullRequest(pullRequest, build); pullRequestDto.Repository = repository; pullRequestDto.Url = BuildPullRequestUrl(pullRequest, requestData.BaseAddress); pullRequestDto.RequiredReviewers = repository.MinimumApproverCount; foreach (var reviewer in pullRequest.reviewers) { // Container reviewers do not count if (reviewer.isContainer) { continue; } if (reviewer.vote == (int)Vote.Approved) { pullRequestDto.AcceptedReviewers++; } } allPullRequests.Add(pullRequestDto); } catch (Exception e) { logger.LogError("Error parsing pull request", e); } }); }); var pullRequestsList = allPullRequests.ToList(); pullRequestRepository.Update(pullRequestsList); updateStatusRepository.UpdateStatus(new UpdateStatus { LastUpdate = DateTime.Now, UpdatedRecords = pullRequestsList.Count, UpdaterName = nameof(PullRequestUpdater) }); }