I have two API requests, one that creates an array of pull request ID’s (PRIDs) from a git repo, and another that gets a count of comments associated with an individual pull request. I would like to be able to loop through the array of PRIDs to return a total count of existing pull requests (PRIDs.length) and average comments per PR measure (Total comments/PRIDs.length).
I am a very young Postman user (think newborn, I started with it yesterday), but it seems like there might be a way to store the PRID array in a collection variable, then loop through that array with the second request to obtain the desired counts, I just don’t know how to use the software well enough to do that.
I have a written the test script that creates an array of Pull Request ID’s as such:
var body = JSON.parse(responseBody);
var PRIDs = ;
for (var i = 0; i<body.value.length;i++){
PRIDs.push(body.value[i].pullRequestId)
}
And have written the test script that counts the number of comments in a single pull request as so:
var body = JSON.parse(responseBody);
var count = 0;
for (var i = 0;i<body.value.length;i++) {
if (body.value[i].comments[0].commentType ==“text”) {
count++;
}
}
Any help, or just a nudge in the general right direction, would be very greatly appreciated, thanks!
Also, if this helps at all, or if anyone has suggestions for another problem I’ve encountered I am using the Azure Devops REST API. I have noticed that when returning the Pull Requests, it caps the $top field at 1000 instances, and since my repo has 2194 Pull Requests thus far, it means I will have to run this script (assuming it is possible) three times to get all of the data I want. If you know of an easy way to automate this into one request that would be splendid!