issue creation and editing, edit markdown output
All checks were successful
Gosec Check / Gosec Check (push) Successful in 1m12s
All checks were successful
Gosec Check / Gosec Check (push) Successful in 1m12s
This commit is contained in:
parent
62f008e73c
commit
626bee5cac
1 changed files with 33 additions and 13 deletions
46
cmd/root.go
46
cmd/root.go
|
@ -128,14 +128,14 @@ var rootCmd = &cobra.Command{
|
||||||
|
|
||||||
var markdownOutput strings.Builder
|
var markdownOutput strings.Builder
|
||||||
markdownHandler := markdown.NewMarkdown(&markdownOutput)
|
markdownHandler := markdown.NewMarkdown(&markdownOutput)
|
||||||
markdownHandler.H1("GoSec Results:")
|
markdownHandler.H1("GoSec Report:")
|
||||||
|
markdownHandler.PlainText("This report automatically updates each time the action runs.\n")
|
||||||
markdownHandler.PlainText("<details>")
|
|
||||||
markdownHandler.PlainText("<summary>Results:</summary>\n")
|
|
||||||
|
|
||||||
if len(rows) == 0 {
|
if len(rows) == 0 {
|
||||||
markdownHandler.PlainText("**Nothing Found! 🥳**")
|
markdownHandler.PlainText("**Nothing Found! 🥳**")
|
||||||
} else {
|
} else {
|
||||||
|
markdownHandler.PlainText("<details>")
|
||||||
|
markdownHandler.PlainText("<summary>Results:</summary>\n")
|
||||||
if sevCountMap["high"] != 0 {
|
if sevCountMap["high"] != 0 {
|
||||||
markdownHandler.PlainText(fmt.Sprintf("🟥 **%d** high severity issues\n", sevCountMap["high"]))
|
markdownHandler.PlainText(fmt.Sprintf("🟥 **%d** high severity issues\n", sevCountMap["high"]))
|
||||||
}
|
}
|
||||||
|
@ -156,17 +156,18 @@ var rootCmd = &cobra.Command{
|
||||||
AutoWrapText: false,
|
AutoWrapText: false,
|
||||||
AutoFormatHeaders: false,
|
AutoFormatHeaders: false,
|
||||||
})
|
})
|
||||||
|
markdownHandler.PlainText("</details>")
|
||||||
}
|
}
|
||||||
|
|
||||||
markdownHandler.PlainText("</details>")
|
|
||||||
|
|
||||||
err = markdownHandler.Build()
|
err = markdownHandler.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markdownOutputStr := markdownOutput.String()
|
||||||
|
|
||||||
if isAction {
|
if isAction {
|
||||||
action.AddStepSummary(markdownOutput.String())
|
action.AddStepSummary(markdownOutputStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
actionCtx, err := action.Context()
|
actionCtx, err := action.Context()
|
||||||
|
@ -181,15 +182,34 @@ var rootCmd = &cobra.Command{
|
||||||
|
|
||||||
repoOwner, repoName := actionCtx.Repo()
|
repoOwner, repoName := actionCtx.Repo()
|
||||||
|
|
||||||
fmt.Println("hi")
|
issues, _, err := forgeClient.ListIssues(forgejo.ListIssueOption{
|
||||||
|
CreatedBy: "forgejo-actions",
|
||||||
if _, _, err := forgeClient.CreateIssue(repoOwner, repoName, forgejo.CreateIssueOption{
|
KeyWord: "GoSec Report",
|
||||||
Title: "testing",
|
Type: forgejo.IssueTypeIssue,
|
||||||
Body: markdownOutput.String(),
|
})
|
||||||
}); err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue