@Summary Update check @ID update-check @Produce json @Tags General @Success 200 {object} codersdk.UpdateCheckResponse @Router /api/v2/updatecheck [get]
(rw http.ResponseWriter, r *http.Request)
| 20 | // @Success 200 {object} codersdk.UpdateCheckResponse |
| 21 | // @Router /api/v2/updatecheck [get] |
| 22 | func (api *API) updateCheck(rw http.ResponseWriter, r *http.Request) { |
| 23 | ctx := r.Context() |
| 24 | |
| 25 | currentVersion := codersdk.UpdateCheckResponse{ |
| 26 | Current: true, |
| 27 | Version: buildinfo.Version(), |
| 28 | URL: buildinfo.ExternalURL(), |
| 29 | } |
| 30 | |
| 31 | if api.updateChecker == nil { |
| 32 | // If update checking is disabled, echo the current |
| 33 | // version. |
| 34 | httpapi.Write(ctx, rw, http.StatusOK, currentVersion) |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | uc, err := api.updateChecker.Latest(ctx) |
| 39 | if err != nil { |
| 40 | if xerrors.Is(err, sql.ErrNoRows) { |
| 41 | // Update checking is enabled, but has never |
| 42 | // succeeded, reproduce behavior as if disabled. |
| 43 | httpapi.Write(ctx, rw, http.StatusOK, currentVersion) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | httpapi.InternalServerError(rw, err) |
| 48 | return |
| 49 | } |
| 50 | |
| 51 | // Since our dev version (v0.12.9-devel+f7246386) is not semver compatible, |
| 52 | // ignore everything after "-"." |
| 53 | versionWithoutDevel := strings.SplitN(buildinfo.Version(), "-", 2)[0] |
| 54 | |
| 55 | httpapi.Write(ctx, rw, http.StatusOK, codersdk.UpdateCheckResponse{ |
| 56 | Current: semver.Compare(versionWithoutDevel, uc.Version) >= 0, |
| 57 | Version: uc.Version, |
| 58 | URL: uc.URL, |
| 59 | }) |
| 60 | } |
nothing calls this directly
no test coverage detected