Skip to content

Commit 890bd22

Browse files
authored
Merge pull request #3 from psampaz/invalid_updates
Check for invalid updates + internal packages
2 parents d1a92e6 + 5742433 commit 890bd22

File tree

13 files changed

+712
-391
lines changed

13 files changed

+712
-391
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55

6+
## [0.2.0] - 2019-04-22
7+
### Added
8+
- Extra column 'VALID TIMESTAMPS' which indicates if the timestamp of the new version is
9+
actually newer that the current one
10+
### Changed
11+
- Packages are now internal
12+
613
## [0.1.0] - 2019-04-22
714
### Added
815
- Initial release

README.md

Lines changed: 213 additions & 184 deletions
Large diffs are not rendered by default.

internal/mod/mod.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package mod
2+
3+
import (
4+
"time"
5+
)
6+
7+
// Module holds information about a specifc module listed by go list
8+
type Module struct {
9+
Path string `json:",omitempty"` // module path
10+
Version string `json:",omitempty"` // module version
11+
Versions []string `json:",omitempty"` // available module versions
12+
Replace *Module `json:",omitempty"` // replaced by this module
13+
Time *time.Time `json:",omitempty"` // time version was created
14+
Update *Module `json:",omitempty"` // available update (with -u)
15+
Main bool `json:",omitempty"` // is this the main module?
16+
Indirect bool `json:",omitempty"` // module is only indirectly needed by main module
17+
Dir string `json:",omitempty"` // directory holding local copy of files, if any
18+
GoMod string `json:",omitempty"` // path to go.mod file describing module, if any
19+
Error *ModuleError `json:",omitempty"` // error loading module
20+
GoVersion string `json:",omitempty"` // go version used in module
21+
}
22+
23+
type ModuleError struct {
24+
Err string // error text
25+
}
26+
27+
// InvalidTimestamp checks if the version reported as update by the go list command is actually newer that current version
28+
func (m *Module) InvalidTimestamp() bool {
29+
var mod Module
30+
if m.Replace != nil {
31+
mod = *m.Replace
32+
} else {
33+
mod = *m
34+
}
35+
36+
if mod.Time != nil && mod.Update != nil {
37+
return mod.Time.After(*mod.Update.Time)
38+
}
39+
40+
return false
41+
}
42+
43+
// CurrentVersion returns the current version of the module taking into consideration the any Replace settings
44+
func (m *Module) CurrentVersion() string {
45+
var mod Module
46+
if m.Replace != nil {
47+
mod = *m.Replace
48+
49+
} else {
50+
mod = *m
51+
}
52+
53+
return mod.Version
54+
}
55+
56+
// HasUpdate checks if the module has a new version
57+
func (m *Module) HasUpdate() bool {
58+
var mod Module
59+
if m.Replace != nil {
60+
mod = *m.Replace
61+
} else {
62+
mod = *m
63+
}
64+
65+
return mod.Update != nil
66+
}
67+
68+
// New Version returns the version of the update taking into consideration the any Replace settings
69+
func (m *Module) NewVersion() string {
70+
var mod Module
71+
if m.Replace != nil {
72+
mod = *m.Replace
73+
} else {
74+
mod = *m
75+
}
76+
77+
if mod.Update == nil {
78+
return ""
79+
}
80+
81+
return mod.Update.Version
82+
}
83+
84+
// FilterModules filters the list of modules provided by the go list command
85+
func FilterModules(modules []Module, hasUpdate, isDirect bool) []Module {
86+
out := make([]Module, 0)
87+
for k := range modules {
88+
89+
if modules[k].Main {
90+
continue
91+
}
92+
93+
if hasUpdate && modules[k].Update == nil {
94+
continue
95+
}
96+
97+
if isDirect && modules[k].Indirect {
98+
continue
99+
}
100+
101+
out = append(out, modules[k])
102+
}
103+
104+
return out
105+
}

0 commit comments

Comments
 (0)