From 29241eb5f58ee647f0b106d78e47a83642ffaf00 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Fri, 17 Apr 2020 13:40:19 -0400 Subject: [PATCH] Query the GitHub API correctly (#8) --- server/admin/message_prod.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/server/admin/message_prod.go b/server/admin/message_prod.go index 740c6cf..54113f0 100644 --- a/server/admin/message_prod.go +++ b/server/admin/message_prod.go @@ -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 {