issue creation and editing, edit markdown output
All checks were successful
Gosec Check / Gosec Check (push) Successful in 1m12s

This commit is contained in:
Shane C 2024-09-06 16:02:10 -04:00
parent 62f008e73c
commit 626bee5cac
Signed by: shanec
GPG key ID: E46B5FEA35B22FF9

View file

@ -128,14 +128,14 @@ var rootCmd = &cobra.Command{
var markdownOutput strings.Builder
markdownHandler := markdown.NewMarkdown(&markdownOutput)
markdownHandler.H1("GoSec Results:")
markdownHandler.PlainText("<details>")
markdownHandler.PlainText("<summary>Results:</summary>\n")
markdownHandler.H1("GoSec Report:")
markdownHandler.PlainText("This report automatically updates each time the action runs.\n")
if len(rows) == 0 {
markdownHandler.PlainText("**Nothing Found! 🥳**")
} else {
markdownHandler.PlainText("<details>")
markdownHandler.PlainText("<summary>Results:</summary>\n")
if sevCountMap["high"] != 0 {
markdownHandler.PlainText(fmt.Sprintf("🟥 **%d** high severity issues\n", sevCountMap["high"]))
}
@ -156,17 +156,18 @@ var rootCmd = &cobra.Command{
AutoWrapText: false,
AutoFormatHeaders: false,
})
markdownHandler.PlainText("</details>")
}
markdownHandler.PlainText("</details>")
err = markdownHandler.Build()
if err != nil {
log.Fatalln(err)
}
markdownOutputStr := markdownOutput.String()
if isAction {
action.AddStepSummary(markdownOutput.String())
action.AddStepSummary(markdownOutputStr)
}
actionCtx, err := action.Context()
@ -181,15 +182,34 @@ var rootCmd = &cobra.Command{
repoOwner, repoName := actionCtx.Repo()
fmt.Println("hi")
if _, _, err := forgeClient.CreateIssue(repoOwner, repoName, forgejo.CreateIssueOption{
Title: "testing",
Body: markdownOutput.String(),
}); err != nil {
issues, _, err := forgeClient.ListIssues(forgejo.ListIssueOption{
CreatedBy: "forgejo-actions",
KeyWord: "GoSec Report",
Type: forgejo.IssueTypeIssue,
})
if err != nil {
log.Fatalln(err)
}
if len(issues) == 0 {
if _, _, err := forgeClient.CreateIssue(repoOwner, repoName, forgejo.CreateIssueOption{
Title: "GoSec Report",
Body: markdownOutputStr,
}); err != nil {
log.Fatalln(err)
}
} else {
for _, issue := range issues {
if issue.Title == "GoSec Report" && strings.Contains(issue.Body, "GoSec Report:") {
if _, _, err := forgeClient.EditIssue(repoOwner, repoName, issue.ID, forgejo.EditIssueOption{
Body: &markdownOutputStr,
}); err != nil {
log.Fatalln(err)
}
}
}
}
},
}