Skip to content

Commit 4ad8671

Browse files
committed
cmd/vulnreport: further unify code of vulnreport regen and review
Change-Id: I1da43b41d7972860760121211de6f47abf0a2c30 Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/595635 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
1 parent f8ec560 commit 4ad8671

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

cmd/vulnreport/creator.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func (c *creator) reportFromMeta(ctx context.Context, meta *reportMeta) (*yamlRe
148148
report.WithModulePath(meta.modulePath),
149149
report.WithAliases(aliases),
150150
report.WithReviewStatus(meta.reviewStatus),
151+
report.WithUnexcluded(meta.unexcluded),
151152
)
152153

153154
if meta.excluded != "" {
@@ -283,11 +284,11 @@ func aliases(iss *issues.Issue) (aliases []string) {
283284
// Data that can be combined with a source vulnerability
284285
// to create a new report.
285286
type reportMeta struct {
286-
id string
287-
modulePath string
288-
aliases []string
289-
excluded report.ExcludedReason
290-
reviewStatus report.ReviewStatus
287+
id string
288+
modulePath string
289+
aliases []string
290+
excluded, unexcluded report.ExcludedReason
291+
reviewStatus report.ReviewStatus
291292
}
292293

293294
const todo = "TODO: "

cmd/vulnreport/regenerate.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,11 @@ func (u *regenerate) run(ctx context.Context, input any) (err error) {
6666
}
6767
}
6868

69-
var modulePath string
70-
if len(oldR.Modules) > 0 {
71-
modulePath = oldR.Modules[0].Module
72-
}
73-
74-
r, err := u.reportFromMeta(ctx, &reportMeta{
75-
id: oldR.ID,
76-
modulePath: modulePath,
77-
aliases: oldR.Aliases(),
78-
reviewStatus: oldR.ReviewStatus,
79-
})
69+
r, err := u.reportFromMeta(ctx, oldR.meta())
8070
if err != nil {
8171
return err
8272
}
8373

84-
r.Unexcluded = oldR.Unexcluded
85-
8674
if !cmp.Equal(r, oldR,
8775
cmpopts.IgnoreFields(report.SourceMeta{}, "Created"),
8876
// VulnerableAt can change based on latest published version, so we don't
@@ -95,3 +83,18 @@ func (u *regenerate) run(ctx context.Context, input any) (err error) {
9583

9684
return nil
9785
}
86+
87+
func (r *yamlReport) meta() *reportMeta {
88+
var modulePath string
89+
if len(r.Modules) > 0 {
90+
modulePath = r.Modules[0].Module
91+
}
92+
93+
return &reportMeta{
94+
id: r.ID,
95+
modulePath: modulePath,
96+
aliases: r.Aliases(),
97+
reviewStatus: r.ReviewStatus,
98+
unexcluded: r.Unexcluded,
99+
}
100+
}

cmd/vulnreport/review.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,10 @@ func (u *review) skip(input any) string {
4747
}
4848

4949
func (u *review) run(ctx context.Context, input any) (err error) {
50-
oldR := input.(*yamlReport)
50+
meta := input.(*yamlReport).meta()
51+
meta.reviewStatus = report.Reviewed
5152

52-
var modulePath string
53-
if len(oldR.Modules) > 0 {
54-
modulePath = oldR.Modules[0].Module
55-
}
56-
57-
r, err := u.reportFromMeta(ctx, &reportMeta{
58-
id: oldR.ID,
59-
modulePath: modulePath,
60-
aliases: oldR.Aliases(),
61-
reviewStatus: report.Reviewed,
62-
})
53+
r, err := u.reportFromMeta(ctx, meta)
6354
if err != nil {
6455
return err
6556
}

internal/report/new.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func New(src Source, pc *proxy.Client, opts ...NewOption) *Report {
3232
}
3333
r.SourceMeta.Created = &cfg.Created
3434
r.ReviewStatus = cfg.ReviewStatus
35+
r.Unexcluded = cfg.Unexcluded
3536

3637
if r.hasExternalSource() {
3738
r.addSourceAdvisory()
@@ -102,12 +103,19 @@ func WithReviewStatus(status ReviewStatus) NewOption {
102103
}
103104
}
104105

106+
func WithUnexcluded(reason ExcludedReason) NewOption {
107+
return func(h *cfg) {
108+
h.Unexcluded = reason
109+
}
110+
}
111+
105112
type cfg struct {
106113
ModulePath string
107114
Aliases []string
108115
Created time.Time
109116
GoID string
110117
ReviewStatus ReviewStatus
118+
Unexcluded ExcludedReason
111119
}
112120

113121
const PendingID = "GO-ID-PENDING"

0 commit comments

Comments
 (0)