-
Notifications
You must be signed in to change notification settings - Fork 48
/
version.go
35 lines (27 loc) · 841 Bytes
/
version.go
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
package version
import (
"context"
"github.com/google/go-github/github"
"golang.org/x/mod/semver"
)
// Tag specifies the current release tag.
// It needs to be manually updated.
const Tag = "v0.33.0"
// IsNewAvailable will fetch the latest project releases
// and will compare the latest release Tag against the current Tag.
func IsNewAvailable() (bool, string, error) {
ctx := context.Background()
client := github.NewClient(nil)
releases, _, err := client.Repositories.ListReleases(ctx, "Girbons", "comics-downloader", nil)
if err != nil {
return false, "", err
}
// Compare returns an integer comparing two versions
// according to semantic version precedence.
result := semver.Compare(Tag, *releases[0].TagName)
// -1 if v < w
if result == -1 {
return true, *releases[0].HTMLURL, err
}
return false, "", err
}