Files
build-emacs-for-macos/pkg/cask/release_info.go
Jim Myhrberg adbcfc6fc4 feat(cask): add cask update command to manage cask formula
This will be used by the jimeh/homebrew-emacs-builds brew tap repository
in combination with brew livecheck to automatically update cask formulas
to the latest nightly builds from the jimeh/emacs-builds repository.
2021-06-28 22:19:10 +01:00

61 lines
1009 B
Go

package cask
import (
"sort"
"strings"
)
type ReleaseInfo struct {
Name string
Version string
Assets map[string]*ReleaseAsset
}
func (s *ReleaseInfo) Asset(nameMatch string) *ReleaseAsset {
if a, ok := s.Assets[nameMatch]; ok {
return a
}
// Dirty and inefficient way to ensure assets are searched in a predictable
// order.
var assets []*ReleaseAsset
for _, a := range s.Assets {
assets = append(assets, a)
}
sort.SliceStable(assets, func(i, j int) bool {
return assets[i].Filename < assets[j].Filename
})
for _, a := range assets {
if strings.Contains(a.Filename, nameMatch) {
return a
}
}
return nil
}
func (s *ReleaseInfo) DownloadURL(nameMatch string) string {
a := s.Asset(nameMatch)
if a == nil {
return ""
}
return a.DownloadURL
}
func (s *ReleaseInfo) SHA256(nameMatch string) string {
a := s.Asset(nameMatch)
if a == nil {
return ""
}
return a.SHA256
}
type ReleaseAsset struct {
Filename string
DownloadURL string
SHA256 string
}