Skip to content

getCommits API call returns extra commits when providing the searchCriteria an array of ids #514

Closed
@xiphoid24

Description

@xiphoid24

Environment

Node version: 16.17.0
Npm version: 8.15.0
OS and version: Windows 10
azure-devops-node-api version: 11.2.0

Issue Description

We are using the API to get a set of commits. The getCommits method accepts a searchCriteria object which has an ids field. The ids field is a sting array of commit ids. When using this method, several commits are returned not just the commits requested by id. Looking at the git API documentation, it accepts a single query parameter named searchCriteria.ids which is an array of commit ids. From my testing, the query parameters are not being formatted properly. Instead of creating a single parameter with a comma separated list of commit ids, it is creating a new parameter for each of the commit ids with the parameter name of
searchCriteria.ids.{indexInArray}. This causes the API to ignore the commit ids all together.

Expected behaviour

When calling the getCommits method while providing the searchCriteria ids field a string array of commit ids it only returns the commits matching the ids provided.

The URL created for the api call is in the following format:
https://domain.com/CollectionName/ProjectId/_apis/git/repositories/RepositoryName/commits?searchCriteria.ids=CommitId0,CommitId1,CommitId2

Actual behaviour

When calling the getCommits method while providing the searchCriteria ids field a string array of commit ids it returns commits where the id matches the ids provided and several others (most likely all).

The URL created for the api call is in the following format:
https://domain.com/CollectionName/ProjectId/_apis/git/repositories/RepositoryName/commits?searchCriteria.ids.0=CommitId0&searchCriteria.ids.1=CommitId1&searchCriteria.ids.2=CommitId2

Steps to reproduce

  1. Use the GitApi to call the getCommits method.
  2. Provide the getCommits method a searchCriteria object with the ids field containing a string array of commit ids
    • { ids: ["CommitId0", "CommitId1"] }
  3. Log the returned commits
  4. Observe it contains more commits than requested

Suggestion

This seems to be caused by the queryParamsToStringHelper method in the VsoClient.ts file. Here it loops all of the properties of the queryParams object. Once the recursion gets to an array, it loops over the array setting the property to the current index of the array. This creates a single query parameter for each index instead of combining the array into a single query parameter.

This could be fixed by updated the if found here to check if queryParams is not an array.

Example

if (queryParams.hasOwnProperty(property) && !Array.isArray(queryParams)) {

This would skip the parameter looping an let the rest of the processing convert the string array into a single comma separated string.

Update:

I created a fork, branch and committed the proposed change

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions