0

I am working on patch release. I am getting change list from vsts using Microsoft VSTS API. I have 3 branches like A -> B -> C. A is base branch and b is created sub branch from A and c is created sub branch from B. So whatever changes I made in A and B that will be in C branch as well as C branch change. Now I have one pull request I'd which is targeted to the C branch. I am able to get all commits of C branch using pull request I'd. But I want to get parent class detail of C and then A. I tried but there is nothing I found.

Manu
  • 7
  • 1
  • 4

1 Answers1

1

Through Get Pull Request By Id rest api, you can get the repository id, sourceRefName, targetRefName from the response body.

enter image description here

enter image description here

Then you can call Get Commits Batch rest api through the repository id and sourceRefName parameters to get all the commits of the parent branch.

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

Sample request body:

{
  "itemVersion": {
    "versionType": "branch",
    "version": "dev"
  }
}

Sample response:

{
    "count": 32,
    "value": [
        {
            "commitId": "bbcb0ee346961422c686fd4d3b2f63f74dffa1e3",
            "author": {
                "name": "hughl01",
                "email": "xxx@hotmail.com",
                "date": "2020-05-20T01:44:05Z"
            },
            "committer": {
                "name": "hughl01",
                "email": "xxx@hotmail.com",
                "date": "2020-05-20T01:44:05Z"
            },
            "comment": "Deleted NEW",
            "changeCounts": {
                "Add": 0,
                "Edit": 0,
                "Delete": 2
            },
            "url": "https://dev.azure.com/xx/59b994e8-4a77-46a1-8b5d-xx/_apis/git/repositories/da09f0c6-1999-45b5-bb93-faa59f69fa24/commits/bbcb0ee346961422c686fd4d3b2f63f74dffxx",
            "remoteUrl": "https://dev.azure.com/xx/xx/_git/forTest/commit/bbcb0ee346961422c686fd4d3b2f63f74dfxx"
        },
 ...
}
Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
  • This will work if my pull request merge the changes in to parent branch. I have query when C is child of B and B is child of A. But I merged PR in C branch which is C->TaskBranch Then My Pull request will show SourceRef = "refs/Head/TaskBranch" and TargetRef="refs/Head/C". And also these changes I am not going merge in B branch which is parent of C. In this case wont get link between B and C branch. Any suggestion would be appreciate. – Manu Jun 04 '20 at 20:01