@@ -138,18 +138,14 @@ jobs:
138138 $oldTagName = "v$OldVersion"
139139 }
140140
141- $escapedTagName = [System.Uri]::EscapeDataString($tagName)
142-
143141 return @{
144142 RepoPath = $repoPath
145143 RepoUrl = $repoUrl
146144 ReleasesUrl = "$repoUrl/releases"
147145 ReleaseUrl = "$repoUrl/releases/tag/$tagName"
148146 CompareUrl = "$repoUrl/compare/$oldTagName...$tagName"
149- ActionsUrl = "$repoUrl/actions?query=branch%3A$escapedTagName"
150147 OldTagName = $oldTagName
151148 TagName = $tagName
152- EscapedTagName = $escapedTagName
153149 }
154150 }
155151
@@ -187,6 +183,60 @@ jobs:
187183 return Invoke-RestMethod @params
188184 }
189185
186+ function Get-ReadmeBuildStatusBadge {
187+ param(
188+ [Parameter(Mandatory = $true)]
189+ [string]$RepoPath
190+ )
191+
192+ try {
193+ $readme = Invoke-GitHubApi -Uri "https://api.github.com/repos/$RepoPath/readme"
194+ if ([string]::IsNullOrWhiteSpace($readme.content)) {
195+ return '—'
196+ }
197+
198+ $bytes = [System.Convert]::FromBase64String(($readme.content -replace '\s', ''))
199+ $markdown = [System.Text.Encoding]::UTF8.GetString($bytes)
200+ $matches = [regex]::Matches($markdown, '\[!\[(?<alt>[^\]]*)\]\((?<image>[^)]*)\)\]\((?<target>[^)]*)\)')
201+
202+ $bestBadge = $null
203+ $bestScore = 0
204+ foreach ($match in $matches) {
205+ $alt = $match.Groups['alt'].Value
206+ $image = $match.Groups['image'].Value
207+ $target = $match.Groups['target'].Value
208+ $haystack = "$alt $image $target".ToLowerInvariant()
209+ $score = 0
210+
211+ if ($alt -match '(?i)\b(build|status|ci|check)\b') {
212+ $score += 8
213+ }
214+ if ($image -match '(?i)(actions/workflows|/workflows/|dev\.azure\.com|badge\.svg)') {
215+ $score += 6
216+ }
217+ if ($target -match '(?i)(/actions|actions/workflows|dev\.azure\.com|/_build/)') {
218+ $score += 4
219+ }
220+ if ($haystack -match '(?i)(codecov|gitter|discord|covenant|visualstudiocode|open%20in)') {
221+ $score -= 8
222+ }
223+
224+ if ($score -gt $bestScore) {
225+ $bestScore = $score
226+ $bestBadge = $match.Value
227+ }
228+ }
229+
230+ if ($bestScore -gt 0 -and -not [string]::IsNullOrWhiteSpace($bestBadge)) {
231+ return $bestBadge
232+ }
233+ } catch {
234+ Write-Verbose "Unable to fetch README build badge for ${RepoPath}: $($_.Exception.Message)" -Verbose
235+ }
236+
237+ return '—'
238+ }
239+
190240 function Get-ReleaseTitle {
191241 param(
192242 [Parameter(Mandatory = $true)]
@@ -353,11 +403,11 @@ jobs:
353403 if ($null -ne $releaseInfo) {
354404 $repoUrl = $releaseInfo.ReleasesUrl
355405 $releaseUrl = $releaseInfo.ReleaseUrl
356- $statusBadge = "[/$($ releaseInfo.EscapedTagName)`?label=build)]($($releaseInfo.ActionsUrl))"
406+ $statusBadge = Get-ReadmeBuildStatusBadge - RepoPath $ releaseInfo.RepoPath
357407 } else {
358408 $repoUrl = ($repoUrl = $s.Url.Replace("/archive/", "/releases/")).Substring(0, $repoUrl.IndexOf("/releases/")) + "/releases"
359409 $releaseUrl = $repoUrl
360- $statusBadge = ""
410+ $statusBadge = "— "
361411 }
362412
363413 # Store single dependency info for messages (only if this is the only update)
0 commit comments