|
| 1 | +function Invoke-ListGitHubReleaseNotes { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + Retrieves release notes for a GitHub repository. |
| 5 | + .DESCRIPTION |
| 6 | + Returns release metadata for the provided repository and semantic version. Hotfix |
| 7 | + versions (e.g. v8.5.2) map back to the base release tag (v8.5.0). |
| 8 | + .FUNCTIONALITY |
| 9 | + Entrypoint,AnyTenant |
| 10 | + .ROLE |
| 11 | + CIPP.Core.Read |
| 12 | + #> |
| 13 | + [CmdletBinding()] |
| 14 | + param($Request, $TriggerMetadata) |
| 15 | + |
| 16 | + $Owner = $Request.Query.Owner |
| 17 | + $Repository = $Request.Query.Repository |
| 18 | + |
| 19 | + if (-not $Owner) { |
| 20 | + throw 'Owner parameter is required to retrieve release notes.' |
| 21 | + } |
| 22 | + |
| 23 | + if (-not $Repository) { |
| 24 | + throw 'Repository parameter is required to retrieve release notes.' |
| 25 | + } |
| 26 | + |
| 27 | + $ReleasePath = "repos/$Owner/$Repository/releases?per_page=50" |
| 28 | + |
| 29 | + $Table = Get-CIPPTable -TableName cacheGitHubReleaseNotes |
| 30 | + $PartitionKey = 'GitHubReleaseNotes' |
| 31 | + $Filter = "PartitionKey eq '$PartitionKey'" |
| 32 | + $Rows = Get-CIPPAzDataTableEntity @Table -filter $Filter | Where-Object -Property Timestamp -GT (Get-Date).AddHours(-24) |
| 33 | + |
| 34 | + try { |
| 35 | + if ($Rows) { |
| 36 | + $Releases = ConvertFrom-Json -InputObject $Rows.GitHubReleases -Depth 10 |
| 37 | + } else { |
| 38 | + $Releases = Invoke-GitHubApiRequest -Path $ReleasePath |
| 39 | + $Releases = $Releases | ForEach-Object { |
| 40 | + [ordered]@{ |
| 41 | + name = $_.name |
| 42 | + body = $_.body |
| 43 | + releaseTag = $_.tag_name |
| 44 | + htmlUrl = $_.html_url |
| 45 | + publishedAt = $_.published_at |
| 46 | + draft = [bool]$_.draft |
| 47 | + prerelease = [bool]$_.prerelease |
| 48 | + commitish = $_.target_commitish |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + $Results = @{ |
| 53 | + GitHubReleases = [string](ConvertTo-Json -Depth 10 -InputObject $Releases) |
| 54 | + RowKey = [string]'GitHubReleaseNotes' |
| 55 | + PartitionKey = $PartitionKey |
| 56 | + } |
| 57 | + Add-CIPPAzDataTableEntity @Table -Entity $Results -Force | Out-Null |
| 58 | + } |
| 59 | + |
| 60 | + } catch { |
| 61 | + $ErrorMessage = "Failed to retrieve release information: $($_)" |
| 62 | + throw $ErrorMessage |
| 63 | + } |
| 64 | + |
| 65 | + if (-not $Releases) { |
| 66 | + return $IsListRequest ? @() : (throw "No releases returned for $Owner/$Repository") |
| 67 | + } |
| 68 | + |
| 69 | + return $Releases |
| 70 | +} |
0 commit comments