Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion cmd/reqcheck/vcpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
package main

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"os"
Expand All @@ -26,6 +28,7 @@ func vcpkgCmd() *cli.Command {
settings := struct {
Output string
Overlays []string
Slack bool
}{}

return &cli.Command{
Expand All @@ -43,6 +46,11 @@ func vcpkgCmd() *cli.Command {
Usage: "overlay repositories",
Destination: &settings.Overlays,
},
&cli.BoolFlag{
Name: "slack",
Usage: "output a slack message",
Destination: &settings.Slack,
},
},
Action: func(c context.Context, cmd *cli.Command) error {
if cmd.NArg() > 1 {
Expand Down Expand Up @@ -191,11 +199,43 @@ func vcpkgCmd() *cli.Command {
Upgrade: upgrade,
}

err = t.Execute(output, td)
buffer := bytes.NewBuffer([]byte{})
var writeTemplateTo io.Writer
if settings.Slack {
writeTemplateTo = buffer
} else {
writeTemplateTo = output
}

err = t.Execute(writeTemplateTo, td)
if err != nil {
return fmt.Errorf("could not write results: %w", err)
}

if settings.Slack {
payload := map[string]interface{}{
"channel": "${{ env.SLACK_CHANNEL_ID }}",
"text": "Requirements check",
"blocks": []map[string]interface{}{{
"type": "section",
"text": map[string]interface{}{
"type": "mrkdwn",
"text": buffer.String(),
},
}},
}

encoded, err := json.Marshal(payload)
if err != nil {
return fmt.Errorf("could not create slack payload: %w", err)
}

_, err = output.Write(encoded)
if err != nil {
return fmt.Errorf("could not write results: %w", err)
}
}

return nil
},
}
Expand Down