Skip to content

Commit

Permalink
Merge pull request #56 from underdog-tech/feat/slack-block-kit
Browse files Browse the repository at this point in the history
feat: Use Slack Block Kit for report formatting
  • Loading branch information
tarkatronic authored May 25, 2023
2 parents 9b78d09 + 49fe77d commit 9193a07
Show file tree
Hide file tree
Showing 6 changed files with 374 additions and 164 deletions.
7 changes: 4 additions & 3 deletions internal/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func Scan(cmd *cobra.Command, args []string) {
}
reporters = append(reporters, &reporting.ConsoleReporter{Config: userConfig})

reportTime := time.Now().Format(time.RFC1123)
ghOrgName, allRepos := api.QueryGithubOrgVulnerabilities(ghOrgLogin, *ghClient)
repositoryOwners := api.QueryGithubOrgRepositoryOwners(ghOrgLogin, *ghClient)
// Count our vulnerabilities
Expand All @@ -62,8 +63,7 @@ func Scan(cmd *cobra.Command, args []string) {
vulnsByTeam := reporting.GroupVulnsByOwner(allRepos, repositoryOwners)
teamReports := reporting.CollateTeamReports(vulnsByTeam)

reportTime := time.Now().Format(time.RFC1123)
summaryHeader := fmt.Sprintf("%s Dependabot Report for %s", ghOrgName, reportTime)
summaryHeader := fmt.Sprintf("%s Vulnbot Report", ghOrgName)

wg := new(sync.WaitGroup)
for _, reporter := range reporters {
Expand All @@ -72,9 +72,10 @@ func Scan(cmd *cobra.Command, args []string) {
summaryHeader,
len(allRepos),
vulnSummary,
reportTime,
wg,
)
go reporter.SendTeamReports(teamReports, wg)
go reporter.SendTeamReports(teamReports, reportTime, wg)
}
wg.Wait()
log.Info().Msg("Done!")
Expand Down
2 changes: 2 additions & 0 deletions reporting/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (c *ConsoleReporter) SendSummaryReport(
header string,
numRepos int,
report VulnerabilityReport,
reportTime string,
wg *sync.WaitGroup,
) error {
defer wg.Done()
Expand Down Expand Up @@ -71,6 +72,7 @@ func (c *ConsoleReporter) SendSummaryReport(
// of this could be quite overwhelming.
func (c *ConsoleReporter) SendTeamReports(
teamReports map[string]map[string]VulnerabilityReport,
reportTime string,
wg *sync.WaitGroup,
) error {
defer wg.Done()
Expand Down
4 changes: 2 additions & 2 deletions reporting/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/underdog-tech/vulnbot/config"
)

func TestSendSummaryReport(t *testing.T) {
func TestSendConsoleSummaryReport(t *testing.T) {
origStdout := os.Stdout
reader, writer, _ := os.Pipe()
os.Stdout = writer
Expand Down Expand Up @@ -55,7 +55,7 @@ Affected repositories: 2

wg := new(sync.WaitGroup)
wg.Add(1)
reporter.SendSummaryReport("OrgName Dependabot Report for now", 13, report, wg)
reporter.SendSummaryReport("OrgName Dependabot Report for now", 13, report, "now", wg)
writer.Close()
written, _ := ioutil.ReadAll(reader)
os.Stdout = origStdout
Expand Down
2 changes: 2 additions & 0 deletions reporting/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ type Reporter interface {
header string,
numRepos int,
report VulnerabilityReport,
reportTime string,
wg *sync.WaitGroup,
) error
SendTeamReports(
teamReports map[string]map[string]VulnerabilityReport,
reportTime string,
wg *sync.WaitGroup,
) error
}
Loading

0 comments on commit 9193a07

Please sign in to comment.