@@ -59,34 +59,85 @@ function Get-AppVeyorFailure {
59
59
Write-Progress - Activity " Get-AppVeyorFailure" - Status " Fetching latest build for branch '$Branch '..." - PercentComplete 0
60
60
Write-Verbose " Looking for latest AppVeyor build for branch: $Branch "
61
61
62
+ # Try GitHub CLI integration first
63
+ $usedGh = $false
62
64
try {
63
- # Get recent builds and find the latest one for this branch
64
- $apiParams = @ {
65
- Endpoint = " projects/dataplat/dbatools/history?recordsNumber=50"
66
- }
67
- $history = Invoke-AppVeyorApi @apiParams
68
-
69
- if (-not $history -or -not $history.builds ) {
70
- Write-Verbose " No build history found"
71
- Write-Progress - Activity " Get-AppVeyorFailure" - Completed
72
- return
65
+ $Owner = " dataplat"
66
+ $Repo = " dbatools"
67
+
68
+ # Get the latest commit SHA for the branch
69
+ $sha = (& gh api " repos/$Owner /$Repo /commits?sha=$Branch &per_page=1" - q ' .[0].sha' 2> $null )
70
+ if ($sha ) {
71
+ $sha = $sha.Trim ()
72
+
73
+ # Try checks API first
74
+ $detailsUrl = (& gh api " repos/$Owner /$Repo /commits/$sha /check-runs?per_page=100" - q ' .check_runs | sort_by(.started_at, .created_at) | reverse[] | select((.name|test("appveyor";"i")) or (.app.slug=="appveyor")) | .details_url' 2> $null )
75
+ if ($detailsUrl ) {
76
+ $detailsUrl = ($detailsUrl -split " `r ?`n " | Select-Object - First 1 ).Trim()
77
+ }
78
+
79
+ # Fallback to statuses API if no check-runs found
80
+ if (-not $detailsUrl ) {
81
+ $detailsUrl = (& gh api " repos/$Owner /$Repo /commits/$sha /status" - q ' .statuses | sort_by(.updated_at, .created_at) | reverse[] | select(.context|test("appveyor";"i")) | .target_url' 2> $null )
82
+ if ($detailsUrl ) {
83
+ $detailsUrl = ($detailsUrl -split " `r ?`n " | Select-Object - First 1 ).Trim()
84
+ }
85
+ }
86
+
87
+ # Extract AppVeyor build version from URL
88
+ if ($detailsUrl -and $detailsUrl -match ' /build/([^/?#]+)' ) {
89
+ $version = $Matches [1 ]
90
+ Write-Verbose " Using GitHub checks to resolve AppVeyor build for branch '$Branch ' (version: $version )"
91
+
92
+ # Call AppVeyor API directly with the version
93
+ $apiParams = @ {
94
+ Endpoint = " projects/dataplat/dbatools/build/$version "
95
+ }
96
+ $build = Invoke-AppVeyorApi @apiParams
97
+
98
+ if ($build -and $build.build ) {
99
+ $BuildNumber = $build.build.buildNumber
100
+ $usedGh = $true
101
+ Write-Verbose " Successfully resolved build #$BuildNumber using GitHub CLI"
102
+ }
103
+ }
73
104
}
105
+ } catch {
106
+ # Silently fall back to existing logic
107
+ Write-Verbose " GitHub CLI approach failed, falling back to AppVeyor history API"
108
+ }
74
109
75
- # Find the latest build for this branch
76
- $branchBuild = $history.builds | Where-Object { $_.branch -eq $Branch } | Select-Object - First 1
77
-
78
- if (-not $branchBuild ) {
79
- Write-Verbose " No builds found for branch: $Branch "
110
+ # Fallback to existing -Branch logic if GitHub CLI didn't work
111
+ if (-not $usedGh ) {
112
+ try {
113
+ # Get recent builds and find the latest one for this branch
114
+ $apiParams = @ {
115
+ Endpoint = " projects/dataplat/dbatools/history?recordsNumber=50"
116
+ }
117
+ $history = Invoke-AppVeyorApi @apiParams
118
+
119
+ if (-not $history -or -not $history.builds ) {
120
+ Write-Verbose " No build history found"
121
+ Write-Progress - Activity " Get-AppVeyorFailure" - Completed
122
+ return
123
+ }
124
+
125
+ # Find the latest build for this branch
126
+ $branchBuild = $history.builds | Where-Object { $_.branch -eq $Branch } | Select-Object - First 1
127
+
128
+ if (-not $branchBuild ) {
129
+ Write-Verbose " No builds found for branch: $Branch "
130
+ Write-Progress - Activity " Get-AppVeyorFailure" - Completed
131
+ return
132
+ }
133
+
134
+ $BuildNumber = $branchBuild.buildNumber
135
+ Write-Verbose " Found latest build #$BuildNumber for branch '$Branch '"
136
+ } catch {
137
+ Write-Verbose " Failed to fetch build history for branch ${Branch} : $_ "
80
138
Write-Progress - Activity " Get-AppVeyorFailure" - Completed
81
139
return
82
140
}
83
-
84
- $BuildNumber = $branchBuild.buildNumber
85
- Write-Verbose " Found latest build #$BuildNumber for branch '$Branch '"
86
- } catch {
87
- Write-Verbose " Failed to fetch build history for branch ${Branch} : $_ "
88
- Write-Progress - Activity " Get-AppVeyorFailure" - Completed
89
- return
90
141
}
91
142
}
92
143
0 commit comments