Fix PR review comments and rename versions to latest-version

- Validate __typename in all list command pagination callbacks
- Serialize PostHogConsent=false as explicit false (not nil)
- Fix maxAgeSeconds factory to only include when value is an int
- Rename cookie-banner versions to latest-version subcommand

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-05-01 15:38:43 +04:00
parent 08aaab1393
commit d133d5ba1d
8 changed files with 23 additions and 16 deletions

View File

@@ -129,6 +129,9 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
if resp.Node == nil {
return nil, fmt.Errorf("cookie banner %s not found", flagBannerID)
}
if resp.Node.Typename != "CookieBanner" {
return nil, fmt.Errorf("expected CookieBanner node, got %s", resp.Node.Typename)
}
return &resp.Node.ConsentRecords, nil
},
)

View File

@@ -25,7 +25,7 @@ import (
"go.probo.inc/probo/pkg/cmd/cookie-banner/publish"
"go.probo.inc/probo/pkg/cmd/cookie-banner/translate"
"go.probo.inc/probo/pkg/cmd/cookie-banner/update"
"go.probo.inc/probo/pkg/cmd/cookie-banner/versions"
"go.probo.inc/probo/pkg/cmd/cookie-banner/latestversion"
"go.probo.inc/probo/pkg/cmd/cookie-banner/view"
)
@@ -44,7 +44,7 @@ func NewCmdCookieBanner(f *cmdutil.Factory) *cobra.Command {
cmd.AddCommand(deactivate.NewCmdDeactivate(f))
cmd.AddCommand(publish.NewCmdPublish(f))
cmd.AddCommand(translate.NewCmdTranslate(f))
cmd.AddCommand(versions.NewCmdVersions(f))
cmd.AddCommand(latestversion.NewCmdLatestVersion(f))
return cmd
}

View File

@@ -12,7 +12,7 @@
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package versions
package latestversion
import (
"encoding/json"
@@ -48,13 +48,12 @@ type versionInfo struct {
UpdatedAt string `json:"updatedAt"`
}
func NewCmdVersions(f *cmdutil.Factory) *cobra.Command {
func NewCmdLatestVersion(f *cmdutil.Factory) *cobra.Command {
var flagOutput *string
cmd := &cobra.Command{
Use: "versions <id>",
Short: "List versions for a cookie banner",
Aliases: []string{"ver"},
Use: "latest-version <id>",
Short: "Show the latest version of a cookie banner",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmdutil.ValidateOutputFlag(flagOutput); err != nil {

View File

@@ -119,6 +119,9 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
if resp.Node == nil {
return nil, fmt.Errorf("organization %s not found", flagOrg)
}
if resp.Node.Typename != "Organization" {
return nil, fmt.Errorf("expected Organization node, got %s", resp.Node.Typename)
}
return &resp.Node.CookieBanners, nil
},
)

View File

@@ -116,6 +116,9 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
if resp.Node == nil {
return nil, fmt.Errorf("cookie banner %s not found", flagBannerID)
}
if resp.Node.Typename != "CookieBanner" {
return nil, fmt.Errorf("expected CookieBanner node, got %s", resp.Node.Typename)
}
return &resp.Node.Categories, nil
},
)

View File

@@ -112,6 +112,9 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
if resp.Node == nil {
return nil, fmt.Errorf("cookie category %s not found", flagCategoryID)
}
if resp.Node.Typename != "CookieCategory" {
return nil, fmt.Errorf("expected CookieCategory node, got %s", resp.Node.Typename)
}
return &resp.Node.CookiePatterns, nil
},
)