summaryrefslogtreecommitdiff
path: root/vendor/github.com/authzed/spicedb/pkg/releases/releases.go
blob: 62451fd93460b547af14682a81ccd6fad4efaa85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package releases

import (
	"context"
	"fmt"
	"time"

	"github.com/google/go-github/v43/github"
)

const (
	githubNamespace  = "authzed"
	githubRepository = "spicedb"
)

// GetSourceRepository returns the source repository path for SpiceDB.
func GetSourceRepository() string {
	return fmt.Sprintf("github.com/%s/%s", githubNamespace, githubRepository)
}

// Release represents a release of SpiceDB.
type Release struct {
	// Version is the version of the release.
	Version string

	// PublishedAt is when the release was published, in UTC.
	PublishedAt time.Time

	// ViewURL is the URL at which the release can be viewed.
	ViewURL string
}

// GetLatestRelease returns the latest release of SpiceDB, as reported by the GitHub API.
func GetLatestRelease(ctx context.Context) (*Release, error) {
	client := github.NewClient(nil)
	release, _, err := client.Repositories.GetLatestRelease(ctx, githubNamespace, githubRepository)
	if err != nil {
		return nil, err
	}

	if release == nil {
		return nil, fmt.Errorf("latest release not found")
	}

	return &Release{
		Version:     *release.Name,
		PublishedAt: (*release.PublishedAt).UTC(),
		ViewURL:     *release.HTMLURL,
	}, nil
}