Skip to content

Commit 3740f5c

Browse files
committed
internal/osv: add review status
Ecosystem metrics cannot pick up REVIEWED vs UNREVIWED unless govulncheck produces it. Change-Id: Ia6ea1ef7cf681ac51e18dd32748dc658a72ebad9 Reviewed-on: https://go-review.googlesource.com/c/vuln/+/591055 Reviewed-by: Tatiana Bradley <tatianabradley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
1 parent 29462d7 commit 3740f5c

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

internal/osv/osv.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,6 @@ type DatabaseSpecific struct {
235235
// The URL of the Go advisory for this vulnerability, of the form
236236
// "https://pkg.go.dev/GO-YYYY-XXXX".
237237
URL string `json:"url,omitempty"`
238+
// The review status of this report (UNREVIEWED or REVIEWED).
239+
ReviewStatus ReviewStatus `json:"review_status,omitempty"`
238240
}

internal/osv/review_status.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package osv
6+
7+
import (
8+
"encoding/json"
9+
"fmt"
10+
)
11+
12+
type ReviewStatus int
13+
14+
const (
15+
ReviewStatusUnknown ReviewStatus = iota
16+
ReviewStatusUnreviewed
17+
ReviewStatusReviewed
18+
)
19+
20+
var statusStrs = []string{
21+
ReviewStatusUnknown: "",
22+
ReviewStatusUnreviewed: "UNREVIEWED",
23+
ReviewStatusReviewed: "REVIEWED",
24+
}
25+
26+
func (r ReviewStatus) String() string {
27+
if !r.IsValid() {
28+
return fmt.Sprintf("INVALID(%d)", r)
29+
}
30+
return statusStrs[r]
31+
}
32+
33+
func ReviewStatusValues() []string {
34+
return statusStrs[1:]
35+
}
36+
37+
func (r ReviewStatus) IsValid() bool {
38+
return int(r) >= 0 && int(r) < len(statusStrs)
39+
}
40+
41+
func ToReviewStatus(s string) (ReviewStatus, bool) {
42+
for stat, str := range statusStrs {
43+
if s == str {
44+
return ReviewStatus(stat), true
45+
}
46+
}
47+
return 0, false
48+
}
49+
50+
func (r ReviewStatus) MarshalJSON() ([]byte, error) {
51+
if !r.IsValid() {
52+
return nil, fmt.Errorf("MarshalJSON: unrecognized review status: %d", r)
53+
}
54+
return json.Marshal(r.String())
55+
}
56+
57+
func (r *ReviewStatus) UnmarshalJSON(b []byte) error {
58+
var s string
59+
if err := json.Unmarshal(b, &s); err != nil {
60+
return err
61+
}
62+
if rs, ok := ToReviewStatus(s); ok {
63+
*r = rs
64+
return nil
65+
}
66+
return fmt.Errorf("UnmarshalJSON: unrecognized review status: %s", s)
67+
}

0 commit comments

Comments
 (0)