From c016f634dd968377193c8faf62f23f5500d455b4 Mon Sep 17 00:00:00 2001 From: Tatiana Bradley Date: Wed, 5 Jun 2024 11:27:51 -0400 Subject: [PATCH] cmd/vulnreport: fix two issues with triage 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 Reviewed-by: Zvonimir Pavlinovic --- cmd/vulnreport/triage.go | 17 ++++++++++++++--- internal/issues/issues.go | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/vulnreport/triage.go b/cmd/vulnreport/triage.go index 5cc38ce2..572ed885 100644 --- a/cmd/vulnreport/triage.go +++ b/cmd/vulnreport/triage.go @@ -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" ) @@ -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" } @@ -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, "") }() diff --git a/internal/issues/issues.go b/internal/issues/issues.go index 40acddb7..273fd22a 100644 --- a/internal/issues/issues.go +++ b/internal/issues/issues.go @@ -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{