Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ build-in-docker:
-v "./bin:/app/bin" \
-v "${HOME}/.netrc:/root/.netrc" \
-w /app \
golang:1.21.1 \
golang:1.25 \
sh -c "CGO_ENABLED=0 GOOS=linux make build"

.PHONY: docker
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ pbuf drift module [module_name] [--tag tag_name]

Replace `[module_name]` with the name of the module. Use the optional `--tag` flag to filter by tag name.

##### Get Module Dependency Drift Status

```bash
pbuf drift dependencies [module_name] [--tag tag_name]
```

Replace `[module_name]` with the name of the module. Use the optional `--tag` flag to evaluate dependency drift for a specific module tag.

---

### Configuration (`pbuf.yaml`)
Expand Down
78 changes: 78 additions & 0 deletions cmd/drift.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cmd

import (
"fmt"
"io"
"text/tabwriter"

v1 "github.com/pbufio/pbuf-cli/gen/pbuf-registry/v1"
"github.com/pbufio/pbuf-cli/internal/model"
"github.com/spf13/cobra"
Expand All @@ -18,6 +22,7 @@ func NewDriftCmd(_ *model.Config, client v1.DriftServiceClient) *cobra.Command {

driftCmd.AddCommand(newListDriftEventsCmd(client))
driftCmd.AddCommand(newGetModuleDriftEventsCmd(client))
driftCmd.AddCommand(newGetModuleDependencyDriftStatusCmd(client))

return driftCmd
}
Expand Down Expand Up @@ -81,3 +86,76 @@ func newGetModuleDriftEventsCmd(client v1.DriftServiceClient) *cobra.Command {
getCmd.Flags().String("tag", "", "filter drift events by tag name")
return getCmd
}

func newGetModuleDependencyDriftStatusCmd(client v1.DriftServiceClient) *cobra.Command {
getCmd := &cobra.Command{
Use: "dependencies [module_name]",
Short: "Get dependency drift status",
Long: "Dependencies is a command to get dependency drift status for a specific module",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
moduleName := args[0]
tagName, err := cmd.Flags().GetString("tag")
if err != nil {
return err
}

req := &v1.GetModuleDependencyDriftStatusRequest{
ModuleName: moduleName,
}
if tagName != "" {
req.TagName = &tagName
}

resp, err := client.GetModuleDependencyDriftStatus(cmd.Context(), req)
if err != nil {
return err
}

return printDependencyDriftStatuses(cmd.OutOrStdout(), moduleName, tagName, resp.GetStatuses())
},
}

getCmd.Flags().String("tag", "", "module tag to evaluate (latest stable when omitted)")
return getCmd
}

func printDependencyDriftStatuses(w io.Writer, moduleName, tagName string, statuses []*v1.DependencyDriftStatus) error {
if _, err := fmt.Fprintf(w, "Dependency drift status for %s", moduleName); err != nil {
return err
}
if tagName != "" {
if _, err := fmt.Fprintf(w, " (tag: %s)", tagName); err != nil {
return err
}
}
if _, err := fmt.Fprintln(w); err != nil {
return err
}

if len(statuses) == 0 {
_, err := fmt.Fprintln(w, "No dependency drift detected.")
return err
}

tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
if _, err := fmt.Fprintln(tw, "DEPENDENCY\tCURRENT\tTARGET\tSEVERITY\tRECOMMENDATION"); err != nil {
return err
}

for _, status := range statuses {
if _, err := fmt.Fprintf(
tw,
"%s\t%s\t%s\t%s\t%s\n",
status.GetDependencyName(),
status.GetCurrentTag(),
status.GetTargetTag(),
status.GetSeverity().String(),
status.GetRecommendation().String(),
); err != nil {
return err
}
}

return tw.Flush()
}
Loading