Skip to content

Commit 62670a2

Browse files
authored
Merge pull request #163 from buildkite/fix_make_webhook_required
fix: when creating a pipeline we require the create_webhook to be set
2 parents e1ead95 + 4def5f0 commit 62670a2

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

pkg/buildkite/pipelines.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ type CreatePipelineArgs struct {
294294
SkipQueuedBranchBuilds bool `json:"skip_queued_branch_builds"`
295295
CancelRunningBranchBuilds bool `json:"cancel_running_branch_builds"`
296296
Tags []string `json:"tags"`
297-
CreateWebhook *bool `json:"create_webhook"`
297+
CreateWebhook bool `json:"create_webhook"`
298298
}
299299

300300
func CreatePipeline(client PipelinesClient) (tool mcp.Tool, handler mcp.TypedToolHandlerFunc[CreatePipelineArgs], scopes []string) {
@@ -317,6 +317,11 @@ func CreatePipeline(client PipelinesClient) (tool mcp.Tool, handler mcp.TypedToo
317317
mcp.Required(),
318318
mcp.Description("The pipeline configuration in YAML format. Contains the build steps and pipeline settings. If not provided, a basic configuration will be used"),
319319
),
320+
mcp.WithBoolean("create_webhook",
321+
mcp.Required(),
322+
mcp.Description("Create a GitHub webhook to trigger builds in response to pull-request and push events"),
323+
mcp.DefaultBool(true),
324+
),
320325
mcp.WithString("description"),
321326
mcp.WithString("default_branch",
322327
mcp.Description("The default branch for builds and metrics filtering"),
@@ -327,10 +332,6 @@ func CreatePipeline(client PipelinesClient) (tool mcp.Tool, handler mcp.TypedToo
327332
mcp.WithBoolean("cancel_running_branch_builds",
328333
mcp.Description("Cancel running builds when new builds are created on the same branch"),
329334
),
330-
mcp.WithBoolean("create_webhook",
331-
mcp.Description("Create a GitHub webhook to trigger builds in response to pull-request and push events"),
332-
mcp.DefaultBool(true),
333-
),
334335
mcp.WithArray("tags",
335336
mcp.Description("Tags to apply to the pipeline. These can be used for filtering and organization"),
336337
mcp.Items(map[string]any{
@@ -371,6 +372,7 @@ func CreatePipeline(client PipelinesClient) (tool mcp.Tool, handler mcp.TypedToo
371372
span.SetAttributes(
372373
attribute.String("name", args.Name),
373374
attribute.String("repository_url", args.RepositoryURL),
375+
attribute.Bool("create_webhook", args.CreateWebhook),
374376
)
375377

376378
create := buildkite.CreatePipeline{
@@ -400,13 +402,7 @@ func CreatePipeline(client PipelinesClient) (tool mcp.Tool, handler mcp.TypedToo
400402
return mcp.NewToolResultError(err.Error()), nil
401403
}
402404

403-
// create webhooks by default to align with the behavior in the dashboard
404-
createWebhook := true
405-
if args.CreateWebhook != nil {
406-
createWebhook = *args.CreateWebhook
407-
}
408-
409-
if createWebhook {
405+
if args.CreateWebhook {
410406
_, err := client.AddWebhook(ctx, args.OrgSlug, pipeline.Slug)
411407
result := CreatePipelineResult{
412408
Pipeline: pipeline,

pkg/buildkite/pipelines_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ steps:
197197
Description: "A test pipeline",
198198
Configuration: testPipelineDefinition,
199199
Tags: []string{"tag1", "tag2"},
200-
CreateWebhook: nil,
200+
CreateWebhook: true, // should create webhook by default
201201
}
202202

203203
result, err := handler(ctx, request, args)
204204
assert.NoError(err)
205-
assert.True(webhookCalled, "AddWebhook should have been called when CreateWebhook is nil")
205+
assert.True(webhookCalled, "AddWebhook should have been called when CreateWebhook is true")
206206

207207
textContent := getTextResult(t, result)
208208
assert.Contains(textContent.Text, `"webhook":{"created":true,"note":"Pipeline and webhook created successfully."}`)
@@ -225,7 +225,6 @@ steps:
225225

226226
ctx := context.Background()
227227
webhookCalled := false
228-
createWebhook := true
229228
client := &MockPipelinesClient{
230229
CreateFunc: func(ctx context.Context, org string, p buildkite.CreatePipeline) (buildkite.Pipeline, *buildkite.Response, error) {
231230

@@ -278,7 +277,7 @@ steps:
278277
Description: "A test pipeline",
279278
Configuration: testPipelineDefinition,
280279
Tags: []string{"tag1", "tag2"},
281-
CreateWebhook: &createWebhook,
280+
CreateWebhook: true,
282281
}
283282

284283
result, err := handler(ctx, request, args)
@@ -306,7 +305,6 @@ steps:
306305

307306
ctx := context.Background()
308307
webhookCalled := false
309-
createWebhook := true
310308
client := &MockPipelinesClient{
311309
CreateFunc: func(ctx context.Context, org string, p buildkite.CreatePipeline) (buildkite.Pipeline, *buildkite.Response, error) {
312310

@@ -350,7 +348,7 @@ steps:
350348
Description: "A test pipeline",
351349
Configuration: testPipelineDefinition,
352350
Tags: []string{"tag1", "tag2"},
353-
CreateWebhook: &createWebhook,
351+
CreateWebhook: true,
354352
}
355353

356354
result, err := handler(ctx, request, args)

0 commit comments

Comments
 (0)