I am trying to get the status of the pull request with pull request ID using API’s. However Unable to get the statusID of the pull request to call the below API, Where can I find the statusID?
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/statuses/{statusId}?api-version=7.1-preview.1
1
To find the statusID, you can run REST API Pull Request Statuses – List firstly. It will list all the statuses associated with a pull request.
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/statuses?api-version=7.1-preview.1
Sample response:
{
"value": [
{
"iterationId": 1,
"id": 1,
"description": "Coverage status check queued for TestPRTrigger",
"context": {
"name": "codecoverage",
"genre": "testprtrigger"
},
"creationDate": "2024-09-10T06:32:27.426169Z",
"updatedDate": "2024-09-10T06:32:27.426169Z",
"createdBy": {
"displayName": "Azure Pipelines Test Service",
"url": "***",
"_links": {
"avatar": {
"href": "***"
}
},
"id": "***",
"uniqueName": "",
"imageUrl": "***",
"descriptor": "***"
}
},
{
"iterationId": 1,
"id": 2,
"state": "pending",
"description": "Coverage status check in progress for TestPRTrigger",
"context": {
"name": "codecoverage",
"genre": "testprtrigger"
},
"creationDate": "2024-09-10T06:33:38.1173998Z",
"updatedDate": "2024-09-10T06:33:38.1173998Z",
"createdBy": {
"displayName": "Azure Pipelines Test Service",
"url": "***",
"_links": {
"avatar": {
"href": "***"
}
},
"id": "***",
"uniqueName": "",
"imageUrl": "***",
"descriptor": "***"
}
},
...
Update
Pull request status provides a way for services to associate simple success/failure type information with a pull request. You need to configure some branch policies on your target branch, then you can get the PR status.
See more info about PR status from Customize and extend pull request workflows with pull request status.
4