Is there a way to get the amount of lines changed in a Pull Request via the Dev Ops Service REST API? - azure-devops

I am currently doing my thesis and analyzing the behavior for code reviews. For this I want to know the size of the pull request that is reviewed. The rest of the information for example authors, reviewers, times etc. I got already by calling the rest API. However I cannot seem to find a way to get the amount of lines changed in each file, or a total number (which is also sufficient).
I have browsed the documentation and found some ways to get amount of files changed, see https://learn.microsoft.com/en-us/rest/api/azure/devops/git/commits/get%20commits?view=azure-devops-rest-5.1. However, I didn't found a way to get the amount of changed lines per file or a total amount.
So is there a way to get amount of lines changed in a Pull Request or between two commits?

For your issue , I am afraid that there is currently no official released REST API to do that. A similar question has been answered in this case ,please refer to it for details, you can refer to these steps to achieve your requirements:
1.Get a list of commits to get a commit’s commit id.
2.Get a commit by commit id (steps 1) to get parents value and repository id (The value at the end of _links>Repository>href) (Using the URL of _links>Changes>href can get file path if you don’t know)
3.Get file diff by this POST request https://dev.azure.com/{organization}/{project}/ _api/_versioncontrol/fileDiff?__v=5&diffParameters=[data 1]&repositoryId=[repository id]
You could also add your request for this feature on our UserVoice site, which is our main forum for product suggestions,our PM and product team will kindly review your suggestion.

Related

Is there a way to filter pull requests where my review is stale/dismissed?

On GitHub, I would like to be able to have a list of Pull Requests that require my attention. This must include any pull request that is created by a member of my team that was not authored by me, but requires a review from me. So far, I have this:
is:pr is:open user:<ORGANIZATION> involves:coworker involves:coworker -author:#me -reviewed-by:#me
The problem is, when my review is dismissed or becomes stale, -reviewed-by:#me filters out that pull request because I've previously reviewed it, even though that review has been dismissed. If I've already approved it or if the pull request has changes requested by me that are not outdated, I do not want to see them in the list.
Is there an online query to be able to list these pull requests from github.com/pulls?
Taking inspiration of this use-case which illustrate the power of GitHub CLI gh, you could, for each of the currently listed PR, do a check (using the "List reviews for a pull request" API):
gh api repos/<your repo name>/pulls/<PR ID>/reviews --jq '.[] | [.id,.state] | join("=")' | grep -Po '\d+(?=\=DISMISSED)'
You can add the .user.login attribute to filter on your name and check if you have, for a given PR, reviews in "DISMISSED" state.
If yes, you know you can filter you that PR from your intial query.
This is not straightforward, as some processing is needed, but it can help.

Fetch AzureDevops build details by Pull Request

