MCPcopy Index your code
hub / github.com/coder/coder / updateCheck

Method updateCheck

coderd/updatecheck.go:22–60  ·  view source on GitHub ↗

@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)

Source from the content-addressed store, hash-verified

20// @Success 200 {object} codersdk.UpdateCheckResponse
21// @Router /api/v2/updatecheck [get]
22func (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}

Callers

nothing calls this directly

Calls 8

VersionFunction · 0.92
ExternalURLFunction · 0.92
WriteFunction · 0.92
InternalServerErrorFunction · 0.92
LatestMethod · 0.80
CompareMethod · 0.80
ContextMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected