Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
xiphoid24 opened this issue Aug 16, 2022 · 5 comments

Comments

@xiphoid24
Copy link

xiphoid24 commented Aug 16, 2022

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

@kirill-ivlev
Copy link
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.

@xiphoid24
Copy link
Author

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

@GravlLift
Copy link

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

@github-actions
Copy link

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

@xiphoid24
Copy link
Author

@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
Projects
None yet
Development

No branches or pull requests

4 participants