My requirement is to tell the user if his/her PR got deployed successfully or not
So I thought,
I can ask user about his PR#
Using PR# - Fetch Build Details
Using BuildID from Step 2, find deployment information
I stuck at step 2
I am using below documentation to fetch build details.
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?view=azure-devops-rest-6.0
Not able to find correct usage of reasonFilter parameter to pass pull request id to fetch build details
API URL Info
Build Reson
Can someone help how exactly to use reasonFilter parameter here
tried this _apis/build/builds?api-version=5.1&$top=1&reasonFilter=pullrequest=20056
Regarding the point you're stuck with: The reasonFilter is simply a number of predefined string values you can choose from. For instance, if you specify reasonFilter=pullrequest, you get all builds started by a pull request. Thus, you can't specify the exact PR ID here.
Regarding your requirement in general: I don't think there's an API to strictly tie the PR ID and its build(s). You should look into the Status API instead. The build is just one of the statuses that can be associated with the pull request or, more specifically, with the commit.
So, I would approach your task the following way (note that it's not an exact algorithm, but a number of steps I would try to find the solution):
get the pull request by the PR ID provided by user
find the lastMergeCommit in the response
get the statuses of that merge commit
investigate the collection of GitStatus objects returned back and find out how to filter the build you're looking for (I don't know the format of that response for sure, but I'm confident there's some attribute to judge by)
Hope this can lead you to the right direction.
how exactly to use reasonFilter parameter here tried this _apis/build/builds?api-version=5.1&$top=1&reasonFilter=pullrequest=20056
Based on your requirement, you need to filter the build via build reason and Pull Request ID.
I'm afraid there is no out-of-box parameter to filter by pull request ID in the Rest API.
For a workaround, you can try to add the tag to your build.
Here are the steps:
You can add a step in your build to use Pull Request ID as Build tag. Refer to this doc: AddBuildTag: Add a tag to the build
For example:
- powershell: |
Write-Host "##vso[build.addbuildtag]$env:SYSTEM_PULLREQUEST_PULLREQUESTID"
displayName: 'PowerShell Script'
condition: eq(variables['Build.reason'], 'pullrequest')
You can set the condition to make sure that when the pipeline is triggered by pull request, it will add build tag.
You can add the tagFilters in Rest API to filter the related build.
For example:
Get https://dev.azure.com/org/project/_apis/build/builds?reasonFilter=pullrequest&tagFilters=PullrequestID&api-version=6.0

Reference Monday.com item ID in Github commit message

When I reference an Item ID from the Monday App in my git commit it should show up because I have following integration enabled: When a pulse ID is mentioned in a commit in this repository, create an update to the relevant pulse.
I can't get it to show in the item's updates. I tried it like #abc123 or just abc123, both don't do anything and the documentation doesn't seem to be offering an answer.
I am a developer on monday.com and i'll be glad to help you!
When stating the things you tried, yes the way to go to mention a pulse is
#{PULSE_ID} but I do wonder, where do you get your pulse id from?
For example, it is shown at the end of the URL:
Please note that the commit has to be pushed first to your branch/master for it to show up on monday, if it's only locally it won't send us webhooks about it.

Azure DevOps/VSTS REST API does not get changes of a changeset

I'm trying to to get the changes of a changeset but it returns 404. I used this:
https://<myname>.visualstudio.com/<projectname>/_apis/tfvc/changesets/291/changes
changeset exists
without the '/changes' it works, returns the changeset info but I also need the merge sources
tried to specify the API version (e.g.: api-version-5.0)
I created a full control Personal Access Token for the client app but no luck. I tried to use this link in the browser and I got the same result: it works only without '/changes'.
What did I wrong?
As this is an old Q, this is for anyone else who has same problem, The projectname needs to be removed from the request.
https://<myname>.visualstudio.com/_apis/tfvc/changesets/291/changes
You look at the docs and sure enough it's not there but most other REST calls require a project name, so it can be confusing.
Also the docs are not very clear that you can interchange https://{myName}.visualstudio.com/ for the documented https://dev.azure.com/{organization}

REST expected behavior of entity filter within collection

Could somebody help to find out the expected behavior in filtering data within REST.
I have an ordinary REST-service with API
GET /api/articles <-- extract all articles
GET /api/articles?category=1 <-- extract all articles belonging the
particular category
I have doubts regarding the second stuff. What must a request return if user set an invalid category. There're 3 options:
return all articles
return an empty collection
return error
I suppose that it might be up to me, but anyway I wonder whether somebody have implemented this and how he/she resolved it.
You have answered your question yourself, but to provide you an example how this is already implemented (in numerous cases) but just pointing to one such example using JIRA.
You can use JIRA's REST APIs to GET the ticket details and which is what I'm showing you here:
Using CURL, I've tried to get the ticket details providing an invalid JIRA ticket id and the above is the response that I received.
It is up to us to decide upon what needs to be the outcome of the REST APIs that we develop, just pointing out one of the scenarios from JIRA REST APIs where they chose to error out (instead of showing no response or etc).
Hope this answers your question well!