lvermeulen / Bitbucket.Cloud.Net

C# client for Atlassian Bitbucket Cloud
MIT License
13 stars 19 forks source link

Paging for GetRepositoryCommitsAsync does not seem to work #2

Closed BjartN closed 4 years ago

BjartN commented 4 years ago

The call await client.GetRepositoryCommitsAsync(workspace, repoSlug, 20) gives the same page 20 times. (I am using the version 1.0.0 Nuget package)

lvermeulen commented 4 years ago

Do you have a repository on which I can reproduce this?

BjartN commented 4 years ago

I don't at the moment. This piece of code seems to be iterating over "numPages" without ever using the value of it. I'm assuming this is the problem.

Hacking it by adding "queryParamValues["page"] = numPages;" in the while loop would perhaps fix it.

` private async Task<IEnumerable> GetPagedResultsAsync(int? maxPages, IDictionary<string, object> queryParamValues, Func<IDictionary<string, object>, Task<PagedResults>> selector) { var results = new List(); bool isLastPage = false; int numPages = 0;

        while (!isLastPage && (maxPages == null || numPages < maxPages))
        {
            var selectorResults = await selector(queryParamValues).ConfigureAwait(false);
            results.AddRange(selectorResults.Values);

            isLastPage = selectorResults.Next == null;
            numPages++;
        }

        return results;
    }

`

lvermeulen commented 4 years ago

Found it! :-) It was actually a little bit more involved than that, have a look at GetPagedResultsAsync(). The devil is in the Math.Max details. Thanks for reporting this issue!