mirror of
https://github.com/drone/drone-gitleaks.git
synced 2026-06-14 05:12:52 +08:00
(feat) add issue count to adaptive card
This commit is contained in:
+2
-2
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/drone/drone-go/drone"
|
||||
)
|
||||
|
||||
func (args Args) writeCard(dat []match) error {
|
||||
result, _ := json.Marshal(CardIssues{Issues: dat})
|
||||
func (args Args) writeCard(data Card) error {
|
||||
result, _ := json.Marshal(data)
|
||||
card := drone.CardInput{
|
||||
Schema: "https://drone.github.io/drone-gitleaks/card.json",
|
||||
Data: result,
|
||||
|
||||
+13
-12
@@ -26,8 +26,9 @@ type Args struct {
|
||||
CardFilePath string `envconfig:"DRONE_CARD_PATH"`
|
||||
}
|
||||
|
||||
type CardIssues struct {
|
||||
Issues []match
|
||||
type Card struct {
|
||||
NumIssues int `json:"NumIssues"`
|
||||
Issues []match `json:"Issues"`
|
||||
}
|
||||
|
||||
// Exec executes the plugin.
|
||||
@@ -53,29 +54,29 @@ func Exec(ctx context.Context, args Args) error {
|
||||
// read the generated report and unmarshal
|
||||
dat := []match{}
|
||||
out, ferr := ioutil.ReadFile(file.Name())
|
||||
if len(out) == 0 {
|
||||
return nil
|
||||
}
|
||||
if ferr != nil {
|
||||
logrus.WithError(ferr).Warnln("Cannot read report")
|
||||
}
|
||||
if jsonerr := json.Unmarshal(out, &dat); jsonerr != nil {
|
||||
logrus.WithError(jsonerr).Warnln("Cannot unmarshal report")
|
||||
logrus.WithError(jsonerr).Warnln("Cannot unmarshal report, ignore if 'No leaks found'")
|
||||
}
|
||||
|
||||
reacted := []match{}
|
||||
issues := []match{}
|
||||
// loop through and print each violation
|
||||
for _, match := range dat {
|
||||
match.Line = "*****"
|
||||
match.Offender = "*****"
|
||||
logrus.Errorf("%s violation in %q at line %d\n", match.Rule, match.File, match.Linenumber)
|
||||
reacted = append(reacted, match)
|
||||
issues = append(issues, match)
|
||||
}
|
||||
|
||||
if len(dat) != 0 {
|
||||
if err := args.writeCard(reacted); err != nil {
|
||||
fmt.Printf("Could not create adaptive card. %s\n", err)
|
||||
}
|
||||
cardData := Card{
|
||||
NumIssues: len(issues),
|
||||
Issues: issues,
|
||||
}
|
||||
|
||||
if err := args.writeCard(cardData); err != nil {
|
||||
fmt.Printf("Could not create adaptive card. %s\n", err)
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user