public async Task <IEnumerable <PullRequestThread> > GetThreads(string project, string repository, int pullRequestId) { var commentsUrl = VSTSApiUrl.Create(_configuration.Value.InstanceName) .ForPullRequests(project, repository) .WithSection(pullRequestId.ToString()) .WithSection("threads") .Build(ApiVersion); var commentsResponse = await _client.ExecuteGet <ValueBasedResponse <PullRequestThread> >(commentsUrl); if (commentsResponse == null) { _logger.LogWarning("Couldn't fetch comments from the server. Url: {APIUrl}", commentsUrl); return(Enumerable.Empty <PullRequestThread>()); } return(commentsResponse.Value); }
private async Task FetchPullRequests(string repositoryName, string projectName, List <PullRequest> pullrequests, PullRequestQuery query, int startFrom = 0) { var sw = Stopwatch.StartNew(); var pullRequestsUrlBuilder = VSTSApiUrl.Create(_configuration.Value.InstanceName) .ForPullRequests(projectName, repositoryName); foreach (var parameter in query.Parameters) { pullRequestsUrlBuilder.WithQueryParameter(parameter.Key, parameter.Value); } pullRequestsUrlBuilder.WithQueryParameter("$skip", startFrom.ToString()); var pullRequestsUrl = pullRequestsUrlBuilder.Build(ApiVersion); _logger.LogInformation($"Attempting to retrieve pull requests from {pullRequestsUrl}"); var prsResponse = await _client.ExecuteGet <PullRequestsResponse>(pullRequestsUrl); if (prsResponse == null) { _logger.LogWarning("Couldn't fetch pull requests from the server. Url: {APIUrl}", pullRequestsUrl); return; } _logger.LogInformation($"Retrieved {prsResponse.Value.Count()} PRs from '{repositoryName}' repository. Start position {startFrom}. Operation took: {sw.Elapsed}"); sw.Restart(); var prs = prsResponse.Value .Where(query.Filter) .ToList(); sw.Stop(); _logger.LogInformation($"Filtering PRs by range took {sw.Elapsed}. Count {prs.Count}"); pullrequests.AddRange(prs); if (prs.Any() && prs.Min(p => p.CreationDate) > query.FromDate) { await FetchPullRequests(repositoryName, projectName, pullrequests, query, startFrom + prs.Count); } }