You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在DevOps的Git项目中获取所有拉取请求的全部评论?

How to Retrieve All Comments from All Pull Requests in Azure DevOps Git

I totally get the frustration—TFS had that handy Visual Studio integration for pulling PR comment data easily, but Azure DevOps Git takes a slightly different approach. Here are three solid methods to get all your pull request comments, depending on your workflow needs:

1. Azure DevOps CLI (Best for Bulk Exports)

The CLI is perfect if you need to script or bulk-export comments. First, make sure you’ve installed the Azure DevOps CLI and authenticated with your org:

az login
az devops configure --defaults organization=YourOrgName project=YourProjectName

Then follow these steps:

  • Export a list of all pull requests (filter by state like completed or all):
    az repos pr list --state all --output json > all-prs.json
    
  • Loop through each PR to fetch its comments (example PowerShell script):
    $pullRequests = Get-Content all-prs.json | ConvertFrom-Json
    foreach ($pr in $pullRequests) {
        az repos pr comment list --id $pr.id --output json >> all-pr-comments.json
    }
    

This will compile all comments into a single JSON file you can parse or analyze later.

2. Azure DevOps REST API (Customizable Automation)

If you need fine-grained control over the data you retrieve, the REST API is your friend. You’ll need a Personal Access Token (PAT) with Code (Read) permissions.

First, fetch all pull requests:

GET https://dev.azure.com/{YourOrg}/{YourProject}/_apis/git/pullrequests?api-version=7.1-preview.1

Then, for each PR ID returned, fetch its comments:

GET https://dev.azure.com/{YourOrg}/{YourProject}/_apis/git/pullrequests/{PRId}/comments?api-version=7.1-preview.1

You can use tools like Postman or write a simple Python/JS script to iterate through PRs and aggregate comments into a structured format.

3. Visual Studio (Ad-Hoc Access)

While bulk exports aren’t as direct as TFS, you can still access PR comments in Visual Studio:

  • Open your Git repo in VS, go to the Pull Requests tab (under the Git menu).
  • Use the filter dropdown to show all PRs (active, completed, abandoned).
  • For each PR, open it and navigate to the Comments tab to view all discussions.
  • Note: This works great for checking individual PRs, but isn’t ideal for bulk data retrieval.

Bonus: Azure DevOps Analytics (Reporting & Dashboards)

If you need to build reports or track comment metrics over time, use the Analytics service. You can connect Power BI to Azure DevOps via the Analytics connector, then create queries to pull PR comments alongside other metrics like author, date, and PR status for deeper analysis.

Pro tip: When using CLI or API, add filters like --type user to only fetch comments from team members (excluding system-generated ones) or --created-after "YYYY-MM-DD" to narrow results to a specific date range.

内容的提问来源于stack exchange,提问作者Buck Uy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 01:02:40