This is a simple script to get changelog of an app in scoop. It fetches changelog from GitHub releases or CHANGELOG.md
.
Add the following to your PowerShell $PROFILE
, and try Get-Changelog <App>
.
<#
.SYNOPSIS
Get changelog of an app in scoop
.NOTES
Prerequisites:
- [scoop](https://scoop.sh).
- [gh](https://cli.github.com) to interact with GitHub API.
- [glow](https://github.com/charmbracelet/glow) to render markdown.
.EXAMPLE
Get-Changelog gh
Get changelog of gh.
.EXAMPLE
Get-Changelog gh -Verbose
Get changelog of gh and show the specific source.
.EXAMPLE
Get-Changelog just -From File
Get changelog of just from the `CHANGELOG.md` file in its repo.
.EXAMPLE
Get-Changelog main/glow
Get changelog of glow in the main bucket.
.LINK
https://github.com/ScoopInstaller/Scoop/issues/2067
.LINK
https://gist.github.com/YDX-2147483647/f8c11c3355f0e9d2aaa8c63926edde08
#>
function Get-Changelog {
param (
# An app in scoop. It will be passed to `scoop cat` directly.
[Parameter(Mandatory = $true)]
[string] $App,
# Where to fetch the changelog.
# - Release: From the GitHub release. (default)
# - File: From the `CHANGELOG.md` in its repo.
[ValidateSet("Release", "File")]
[string] $From = "Release"
)
$manifest = scoop cat $App | ConvertFrom-Json
$github_url = if ($manifest.checkver -eq 'github') {
[string]$manifest.homepage
}
elseif ($null -ne $manifest.checkver.github) {
[string]$manifest.checkver.github
}
else {
throw "Cannot find GitHub URL for `“$App`”. You can ``scoop home $App`` to open its homepage for changelog, or ``scoop cat $App`` to debug."
}
switch ($From) {
"Release" {
Write-Verbose "Fetching changelog of $App v$($manifest.version) from the release of ${github_url}."
gh release view --repo $github_url
}
"File" {
Write-Verbose "Fetching changelog of $App v$($manifest.version) from CHANGELOG.md in ${github_url}."
$owner_repo = $github_url.Replace('https://github.com/', '')
$changelog = gh api -H "Accept: application/vnd.github.raw" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${owner_repo}/contents/CHANGELOG.md
$changelog | glow -
}
Default {
throw "Fetching changelog from `“$From`” is not supported."
}
}
}
You can integrate Get-Changelog
into scoop as an alias:
scoop alias add c '"Get-Changelog $args" | Invoke-Expression'
However, PowerShell won't auto complete for you then.
> Get-Changelog pnpm
Exception: Cannot find GitHub URL for “pnpm”. You can `scoop home pnpm` to open its homepage for changelog, or `scoop cat pnpm` to debug.
Because pnpm.json
uses a script to checkver
, which is too complicated for this simple script… I will appreciate it if someone can detect the repo from autoupdate
or something.