forked from chanzuckerberg/fogg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.go
44 lines (38 loc) · 1.04 KB
/
github.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
36
37
38
39
40
41
42
43
44
package util
import (
"context"
"fmt"
"github.com/chanzuckerberg/go-misc/github"
"github.com/sirupsen/logrus"
)
// CheckLatestVersion checks to see if we're on the latest version
func CheckLatestVersion(ctx context.Context, owner string, repo string) error {
err := checkLatestVersion(ctx, owner, repo)
if err != nil {
logrus.WithError(err).WithField("repo", fmt.Sprintf("%s/%s", owner, repo)).Warn("Could not fetch latest release info")
return err
}
return nil
}
func checkLatestVersion(ctx context.Context, owner string, repo string) error {
currentVersion, err := VersionString()
if err != nil {
return err
}
githubClient := github.NewClient(nil)
versions, err := githubClient.CheckLatestVersion(ctx, owner, repo, currentVersion)
if err != nil {
return err
}
outdated, err := versions.Outdated(currentVersion)
if err != nil {
return err
}
if outdated {
logrus.
WithField("current_version", currentVersion).
WithField("latest_version", versions.Latest()).
Warnf("Please upgrade %s/%s", owner, repo)
}
return nil
}