MCPcopy
hub / github.com/passteque/gluetun / GetMessage

Function GetMessage

internal/version/version.go:17–45  ·  view source on GitHub ↗

GetMessage returns a message for the user describing if there is a newer version available. It should only be called once the tunnel is established.

(ctx context.Context, buildInfo models.BuildInformation,
	client *http.Client,
)

Source from the content-addressed store, hash-verified

15// GetMessage returns a message for the user describing if there is a newer version
16// available. It should only be called once the tunnel is established.
17func GetMessage(ctx context.Context, buildInfo models.BuildInformation,
18 client *http.Client,
19) (message string, err error) {
20 if buildInfo.Version == "latest" {
21 // Find # of commits between current commit and latest commit
22 commitsSince, err := getCommitsSince(ctx, client, buildInfo.Commit)
23 if err != nil {
24 return "", err
25 } else if commitsSince == 0 {
26 return fmt.Sprintf("You are running on the bleeding edge of %s!", buildInfo.Version), nil
27 }
28 commits := "commits"
29 if commitsSince == 1 {
30 commits = "commit"
31 }
32 return fmt.Sprintf("You are running %d %s behind the most recent %s", commitsSince, commits, buildInfo.Version), nil
33 }
34 tagName, name, releaseTime, err := getLatestRelease(ctx, client)
35 if err != nil {
36 return "", err
37 }
38 if tagName == buildInfo.Version {
39 return fmt.Sprintf("You are running the latest release %s", buildInfo.Version), nil
40 }
41 timeSinceRelease := format.FriendlyDuration(time.Since(releaseTime))
42 return fmt.Sprintf("There is a new release %s (%s) created %s ago",
43 tagName, name, timeSinceRelease),
44 nil
45}
46
47var errReleaseNotFound = errors.New("release not found")
48

Callers 1

onTunnelUpMethod · 0.92

Calls 3

FriendlyDurationFunction · 0.92
getCommitsSinceFunction · 0.85
getLatestReleaseFunction · 0.85

Tested by

no test coverage detected