-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
29462d7
commit 3740f5c
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package osv | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type ReviewStatus int | ||
|
||
const ( | ||
ReviewStatusUnknown ReviewStatus = iota | ||
ReviewStatusUnreviewed | ||
ReviewStatusReviewed | ||
) | ||
|
||
var statusStrs = []string{ | ||
ReviewStatusUnknown: "", | ||
ReviewStatusUnreviewed: "UNREVIEWED", | ||
ReviewStatusReviewed: "REVIEWED", | ||
} | ||
|
||
func (r ReviewStatus) String() string { | ||
if !r.IsValid() { | ||
return fmt.Sprintf("INVALID(%d)", r) | ||
} | ||
return statusStrs[r] | ||
} | ||
|
||
func ReviewStatusValues() []string { | ||
return statusStrs[1:] | ||
} | ||
|
||
func (r ReviewStatus) IsValid() bool { | ||
return int(r) >= 0 && int(r) < len(statusStrs) | ||
} | ||
|
||
func ToReviewStatus(s string) (ReviewStatus, bool) { | ||
for stat, str := range statusStrs { | ||
if s == str { | ||
return ReviewStatus(stat), true | ||
} | ||
} | ||
return 0, false | ||
} | ||
|
||
func (r ReviewStatus) MarshalJSON() ([]byte, error) { | ||
if !r.IsValid() { | ||
return nil, fmt.Errorf("MarshalJSON: unrecognized review status: %d", r) | ||
} | ||
return json.Marshal(r.String()) | ||
} | ||
|
||
func (r *ReviewStatus) UnmarshalJSON(b []byte) error { | ||
var s string | ||
if err := json.Unmarshal(b, &s); err != nil { | ||
return err | ||
} | ||
if rs, ok := ToReviewStatus(s); ok { | ||
*r = rs | ||
return nil | ||
} | ||
return fmt.Errorf("UnmarshalJSON: unrecognized review status: %s", s) | ||
} |