Skip to content

Commit

Permalink
Query the GitHub API correctly (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
natsukagami authored Apr 17, 2020
1 parent 7944175 commit 29241eb
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions server/admin/message_prod.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@ var currentVersion version
// NewVersionMessageGet checks if there is a new version of kjudge
func NewVersionMessageGet() (string, error) {
if currentVersion.TagName == "" || time.Now().After(currentVersion.LastUpdate.Add(time.Hour)) {
response, err := http.Get("https://github.com/api/v1/repos/natsukagami/kjudge/releases?page=1&per_page=1")
response, err := http.Get("https://api.github.com/repos/natsukagami/kjudge/releases/latest")
if err != nil {
return "", errors.WithStack(err)
}
defer response.Body.Close()
var x []jsonRelease
var x jsonRelease
decode := json.NewDecoder(response.Body)
if err := decode.Decode(&x); err != nil {
return "", errors.WithStack(err)
}
if len(x) == 0 {
return "", errors.New("Found no relase")
}
currentVersion.TagName = x[0].TagName[1:]
currentVersion.TagName = x.TagName[1:]
currentVersion.LastUpdate = time.Now()
}
if kjudge.Version != currentVersion.TagName {
Expand Down

0 comments on commit 29241eb

Please sign in to comment.