Skip to content

Commit

Permalink
cmd/vulnreport: fix two issues with triage
Browse files Browse the repository at this point in the history
1. Don't remove existing labels when triaging
2. Skip issues already marked excluded when triaging

Change-Id: I5e3fd3a614f56407d75c920202937b4534fe15c9
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/590776
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
  • Loading branch information
tatianab committed Jun 5, 2024
1 parent b195240 commit c016f63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions cmd/vulnreport/triage.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strings"
"sync"

"golang.org/x/exp/slices"
"golang.org/x/vulndb/cmd/vulnreport/log"
"golang.org/x/vulndb/internal/issues"
)
Expand Down Expand Up @@ -79,6 +80,10 @@ func (t *triage) skip(input any) string {
return "direct external report"
}

if isExcluded(iss) {
return "excluded"
}

if !*force && iss.HasLabel(labelTriaged) {
return "already triaged; use -f to force re-triage"
}
Expand All @@ -101,10 +106,16 @@ type priorityResult struct {
func (t *triage) triage(ctx context.Context, iss *issues.Issue) {
labels := []string{labelTriaged}
defer func() {
// Preserve any existing labels.
labels = append(labels, iss.Labels...)
slices.Sort(labels)
labels = slices.Compact(labels)
if *dry {
log.Infof("issue #%d: would add labels: [%s]", iss.Number, strings.Join(labels, ", "))
} else if err := t.ic.AddLabels(ctx, iss.Number, labels); err != nil {
log.Warnf("issue #%d: could not auto-add label(s) ", iss.Number)
log.Infof("issue #%d: would set labels: [%s]", iss.Number, strings.Join(labels, ", "))
} else {
if err := t.ic.SetLabels(ctx, iss.Number, labels); err != nil {
log.Warnf("issue #%d: could not auto-set label(s) %s", iss.Number, labels)
}
}
t.addStat(iss, statTriaged, "")
}()
Expand Down
2 changes: 1 addition & 1 deletion internal/issues/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (c *Client) CreateIssue(ctx context.Context, iss *Issue) (number int, err e
return giss.GetNumber(), nil
}

func (c *Client) AddLabels(ctx context.Context, issNum int, labels []string) (err error) {
func (c *Client) SetLabels(ctx context.Context, issNum int, labels []string) (err error) {
defer derrors.Wrap(&err, "AddLabels(%d, %s)", issNum, labels)

req := &github.IssueRequest{
Expand Down

0 comments on commit c016f63

Please sign in to comment.