Skip to content

Commit 424d573

Browse files
committed
Validate SHA for remotes
1 parent f9a2c18 commit 424d573

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

schema.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
"sha": {
3030
"$id": "/properties/projects/items/properties/sha",
3131
"type": "string",
32-
"title": "The SHA Schema ",
33-
"description": "An explanation about the purpose of this instance.",
34-
"default": ""
32+
"title": "The SHA Schema",
33+
"description": "This property is obsolete and should not be used.",
34+
"default": "",
35+
"deprecated": true
3536
},
3637
"dst": {
3738
"$id": "/properties/projects/items/properties/dst",

sync.ps1

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,37 @@ function Get-DefaultBranch {
3636
[BranchInfo]::new($shaPattern.Match($output).Value, $branchPattern.Match($output).Value)
3737
}
3838

39+
function Get-OutdatedRemotes {
40+
[CmdletBinding()]
41+
param(
42+
[Parameter(Mandatory = $true, Position = 0 )]
43+
$project,
44+
45+
[Parameter(Mandatory = $true, Position = 1 )]
46+
$masterBranch
47+
)
48+
49+
$project.dst | ? {
50+
$remoteName = $_.name
51+
$remoteUrl = $_.url
52+
53+
Write-Host "`t$remoteName " -ForegroundColor Cyan -NoNewline
54+
$branchRemote = Get-DefaultBranch $remoteUrl
55+
56+
if ($branchRemote.SHA -eq $masterBranch.SHA) {
57+
Write-Host "[OK]" -ForegroundColor Green
58+
}
59+
else {
60+
Write-Host "[MISSMATCH]" -ForegroundColor Red
61+
Write-Host "Master SHA: $($masterBranch.SHA)" -ForegroundColor Yellow
62+
Write-Host "Remote SHA: $($branchRemote.SHA)" -ForegroundColor Yellow
63+
$_
64+
}
65+
}
66+
67+
68+
}
69+
3970
Clear-Host
4071
$configuration = Get-Content -Raw -Path .\config.json | ConvertFrom-Json
4172
$rootDirectoryPath = Get-CurrentLocation
@@ -51,6 +82,7 @@ $configuration.projects | % {
5182

5283
$sha = $_.sha
5384
$branch = Get-DefaultBranch $_.url
85+
# deprecated - SHA validation will be done against the master branch and remotes
5486
if (![string]::IsNullOrWhiteSpace($sha)) {
5587
if ($sha -eq $branch.SHA) {
5688
Write-Host "Validating SHA [OK]"
@@ -62,6 +94,14 @@ $configuration.projects | % {
6294
Write-Host "Config SHA: $sha" -ForegroundColor Yellow
6395
}
6496
}
97+
# end deprecated
98+
99+
Write-Host "Getting outdated remotes" -ForegroundColor Yellow
100+
$remotes = Get-OutdatedRemotes -Project $_ -MasterBranch $branch
101+
if (!$remotes) {
102+
Write-Host "No remotes to update" -ForegroundColor Green
103+
return
104+
}
65105

66106
$repoPath = Join-Path $rootDirectoryPath $_.name
67107
if (Test-Path $repoPath) {
@@ -96,7 +136,7 @@ $configuration.projects | % {
96136
Write-Host "Current Location $(Get-CurrentLocation)" -ForegroundColor Gray
97137

98138
Write-Host "Validating remotes" -ForegroundColor Cyan
99-
$_.dst | % {
139+
$remotes | % {
100140
$remoteName = $_.name
101141
$remoteUrl = $_.url
102142
Write-Host "`t$remoteName" -ForegroundColor Cyan -NoNewline

0 commit comments

Comments
 (0)