Is there an az cli
command that gets the threads and comments on a PR?
PR’s can be listed with:
az repos pr list --organization $organization --project "$project" --repository $repo
The REST API has this endpoint, which gets the threads and comments:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/threads?api-version=7.1-preview.1
example output cropped:
"value": [
{
"pullRequestThreadContext": null,
"id": 111111,
"publishedDate": "2024-02-19T16:00:00.000Z",
"lastUpdatedDate": "2024-02-19T16:00:00.000Z",
"comments": [],
"status": "active",
"threadContext": null,
"etc": "etc"
},
{
"pullRequestThreadContext": null,
"id": 123456,
"publishedDate": "2024-02-19T16:00:00.000Z",
"lastUpdatedDate": "2024-02-19T16:00:00.000Z",
"comments": [
"content": "Some comment on the PR appears in this field",
"publishedDate": "2024-02-19T16:00:00.000Z",
"lastUpdatedDate": "2024-02-19T16:00:00.00Z",
"lastContentUpdatedDate": "2024-02-19T16:00:00.000Z",
"commentType": "text",
"etc": "etc"`
]
}
]
"etc"
"etc"
}
But there does not seem to be a way to use az repos
to get threads and comments.
(I am specifically looking for PR’s that have open comments, with "status": "active"
and not "status": "fixed"
: since our automation should not close these PR’s. Atm we have no way of differentiating between PR’s except for using the REST API, ideally we do not use both REST API and az cli, az cli is more user friendly, so has my preference.)
2
Answers
Instead of using
az repos pr list
, Useaz repos pr show
command to get the comments from the PR ID of the repository. Unfortunately, According to this MS Document there’s no direct command to get the comments fromaz repos
.Commands:-
Output:-
Also, You can also use Powershell command to easily call any Azure Rest API, to call the Rest API mentioned in the question to list Repos by PR ID:-
Commands:-
Output:-
To get threads with
az devops
, you may useinvoke
subcommand. To get threads:To get comments in threads: