github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/releases/releases.go (about) 1 package releases 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 "github.com/google/go-github/v43/github" 9 ) 10 11 const ( 12 githubNamespace = "authzed" 13 githubRepository = "spicedb" 14 ) 15 16 // GetSourceRepository returns the source repository path for SpiceDB. 17 func GetSourceRepository() string { 18 return fmt.Sprintf("github.com/%s/%s", githubNamespace, githubRepository) 19 } 20 21 // Release represents a release of SpiceDB. 22 type Release struct { 23 // Version is the version of the release. 24 Version string 25 26 // PublishedAt is when the release was published, in UTC. 27 PublishedAt time.Time 28 29 // ViewURL is the URL at which the release can be viewed. 30 ViewURL string 31 } 32 33 // GetLatestRelease returns the latest release of SpiceDB, as reported by the GitHub API. 34 func GetLatestRelease(ctx context.Context) (*Release, error) { 35 client := github.NewClient(nil) 36 release, _, err := client.Repositories.GetLatestRelease(ctx, githubNamespace, githubRepository) 37 if err != nil { 38 return nil, err 39 } 40 41 if release == nil { 42 return nil, fmt.Errorf("latest release not found") 43 } 44 45 return &Release{ 46 Version: *release.Name, 47 PublishedAt: (*release.PublishedAt).UTC(), 48 ViewURL: *release.HTMLURL, 49 }, nil 50 }