2
votes

Requirement is to read/extract source code of each file present in an Azure DevOps pull request using APIs or C#. I am able to download the code for a particular file using sample URL below -

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path=/{CodePath}&version={branch name}&api-version=5.1

Now I need, list of files with location where it is stored in a branch of Azure DevOps

I have tried different GET calls from REST APIs available. Ex - GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/iterations/{iterationId}?api-version=5.1 or GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/attachments/{fileName}?api-version=5.1-preview.1

These call are returning information about the 1. About file commits 2. About documents attached in description

Information I have to fulfill the requirement - Organization name,Repository name,Branch Name, Pull request ID

Thanks in advance

1

1 Answers

1
votes

Is there a way to list pull request files(from source branch) with it's location in Azure Devops using APIs? Is there any other way using C#?

I am afraid there is no such out of way to list pull request files(from source branch) with it's location in Azure Devops using APIs.

First, when we use the pull request API, we could get the Organization name and Pull request ID directly.

Then we could use the REST API Pull Requests - Get Pull Requests to get the repository name and sourceRefName (Branch Name):

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests?api-version=5.1

enter image description here

Second, we could use the REST API Pull Request Commits - Get Pull Request Commits to get the commits in the PR:

enter image description here

Then, we could use the commit id with REST API Commits - Get Changes to file path:

enter image description here

Now, we get all the info what we want.

Hope this helps.