()
| 114 | } |
| 115 | |
| 116 | func webhooksCreateCmd() *cobra.Command { |
| 117 | var ( |
| 118 | eventsFlag string |
| 119 | secretFlag string |
| 120 | ) |
| 121 | |
| 122 | cmd := &cobra.Command{ |
| 123 | Use: "create <url>", |
| 124 | Short: "Register a new webhook", |
| 125 | Long: `Register a new webhook URL to receive event notifications. |
| 126 | |
| 127 | Examples: |
| 128 | pad webhook create https://httpbin.org/post |
| 129 | pad webhook create https://slack.com/webhook/... --events "item.created,item.updated" |
| 130 | pad webhook create https://example.com/hook --secret "mysecret"`, |
| 131 | Args: cobra.ExactArgs(1), |
| 132 | RunE: func(cmd *cobra.Command, args []string) error { |
| 133 | client, _ := getClient() |
| 134 | ws := getWorkspace() |
| 135 | |
| 136 | input := models.WebhookCreate{ |
| 137 | URL: args[0], |
| 138 | Events: eventsFlag, |
| 139 | Secret: secretFlag, |
| 140 | } |
| 141 | |
| 142 | hook, err := client.CreateWebhook(ws, input) |
| 143 | if err != nil { |
| 144 | // TASK-788: emit structured marker so MCP stdio classifier |
| 145 | // can surface ErrPlanLimitExceeded instead of ErrServerError. |
| 146 | if apiErr, ok := err.(*cli.APIError); ok { |
| 147 | if apiErr.AsPlanLimit() != nil { |
| 148 | cli.WritePlanLimitError(os.Stderr, apiErr) |
| 149 | return fmt.Errorf("webhook creation blocked: plan limit reached") |
| 150 | } |
| 151 | } |
| 152 | return err |
| 153 | } |
| 154 | |
| 155 | if formatFlag == "json" { |
| 156 | return cli.PrintJSON(hook) |
| 157 | } |
| 158 | |
| 159 | green := color.New(color.FgGreen) |
| 160 | fmt.Printf("%s Webhook created\n", green.Sprint("✓")) |
| 161 | fmt.Printf(" ID: %s\n", hook.ID) |
| 162 | fmt.Printf(" URL: %s\n", hook.URL) |
| 163 | events := hook.Events |
| 164 | if events == "" { |
| 165 | events = "*" |
| 166 | } |
| 167 | fmt.Printf(" Events: %s\n", events) |
| 168 | return nil |
| 169 | }, |
| 170 | } |
| 171 | |
| 172 | cmd.Flags().StringVar(&eventsFlag, "events", "", "comma-separated event types (default: all)") |
| 173 | cmd.Flags().StringVar(&secretFlag, "secret", "", "shared secret for HMAC signature verification") |
no test coverage detected