-
Notifications
You must be signed in to change notification settings - Fork 14
/
version.go
67 lines (54 loc) · 2.13 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package validate
import (
"go.lsp.dev/protocol"
"golang.org/x/mod/semver"
)
type InfoVersions struct {
LatestVersion string
LatestMinorVersion string
LatestPatchVersion string
}
/**
* Calculate diagnostic information about a package version.
* version: Version of the package to diagnostic
* infoVersions: Several information about the given package
*/
func DiagnosticVersion(version string, infoVersions InfoVersions) (string, protocol.DiagnosticSeverity) {
// Displaying a warning if the version is a pre-release (ex: 0.x.x),
// and a release version exists (ex: 1.20.3)*
if semver.Major("v"+version) == "v0" && semver.Major("v"+infoVersions.LatestVersion) != "v0" {
return "A production version has been released. Latest: " + infoVersions.LatestVersion,
protocol.DiagnosticSeverityWarning
}
// Displaying a warning if a patched version exists
if infoVersions.LatestPatchVersion != version {
text := "A newer patched version exists.\n"
text += "- Current: " + version + "\n"
if infoVersions.LatestVersion != infoVersions.LatestMinorVersion {
if infoVersions.LatestMinorVersion != infoVersions.LatestPatchVersion {
text += "- Patch: " + infoVersions.LatestPatchVersion + "\n"
}
text += "- Minor: " + infoVersions.LatestMinorVersion + "\n"
}
text += "- Latest: " + infoVersions.LatestVersion
return text, protocol.DiagnosticSeverityWarning
}
// Displaying an info if a new minor exists
if infoVersions.LatestMinorVersion != version {
text := "A newer minor version exists.\n"
text += "- Current: " + version + "\n"
if infoVersions.LatestVersion != infoVersions.LatestMinorVersion {
text += "- Minor: " + infoVersions.LatestMinorVersion + "\n"
}
text += "- Latest: " + infoVersions.LatestVersion
return text, protocol.DiagnosticSeverityInformation
}
// Displaying an info if a new major exists
if infoVersions.LatestVersion != version {
text := "A newer major version exists.\n"
text += "- Current: " + version + "\n"
text += "- Latest: " + infoVersions.LatestVersion
return text, protocol.DiagnosticSeverityInformation
}
return "", protocol.DiagnosticSeverityInformation
}