Skip to content

Commit 2016cf9

Browse files
committed
fix: show only date in GL report header
1 parent c7c1d7b commit 2016cf9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

internal/publish/to_gitlab.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
// which is how we want to display it in the
1717
var severityScoreOrder = getSeverityScoreOrder(scanner.SeverityScoreThresholds)
1818

19+
// now is a function that returns the current time
20+
var now = time.Now
21+
1922
// PublishAsGitlabIssues creates or updates GitLab Issue reports for the given reports
2023
// It will add the Issue URL to the Report if it was created or updated successfully
2124
func PublishAsGitlabIssues(reports []scanner.Report, s gitlab.IService) {
@@ -133,12 +136,12 @@ func markdownBoolean(b bool) string {
133136

134137
// getVulnReportHeader returns the header for the vulnerability report
135138
func getVulnReportHeader() string {
136-
currentTime := time.Now().Local()
139+
currentTime := now().Local()
137140

138141
return fmt.Sprintf(`
139142
ℹ️ This issue lists all the vulnerabilities found in the project by [Sheriff](https://gitlab.com/namespace/sheriff) on %s.
140143
141144
Please review the vulnerabilities and take the necessary actions to fix or acknowledge them, see the [sheriff documentation](https://security-scanner-c26e93.gitlab.io/user-guide/) for more information.`,
142-
currentTime.Format("2006-01-02 15:04:05"),
145+
currentTime.Format("2006-01-02"),
143146
)
144147
}

internal/publish/to_gitlab_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package publish
33
import (
44
"sheriff/internal/scanner"
55
"testing"
6+
"time"
67

78
"github.com/stretchr/testify/assert"
89
"github.com/stretchr/testify/mock"
@@ -184,6 +185,23 @@ func TestPublishAsGitlabIssues(t *testing.T) {
184185

185186
}
186187

188+
func TestGitlabIssueReportHeader(t *testing.T) {
189+
origNow := now
190+
now = func() time.Time {
191+
return time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
192+
}
193+
defer func() {
194+
now = origNow
195+
}()
196+
197+
got := getVulnReportHeader()
198+
199+
want := `ℹ️ This issue lists all the vulnerabilities found in the project by [Sheriff](https://gitlab.com/namespace/sheriff) on 2021-01-01.`
200+
201+
assert.Contains(t, got, want)
202+
203+
}
204+
187205
type mockGitlabService struct {
188206
mock.Mock
189207
}

0 commit comments

Comments
 (0)