-
Notifications
You must be signed in to change notification settings - Fork 8
/
updates.go
67 lines (50 loc) · 1.4 KB
/
updates.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"time"
"strings"
"github.com/octokit/go-octokit/octokit"
)
type Update struct {
Version string `json:"version,omitempty"`
ReleaseURL string `json:"release_url,omitempty"`
Name string `json:"name"`
PreRelease bool `json:"is_prerelease"`
PublishedAt *time.Time `json:"published_at"`
Body string `json:"description"`
}
func checkForUpdate(currVer string) *Update {
githubClient := octokit.NewClient(nil)
releaseURL, err := octokit.ReleasesURL.Expand(octokit.M{"owner": "smurfpandey", "repo": "mysqlweb"})
if err != nil {
return nil
}
releases, result := githubClient.Releases(releaseURL).All()
if result.HasError() {
return nil
}
latestRelease := releases[0]
latestVersion := latestRelease.TagName
if strings.HasPrefix(latestVersion, "v") {
//Remove v then compare
latestVersion = strings.Replace(latestVersion, "v", "", 1)
}
isNew := compareVersion(currVer, latestVersion)
if isNew == 0 || isNew == -1 {
return nil
}
//We got a new release
//Better inform the user
//But let's make sure its not a Draft
if latestRelease.Draft {
return nil
}
update := Update{
Version: latestRelease.TagName,
ReleaseURL: latestRelease.HTMLURL,
Name: latestRelease.Name,
PreRelease: latestRelease.Prerelease,
PublishedAt: latestRelease.PublishedAt,
Body: latestRelease.Body,
}
return &update
}