Skip to content

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

Closed

Description

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

Activity

  1. kirill-ivlev commented on Aug 18, 2022

    @kirill-ivlev
    Contributor

    Hi @gregpechiro!

    Thank you for your request, please feel free to create PR to the parent repo, we will test & review it, once we will have capacity.

  2. xiphoid24 commented on Aug 18, 2022

    @xiphoid24
    Author

    Hey Kirill Ivlev (@kirill-ivlev),
    Thanks for taking a look. Here is a link to the PR.

  3. GravlLift commented on Nov 15, 2022

    @GravlLift

    Just ran into this issue myself. Kirill Ivlev (@kirill-ivlev), @gregpechiro's PR is a single line change and it's been open for 3 months, what's the holdup?

  4. github-actions commented on Feb 13, 2023

    @github-actions

    This issue has had no activity in 90 days. Please comment if it is not actually stale

  5. xiphoid24 commented on Jul 28, 2023

    @xiphoid24
    Author

    Kirill Ivlev (@kirill-ivlev) I failed to comment to keep this open. As far as I know this is still an issue. Please reopen this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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