-
Notifications
You must be signed in to change notification settings - Fork 7
/
parser.go
65 lines (53 loc) · 1.24 KB
/
parser.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
package main
import (
"encoding/json"
"regexp"
"github.com/pkg/errors"
)
// Available is type for android library
type Available struct {
Release string
Milestone string
Integration string
}
// Dependency is type for android library
type Dependency struct {
Group string
Version string
Available Available
Name string
}
// Item is type for android library
type Item struct {
Dependencies []Dependency
count int
}
// Report is type for android library status
type Report struct {
Current Item
Exceeded Item
Outdated Item
Unresolved Item
Count int
}
func parse(reportData []byte, excludePattern *regexp.Regexp) (Report, error) {
var report Report
err := json.Unmarshal([]byte(reportData), &report)
if err != nil {
return report, errors.Wrap(err, "JSON parse failed")
}
if excludePattern != nil {
var dependencies []Dependency
for _, dependency := range report.Outdated.Dependencies {
if !excludePattern.MatchString(dependency.Pkg()) {
dependencies = append(dependencies, dependency)
}
}
report.Outdated.Dependencies = dependencies
}
return report, nil
}
// Pkg retrun full pkg name
func (dependency *Dependency) Pkg() string {
return dependency.Group + ":" + dependency.Name
}