forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetLatestCommitSHA.ps1
More file actions
30 lines (22 loc) · 1.08 KB
/
Copy pathGetLatestCommitSHA.ps1
File metadata and controls
30 lines (22 loc) · 1.08 KB
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
Param(
[string]$owner,
[string]$repo,
[string]$branchName
)
Write-Host "Getting the latest commit SHA for $($branchName):" -ForegroundColor Magenta;
$latestCommitUrl = "https://api.github.com/repos/$($owner)/$($repo)/commits/$($branchName)";
Write-Host "Getting latest commit with '$($latestCommitUrl)'" -ForegroundColor Blue;
$latestCommitData = Invoke-RestMethod -Uri $latestCommitUrl -Method Get;
if ($latestCommitData.Count -eq 0) {
Write-Host "Unable to get latest commit with '$($latestCommitUrl)'" -ForegroundColor Red;
EXIT 1;
}
if ([string]::IsNullOrEmpty($latestCommitData.sha)) {
Write-Host "SHA is not present in the latest commit that is fetched" -ForegroundColor Red;
Write-Host "Latest Commit Data:" -ForegroundColor Cyan;
Write-Host -Object $latestCommitData -ForegroundColor Cyan;
EXIT 1;
}
Write-Host "Latest Commit SHA is '$($latestCommitData.sha)'" -ForegroundColor Green;
Write-Host "##vso[task.setvariable variable=LASTEST_COMMIT_SHA]$($latestCommitData.sha)";
Write-Host "Updated latest commit sha in global variable" -ForegroundColor Green;