Skip to content

Commit d2b9684

Browse files
patrobinsonmcncl
andauthored
add ignore_default_branch_pull_requests to provider settings (#918)
* WIP: add ignore_default_branch_pull_requests setting to provider settings * update docs * retrieve state from API * chore(tests): add a test for ignore_default_branch field setting Signed-off-by: Ben McNicholl <[email protected]> --------- Signed-off-by: Ben McNicholl <[email protected]> Co-authored-by: Ben McNicholl <[email protected]>
1 parent 30e9017 commit d2b9684

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

buildkite/resource_pipeline.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type providerSettingsModel struct {
117117
PublishBlockedAsPending types.Bool `tfsdk:"publish_blocked_as_pending"`
118118
PublishCommitStatusPerStep types.Bool `tfsdk:"publish_commit_status_per_step"`
119119
SeparatePullRequestStatuses types.Bool `tfsdk:"separate_pull_request_statuses"`
120+
IgnoreDefaultBranchPullRequests types.Bool `tfsdk:"ignore_default_branch_pull_requests"`
120121
}
121122

122123
type pipelineResource struct {
@@ -725,6 +726,11 @@ func (*pipelineResource) Schema(ctx context.Context, req resource.SchemaRequest,
725726
MarkdownDescription: "Whether to create a separate status for pull request builds, allowing you to require a passing pull request" +
726727
" build in your [required status checks](https://help.github.com/en/articles/enabling-required-status-checks) in GitHub.",
727728
},
729+
"ignore_default_branch_pull_requests": schema.BoolAttribute{
730+
Computed: true,
731+
Optional: true,
732+
MarkdownDescription: "Whether to prevent caching pull requests with the source branch matching the default branch.",
733+
},
728734
},
729735
},
730736
},
@@ -1056,6 +1062,7 @@ type PipelineExtraSettings struct {
10561062
PublishBlockedAsPending *bool `json:"publish_blocked_as_pending,omitempty"`
10571063
PublishCommitStatusPerStep *bool `json:"publish_commit_status_per_step,omitempty"`
10581064
SeparatePullRequestStatuses *bool `json:"separate_pull_request_statuses,omitempty"`
1065+
IgnoreDefaultBranchPullRequests *bool `json:"ignore_default_branch_pull_requests"`
10591066
}
10601067

10611068
func getPipelineExtraInfo(ctx context.Context, client *Client, slug string, timeouts time.Duration) (*PipelineExtraInfo, error) {
@@ -1113,6 +1120,7 @@ func updatePipelineExtraInfo(ctx context.Context, slug string, settings *provide
11131120
PublishBlockedAsPending: settings.PublishBlockedAsPending.ValueBoolPointer(),
11141121
PublishCommitStatusPerStep: settings.PublishCommitStatusPerStep.ValueBoolPointer(),
11151122
SeparatePullRequestStatuses: settings.SeparatePullRequestStatuses.ValueBoolPointer(),
1123+
IgnoreDefaultBranchPullRequests: settings.IgnoreDefaultBranchPullRequests.ValueBoolPointer(),
11161124
},
11171125
}
11181126

@@ -1162,6 +1170,7 @@ func updatePipelineResourceExtraInfo(state *pipelineResourceModel, pipeline *Pip
11621170
PublishBlockedAsPending: types.BoolPointerValue(s.PublishBlockedAsPending),
11631171
PublishCommitStatusPerStep: types.BoolPointerValue(s.PublishCommitStatusPerStep),
11641172
SeparatePullRequestStatuses: types.BoolPointerValue(s.SeparatePullRequestStatuses),
1173+
IgnoreDefaultBranchPullRequests: types.BoolPointerValue(s.IgnoreDefaultBranchPullRequests),
11651174
}
11661175
}
11671176

@@ -1402,6 +1411,10 @@ func pipelineSchemaV0() schema.Schema {
14021411
Computed: true,
14031412
Optional: true,
14041413
},
1414+
"ignore_default_branch_pull_requests": schema.BoolAttribute{
1415+
Computed: true,
1416+
Optional: true,
1417+
},
14051418
},
14061419
},
14071420
},

buildkite/resource_pipeline_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
646646
publish_blocked_as_pending = true
647647
publish_commit_status_per_step = true
648648
separate_pull_request_statuses = true
649+
ignore_default_branch_pull_requests = true
649650
}
650651
}
651652
`, clusterName, pipelineName),
@@ -659,6 +660,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
659660
return nil
660661
},
661662
resource.TestCheckResourceAttrPair("buildkite_pipeline.pipeline", "cluster_id", "buildkite_cluster.cluster", "id"),
663+
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "provider_settings.ignore_default_branch_pull_requests", "true"),
662664
aggregateRemoteCheck(&pipeline),
663665
),
664666
},

docs/resources/pipeline.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ Optional:
177177
- `cancel_deleted_branch_builds` (Boolean) Automatically cancel running builds for a branch if the branch is deleted.
178178
- `filter_condition` (String) The condition to evaluate when deciding if a build should run. More details available in [the documentation](https://buildkite.com/docs/pipelines/conditionals#conditionals-in-pipelines).
179179
- `filter_enabled` (Boolean) Whether to filter builds to only run when the condition in `filter_condition` is true.
180+
- `ignore_default_branch_pull_requests` (Boolean) Whether to prevent caching pull requests with the source branch matching the default branch.
180181
- `prefix_pull_request_fork_branch_names` (Boolean) Prefix branch names for third-party fork builds to ensure they don't trigger branch conditions. For example, the main branch from some-user will become some-user:main.
181182
- `publish_blocked_as_pending` (Boolean) The status to use for blocked builds. Pending can be used with [required status checks](https://help.github.com/en/articles/enabling-required-status-checks) to prevent merging pull requests with blocked builds.
182183
- `publish_commit_status` (Boolean) Whether to update the status of commits in Bitbucket or GitHub.

0 commit comments

Comments
 (0)