@@ -195,67 +195,46 @@ if ("$Tag" -eq '')
195195 {
196196 Write-Host " Filtering tags by GitHub release title pattern '$GhTitlePattern '"
197197
198- # Check if URL is a GitHub URL first
199- if ($url -notmatch ' github\.com' )
198+ # Parse GitHub repo owner/name from URL
199+ if ($url -notmatch ' github\.com[:/]([^/]+)/([^/]+?)(?:\.git)?$ ' )
200200 {
201201 throw " Could not parse GitHub owner/repo from URL: $url "
202202 }
203203
204- # Parse GitHub repo owner/name from URL
205- if ($url -match ' github\.com[:/]([^/]+)/([^/]+?)(?:\.git)?$' )
204+ $owner , $repo = $Matches [1 ], $Matches [2 ]
205+
206+ try
206207 {
207- $owner = $Matches [ 1 ]
208- $repo = $Matches [ 2 ]
208+ # Fetch releases from GitHub API
209+ $releases = @ (gh api " repos/ $owner / $repo /releases " -- jq ' .[] | {tag_name: .tag_name, name: .name} ' | ConvertFrom-Json )
209210
210- try
211+ # Find tags that have matching release titles
212+ $validTags = @ {}
213+ foreach ($release in $releases )
211214 {
212- # Fetch releases from GitHub API (first 30 releases should be sufficient for most cases)
213- $releases = gh api " repos/$owner /$repo /releases" -- jq ' .[] | {tag_name: .tag_name, name: .name}' | ConvertFrom-Json
214-
215- # Handle case where releases might be null or single object
216- if ($null -eq $releases )
215+ if ($release.name -match $GhTitlePattern )
217216 {
218- $releases = @ ()
219- }
220- elseif ($releases -isnot [array ])
221- {
222- $releases = @ ($releases )
223- }
224-
225- # Create a hashtable of tag->title mappings for releases that match the pattern
226- $validTags = @ {}
227- foreach ($release in $releases )
228- {
229- if ($release.name -match $GhTitlePattern )
230- {
231- $validTags [$release.tag_name ] = $true
232- }
217+ $validTags [$release.tag_name ] = $true
233218 }
219+ }
234220
235- # Filter tags to only include those with matching release titles
236- $originalTagCount = $tags.Length
237- $tags = @ ($tags | Where-Object { $validTags.ContainsKey ($_ ) })
238- Write-Host " GitHub release title filtering: $originalTagCount -> $ ( $tags.Count ) tags"
221+ # Filter tags to only include those with matching release titles
222+ $originalTagCount = $tags.Length
223+ $tags = @ ($tags | Where-Object { $validTags.ContainsKey ($_ ) })
224+ Write-Host " GitHub release title filtering: $originalTagCount -> $ ( $tags.Count ) tags"
239225
240- if ($tags.Count -le 0 )
241- {
242- throw " Found no tags with GitHub releases matching title pattern '$GhTitlePattern '"
243- }
244- }
245- catch
226+ if ($tags.Count -eq 0 )
246227 {
247- # If it's our specific "no matching tags" error, re-throw it
248- if ($_.Exception.Message -like " *Found no tags with GitHub releases matching title pattern*" )
249- {
250- throw
251- }
252- # Otherwise, wrap it as a GitHub API error
253- throw " Failed to fetch GitHub releases for $owner /$repo `: $ ( $_.Exception.Message ) "
228+ throw " Found no tags with GitHub releases matching title pattern '$GhTitlePattern '"
254229 }
255230 }
256- else
231+ catch
257232 {
258- throw " Could not parse GitHub owner/repo from URL: $url "
233+ if ($_.Exception.Message -like " *Found no tags with GitHub releases matching title pattern*" )
234+ {
235+ throw
236+ }
237+ throw " Failed to fetch GitHub releases for $owner /$repo `: $ ( $_.Exception.Message ) "
259238 }
260239 }
261240
0 commit comments