public static async Task <IReadOnlyList <Contribution> > Get( IReadOnlyCollection <CommitterGroup> committerGroups, IPullRequestService pullRequestService) { Guard.AgainstNullArgument(nameof(committerGroups), committerGroups); Guard.AgainstNullArgument(nameof(pullRequestService), pullRequestService); return ((await Task.WhenAll(committerGroups.SelectMany(group => @group.RepositoryList.Select(id => { log.InfoFormat("Getting pull requests for {@Repository}...", id); return pullRequestService.Get(id.Owner, id.Name).ContinueWith(task => { if (task.Exception != null) { log.ErrorException("Failed to get pull requests for {@Repository}.", task.Exception.InnerException, id); return Enumerable.Empty <PullRequest>(); } log.InfoFormat("Got pull requests for {@Repository}.", id); return task.Result; }); })))) .SelectMany(_ => _) .Select(pullRequest => new { pullRequest.Repository, Login = pullRequest.Creator, pullRequest.Created.LocalDateTime }) .Distinct() .GroupBy(contribution => new { Group = committerGroups.First(group => @group.RepositoryList.Contains(contribution.Repository)).Name, contribution.Login }) .Select(g => new Contribution(g.Key.Group, g.Key.Login, g.Sum(contribution => Score(contribution.LocalDateTime)))) .ToList()); }
public static async Task<IReadOnlyList<Contribution>> Get( IReadOnlyCollection<CommitterGroup> committerGroups, IPullRequestService pullRequestService) { Guard.AgainstNullArgument(nameof(committerGroups), committerGroups); Guard.AgainstNullArgument(nameof(pullRequestService), pullRequestService); return (await Task.WhenAll(committerGroups.SelectMany(group => @group.RepositoryList.Select(id => { log.InfoFormat("Getting pull requests for {@Repository}...", id); return pullRequestService.Get(id.Owner, id.Name).ContinueWith(task => { if (task.Exception != null) { log.ErrorException("Failed to get pull requests for {@Repository}.", task.Exception.InnerException, id); return Enumerable.Empty<PullRequest>(); } log.InfoFormat("Got pull requests for {@Repository}.", id); return task.Result; }); })))) .SelectMany(_ => _) .Select(pullRequest => new { pullRequest.Repository, Login = pullRequest.Creator, pullRequest.Created.LocalDateTime }) .Distinct() .GroupBy(contribution => new { Group = committerGroups.First(group => @group.RepositoryList.Contains(contribution.Repository)).Name, contribution.Login }) .Select(g => new Contribution(g.Key.Group, g.Key.Login, g.Sum(contribution => Score(contribution.LocalDateTime)))) .ToList(); }