-
Notifications
You must be signed in to change notification settings - Fork 10
/
Test-D365FOLabelsFromCheckins.ps1
100 lines (84 loc) · 4.11 KB
/
Test-D365FOLabelsFromCheckins.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#https://github.com/valerymoskalenko/D365FFO-PowerShell-scripts/blob/master/Test-D365FOLabelsFromCheckins.ps1
Set-StrictMode -Version Latest
Set-Location -Path C:\Scripts
[string]$DevOpsURL = 'https://contoso.visualstudio.com' #https://dev.azure.com/Fleet-Complete/FLEX
[string]$DevOpsProject = 'Contoso-Project'
[string]$DevOpsUsername = 'valery.moskalenko@contoso.com'
[string]$DevOpsPassword = 'iax45*************************56fuq'
[string]$DevOpsLabelFile = '$/Contoso-Project/Trunk/DEV/Metadata/ContosoCustomization/Contoso Customization/AxLabelFile/LabelResources/en-US/Contoso.en-US.label.txt'
[string]$tempFile = Join-Path -Path $env:TEMP -ChildPath 'temp.txt'
$uriChangesetsList = "$($DevOpsURL)/$($DevOpsProject)/_apis/tfvc/changesets?searchCriteria.itemPath=$DevOpsLabelFile&api-version=5.0"
$pair = "${DevOpsUsername}:${DevOpsPassword}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$headers = @{
"Accept" = "application/json"
"Accept-Charset" = "UTF-8"
"Authorization"= "Basic $base64"
}
$wcChangesetsList = Invoke-WebRequest -Uri $uriChangesetsList -Method Get -Headers $headers -Verbose
$jsonChangesetsList = $wcChangesetsList.Content | ConvertFrom-Json
$jsonChangesetsList.value | Select changesetId, createdDate, comment | FT
$headersChangeset = @{
"Accept" = "text/plain"
"Accept-Charset" = "UTF-8"
"Authorization"= "Basic $base64"
}
$AllLabels = @{} #init hash table with all Labels
foreach ($changeset in $jsonChangesetsList.value)
{
[string]$changesetId = $changeset.changesetId
Write-Host "Working on Changeset" $changesetId "by" $changeset.author.displayName $changeset.comment -ForegroundColor Yellow
[string]$LabelFileChangeset = Join-Path -Path $env:TEMP -ChildPath "LabelFile_$changesetId.txt"
if (Test-Path $LabelFileChangeset) {Remove-Item -Path $LabelFileChangeset -Force}
$uriLabelFileChangeset = "$($DevOpsURL)/$($DevOpsProject)/_apis/tfvc/items/$DevOpsLabelFile" + "?versionType=Changeset&version=$changesetId"
$wcLabelFileChangeset = Invoke-WebRequest -Uri $uriLabelFileChangeset -Headers $headersChangeset # -OutFile $LabelFileChangeset
#Process Label File
$wcLabelFileChangeset.Content | Set-Content -Path $LabelFileChangeset
foreach($row in Get-Content -Path $LabelFileChangeset| Select-String -Pattern '^(?! ;).*=.*' )
{
$labelId = '';
$labelText = '';
$labelId, $labelText = $row -split '='
If (-not $AllLabels.ContainsKey($labelId))
{
$AllLabels.Add($labelId, $labelText); #insert
} <#else {
$AllLabels[$labelId] = $labelText; #update
}#>
}
}
#Get latest changeset
[string]$LabelFileLatest = Join-Path -Path $env:TEMP -ChildPath "LabelFile_LATEST.txt"
if (Test-Path $LabelFileLatest) {Remove-Item -Path $LabelFileLatest -Force}
$uriLabelFileLatest = "$($DevOpsURL)/$($DevOpsProject)/_apis/tfvc/items/$DevOpsLabelFile"
$wcLabelFilelatest = Invoke-WebRequest -Uri $uriLabelFileLatest -Headers $headersChangeset # -OutFile $LabelFileChangeset
$wcLabelFilelatest.Content | Set-Content -Path $LabelFileLatest
#Compare Label File
Write-Host "Compare labels: All labels vs Latest Labels:" -ForegroundColor Green
$LatestLabels = @{} #init hash table with Latest Labels
foreach($row in Get-Content -Path $LabelFileLatest| Select-String -Pattern '^(?! ;).*=.*' )
{
$labelId = '';
$labelText = '';
$labelId, $labelText = $row -split '='
If (-not $LatestLabels.ContainsKey($labelId))
{
$LatestLabels.Add($labelId, $labelText); #insert
} else {
$LatestLabels[$labelId] = $labelText; #update
Write-Host "Duplicate label Id:" $labelId "? in Latest Labels" -ForegroundColor Red
}
If (-not $AllLabels.ContainsKey($labelId))
{
Write-Host "Missing label in All Labels: $labelId=$($LatestLabels[$labelId])" -ForegroundColor Red
}
}
foreach($label in $AllLabels.Keys)
{
if (-not $LatestLabels.ContainsKey($label))
{
Write-Host "Missing label in Latest Labels: $label=$($AllLabels[$label])" -ForegroundColor Red
#Write-host "..with text:" $AllLabels[$label]
}
}