导出特定日期范围内Azure Repos中特定文件夹中所有文件的git历史记录
问题描述:
Salesforce文件夹结构如下,其中包含许多类和元xml:
Salesforce Folder structure as below containing numerous classes and meta xml's:
Project
--src
--classes
-- Class A
-- Class A-Meta.xml
-- Class B
-- Class B-Meta.xml
-- Class N
问题陈述: 对于每堂课,我需要
Problem statement: For each class, I need
- 日期范围内的历史记录
- 输出应包含在此日期范围内对此文件进行过提交的文件名,提交ID和作者名.
- 以excel/csv/word格式导出此信息
样本输出
Classname Author commit
Class A Dev1 abcd
Class A Dev2 pqrs
Class A Dev3 uvwz
Class B Dev9 yuot
Class B Dev1 qwew
我正在使用VSTS Azure Repos.打开以使用git log或其他快速完成此操作的方式.
I am using VSTS Azure Repos. Open to use git log or any other way of getting this done quickly.
答
- 日期范围内的历史记录
We can use this REST API to retrieve git commits for a project in a date range, we can get commit ID, author and committer Info.
示例:
GET https://dev.azure.com/{Org name}/_apis/git/repositories/{repositoryId}/commits?searchCriteria.toDate=6/16/2018 12:00:00 AM&searchCriteria.fromDate=6/14/2018 12:00:00 AM&api-version=5.0
我们可以通过提交ID获取提交文件夹名称
We can get the commit Folder name via commit ID
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/changes?api-version=6.0-preview.1
并使用以下API获取详细的提交信息
And get the detail commit info with below API
Get https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=6.0-preview.1
电源外壳示例:
$connectionToken="{pat}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$Commits = "https://dev.azure.com/{org name}/_apis/git/repositories/{repo id}/commits?searchCriteria.toDate=9/15/2020 12:00:00 AM&searchCriteria.fromDate=9/1/2020 12:00:00 AM&api-version=5.0"
$CommitInfo = Invoke-RestMethod -Uri $Commits -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get
ForEach ($ID in $CommitInfo.value.commitId)
{
Write-Host $ID
$url = "https://dev.azure.com/{org name}/{project name}/_apis/git/repositories/{repo id}/commits/$($ID)?api-version=6.0-preview.1"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$CommitDetail = Invoke-RestMethod -Uri $url -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get
Write-Host "commit ID is" $CommitDetail.commitId "author is" $CommitDetail.author.name "committer is" $CommitDetail.committer.name
}
结果: