Skip to content

[BUG]: Specifying PageCount doesn't work if the query gets constructed with page number as the first query parameter #2693

@corwin-gs

Description

@corwin-gs

What happened?

I tried requesting 5 pages of file changes in a PR, for example:

var apiOptions = new ApiOptions
{
    PageCount = 5,
};
var pullRequest = await GitHubClient.PullRequest.Get(repoOwnerName, repositoryName, pullRequestNumber);

which actually requests all pages.

This is because of this code in Pagination.cs

return uri.Query.Split('&')
    .Select(keyValue =>
    {
        var indexOf = keyValue.IndexOf('=');
        if (indexOf > 0)
        {
            var key = keyValue.Substring(0, indexOf);
            var value = keyValue.Substring(indexOf + 1);
            return new KeyValuePair<string, string>(key, value);
        }

        //just a plain old value, return it
        return new KeyValuePair<string, string>(keyValue, null);
    })
    .ToDictionary(x => x.Key, x => x.Value);

which incorrectly includes the initial ?, which you can see the effect of in this debugger screenshot
image
and TryGetValue naturally returns false.

Versions

Octokit.net 5.0.2

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Up for grabsIssues that are ready to be worked on by anyoneType: BugSomething isn't working as documentedhacktoberfestIssues for participation in Hacktoberfest

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions