cmd/vulnreport: use non-hardcoded year in issue filenames
Change hardcoded "GO-2021-" prefix to use the year the GitHub issue was
created.
Fixes golang/go#52840.
Change-Id: Iad694e886e496adc2a783cde5808d640c7af70e7
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/405634
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/cmd/vulnreport/main.go b/cmd/vulnreport/main.go
index e2f31ee..aa1e1a9 100644
--- a/cmd/vulnreport/main.go
+++ b/cmd/vulnreport/main.go
@@ -159,7 +159,11 @@
return fmt.Errorf("expected last element of title to be the CVE ID or GHSA ID; got %q", iss.Title)
}
addTODOs(r)
- return r.Write(fmt.Sprintf("reports/GO-2021-%04d.yaml", issueNumber))
+ var year int
+ if !iss.CreatedAt.IsZero() {
+ year = iss.CreatedAt.Year()
+ }
+ return r.Write(fmt.Sprintf("reports/GO-%04d-%04d.yaml", year, issueNumber))
}
const todo = "TODO: fill this out"
diff --git a/internal/issues/issues.go b/internal/issues/issues.go
index e7a9baf..ca4ef7b 100644
--- a/internal/issues/issues.go
+++ b/internal/issues/issues.go
@@ -9,6 +9,7 @@
import (
"context"
"fmt"
+ "time"
"github.com/google/go-github/v41/github"
"golang.org/x/oauth2"
@@ -17,9 +18,10 @@
// An Issue represents a GitHub issue or similar.
type Issue struct {
- Title string
- Body string
- Labels []string
+ Title string
+ Body string
+ Labels []string
+ CreatedAt time.Time
}
// Client is a client that can create and retrieve issues.
@@ -98,6 +100,9 @@
if iss.Body != nil {
r.Body = *iss.Body
}
+ if iss.CreatedAt != nil {
+ r.CreatedAt = *iss.CreatedAt
+ }
return r, nil
}