admin管理员组文章数量:1406060
I'm trying to use PowerShell 5.1 to get completed PRs for a date range in Azure DevOps. I'm getting a response, but not respecting the closed date parameter. I know I can filter the list afterwards, but that seems inefficient.
$startDate = (Get-Date -Date "2025-01-31T00:00:00Z").ToString("yyyy-MM-ddTHH:mm:ssZ")
$url = "$anization/$project/_apis/git/repositories/$repositoryId/pullrequests?searchCriteria.status=completed&searchCriteria.targetRefName=refs/heads/master&searchCriteria.closedDate>$startDate&api-version=6.0"
I'm trying to use PowerShell 5.1 to get completed PRs for a date range in Azure DevOps. I'm getting a response, but not respecting the closed date parameter. I know I can filter the list afterwards, but that seems inefficient.
$startDate = (Get-Date -Date "2025-01-31T00:00:00Z").ToString("yyyy-MM-ddTHH:mm:ssZ")
$url = "$anization/$project/_apis/git/repositories/$repositoryId/pullrequests?searchCriteria.status=completed&searchCriteria.targetRefName=refs/heads/master&searchCriteria.closedDate>$startDate&api-version=6.0"
Share
Improve this question
edited Mar 7 at 3:16
Bright Ran-MSFT
14.5k1 gold badge12 silver badges28 bronze badges
asked Mar 6 at 16:50
RodRod
15.5k35 gold badges134 silver badges264 bronze badges
4
|
2 Answers
Reset to default 1On the api-version=6.0
of Azure DevOps REST API "Pull Requests - Get Pull Requests", the searchCriteria.closedDate
is not an available/valid parameter for the request URI.
Since the api-version=7.1
of this API, there are some new URI parameters are introduced. For your case, you can use this API version with the parameters searchCriteria.minTime
, searchCriteria.maxTime
and searchCriteria.queryTimeRangeType
like as below.
GET https://dev.azure/{anization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests?searchCriteria.status=completed&searchCriteria.targetRefName=refs/heads/master&searchCriteria.minTime={minDataTime}&searchCriteria.maxTime={maxDataTime}&searchCriteria.queryTimeRangeType=closed&api-version=7.1
`closedDate` parameter is being formatted or interpreted in the URL differently. Maybe adding endDate parameter and reformatting can help you pass the date correctly and recognized by the API
$startDate = (Get-Date -Date "2025-01-31T00:00:00Z").ToString("yyyy-MM-ddTHH:mm:ssZ")
$endDate = (Get-Date -Date "2025-02-28T23:59:59Z").ToString("yyyy-MM-ddTHH:mm:ssZ")
$url = "$anization/$project/_apis/git/repositories/$repositoryId/pullrequests?searchCriteria.status=completed&searchCriteria.targetRefName=refs/heads/master&searchCriteria.closedDate=$startDate&searchCriteria.closedDate=$endDate&api-version=6.0"
$response = Invoke-RestMethod -Uri $url -Method Get -Headers @{Authorization = "Bearer $token"}
$completedPRs = $response.value | Where-Object { $_.closedDate -ge $startDate -and $_.closedDate -le $endDate }
$completedPRs
Note: The API call is not tested.
本文标签: Trying to use PowerShell 51 to get completed PRs for a date range in my Azure DevOpsStack Overflow
版权声明:本文标题:Trying to use PowerShell 5.1 to get completed PRs for a date range in my Azure DevOps - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744961379a2634674.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
searchCriteria.closedDate>$startDate
withsearchCriteria.minTime=$startDate&searchCriteria.queryTimeRangeType=closed
– Mathias R. Jessen Commented Mar 6 at 17:10.ToString()
call operates on is a local date, so theZ
suffix in the formatted output is inappropriate, unless your local time zone coincides with UTC. – mklement0 Commented Mar 6 at 22:44