You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 searchCriteriaids 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 searchCriteriaids 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
Use the GitApi to call the getCommits method.
Provide the getCommits method a searchCriteria object with the ids field containing a string array of commit ids
{ ids: ["CommitId0", "CommitId1"] }
Log the returned commits
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
The text was updated successfully, but these errors were encountered:
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 asearchCriteria
object which has anids
field. Theids
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 namedsearchCriteria.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 ofsearchCriteria.ids.{indexInArray}
. This causes the API to ignore the commit ids all together.Expected behaviour
When calling the
getCommits
method while providing thesearchCriteria
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 thesearchCriteria
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
GitApi
to call thegetCommits
method.getCommits
method asearchCriteria
object with theids
field containing a string array of commit ids{ ids: ["CommitId0", "CommitId1"] }
Suggestion
This seems to be caused by the queryParamsToStringHelper method in the
VsoClient.ts
file. Here it loops all of the properties of thequeryParams
object. Once the recursion gets to an array, it loops over the array setting theproperty
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 ifqueryParams
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
The text was updated successfully, but these errors were encountered: