Commit ba885de89c

ba885de89c55a6ed66ae41c37d4350cf6e8876da

parent: 8dcfa45a8a

Verified · cmc

cmc <hello@cleberg.net> · 2026-09-29 00:11 UTC

cli: webhook add forwards stdin for --secret -

Ref #284

Layout: unified · split

cmd/gitbay/main.go +2 −2
@@ -357,7 +357,7 @@ func isEmptyReader(r io.Reader) bool {
357// usesStdin reports whether the arguments request stdin content. 357// usesStdin reports whether the arguments request stdin content.
358func usesStdin(args []string) bool { 358func usesStdin(args []string) bool {
359 for i, a := range args { 359 for i, a := range args {
360 if (a == "--file" || a == "--key") && i+1 < len(args) && args[i+1] == "-" { 360 if (a == "--file" || a == "--key" || a == "--secret") && i+1 < len(args) && args[i+1] == "-" {
361 return true 361 return true
362 } 362 }
363 if a == "--token-stdin" { 363 if a == "--token-stdin" {
@@ -750,7 +750,7 @@ func webCmd() *cobra.Command {
750 750
751func webhookCmd() *cobra.Command { 751func webhookCmd() *cobra.Command {
752 return group("webhook", "outbound event delivery", 752 return group("webhook", "outbound event delivery",
753 pass("add", passOpts{server: []string{"webhook", "add"}, needsRepo: true}), 753 pass("add", passOpts{server: []string{"webhook", "add"}, needsRepo: true, stdinOK: true, stdinWhat: "the webhook secret", stdinSecret: true}),
754 pass("list", passOpts{server: []string{"webhook", "list"}, needsRepo: true}), 754 pass("list", passOpts{server: []string{"webhook", "list"}, needsRepo: true}),
755 pass("remove", passOpts{server: []string{"webhook", "remove"}, needsRepo: true}), 755 pass("remove", passOpts{server: []string{"webhook", "remove"}, needsRepo: true}),
756 pass("deliveries", passOpts{server: []string{"webhook", "deliveries"}, needsRepo: true}), 756 pass("deliveries", passOpts{server: []string{"webhook", "deliveries"}, needsRepo: true}),
cmd/gitbay/stdinpayload_test.go +11
@@ -114,3 +114,14 @@ func swapTerminal(f func(*os.File) bool) func() {
114 isTerminal = f 114 isTerminal = f
115 return func() { isTerminal = prev } 115 return func() { isTerminal = prev }
116} 116}
117
118// webhook add --secret - reads the secret on the server, so the CLI must
119// forward stdin for it the way it does for --file - (#284).
120func TestUsesStdinForSecretDash(t *testing.T) {
121 if !usesStdin([]string{"alice/app", "https://ci.example/hook", "--secret", "-"}) {
122 t.Error("--secret - does not forward stdin")
123 }
124 if usesStdin([]string{"alice/app", "https://ci.example/hook", "--events", "push"}) {
125 t.Error("forwarded stdin with no flag asking for it")
126 }
127}