Skip to content

Commit 532679b

Browse files
authored
Sync terraform provider to new updatable merge queue fields (#10)
1 parent 4fb69c1 commit 532679b

7 files changed

Lines changed: 127 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- `trunk_merge_queue`: support for `extension_enabled`, `enqueueing_label`, `label_commands_enabled`, and `state_labels_enabled` attributes
1213
- `trunk_merge_queue` resource for managing Trunk merge queues
1314
- Full CRUD operations (create, read, update, delete)
1415
- Import support via `terraform import`

docs/resources/merge_queue.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ Manages a Trunk merge queue.
3131
- `concurrency` (Number) Number of concurrent test slots.
3232
- `create_prs_for_testing_branches` (Boolean) Create PRs for testing branches.
3333
- `direct_merge_mode` (String) Direct merge mode: "off" or "always".
34+
- `enqueueing_label` (String) The GitHub label whose application enqueues a PR onto the merge queue.
35+
- `extension_enabled` (Boolean) Whether the Trunk Merge Queue browser extension is enabled (shown) for this repository.
36+
- `label_commands_enabled` (Boolean) Whether label-based commands (e.g. enqueue/dequeue via labels) are enabled on the merge queue.
3437
- `merge_method` (String) Merge method: "merge_commit", "squash", or "rebase".
3538
- `mode` (String) Queue mode: "single" or "parallel".
3639
- `optimization_mode` (String) Optimization mode: "off" or "bisection_skip_redundant_tests".
3740
- `pending_failure_depth` (Number) Number of PRs below a failure to wait for before eviction.
3841
- `required_statuses` (List of String) Override required status checks. Set to null to revert to branch protection or trunk.yaml defaults; set to [] to explicitly require no statuses.
3942
- `state` (String) Queue state: "running", "paused", or "draining".
43+
- `state_labels_enabled` (Boolean) Whether the merge queue applies labels to PRs reflecting their merge queue state.
4044
- `status_check_enabled` (Boolean) Post GitHub status checks.
4145
- `testing_timeout_minutes` (Number) Maximum minutes to wait for tests.
4246

docs/trd/terraform-provider-trunk.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ All optional attributes are also `Computed: true` because the API always returns
107107
| `direct_merge_mode` | string | `"off"` | `"off"` or `"always"` |
108108
| `optimization_mode` | string | `"off"` | `"off"` or `"bisection_skip_redundant_tests"` |
109109
| `bisection_concurrency` | int | -- | Concurrent tests during bisection |
110+
| `extension_enabled` | bool | -- | Whether the browser extension is enabled |
111+
| `enqueueing_label` | string | -- | GitHub label whose application enqueues a PR |
112+
| `label_commands_enabled` | bool | -- | Whether label-based commands are enabled |
113+
| `state_labels_enabled` | bool | -- | Whether MQ applies state labels to PRs |
110114
| `required_statuses` | list | -- | Override required status checks |
111115

112116
**Note on `required_statuses`:** This field distinguishes three states:

internal/client/merge_queue_test.go

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func testQueue() Queue {
2828
DirectMergeMode: "off",
2929
OptimizationMode: "off",
3030
BisectionConcurrency: 1,
31+
ExtensionEnabled: false,
32+
EnqueueingLabel: "",
33+
LabelCommandsEnabled: false,
34+
StateLabelsEnabled: false,
3135
}
3236
}
3337

@@ -147,6 +151,10 @@ func TestGetQueue_AllFields(t *testing.T) {
147151
DirectMergeMode: "off",
148152
OptimizationMode: "bisection_skip_redundant_tests",
149153
BisectionConcurrency: 5,
154+
ExtensionEnabled: true,
155+
EnqueueingLabel: "merge-queue",
156+
LabelCommandsEnabled: true,
157+
StateLabelsEnabled: true,
150158
RequiredStatuses: &statuses,
151159
}
152160
_ = json.NewEncoder(w).Encode(q)
@@ -186,6 +194,18 @@ func TestGetQueue_AllFields(t *testing.T) {
186194
if queue.BisectionConcurrency != 5 {
187195
t.Errorf("BisectionConcurrency = %d, want 5", queue.BisectionConcurrency)
188196
}
197+
if !queue.ExtensionEnabled {
198+
t.Error("ExtensionEnabled = false, want true")
199+
}
200+
if queue.EnqueueingLabel != "merge-queue" {
201+
t.Errorf("EnqueueingLabel = %q, want %q", queue.EnqueueingLabel, "merge-queue")
202+
}
203+
if !queue.LabelCommandsEnabled {
204+
t.Error("LabelCommandsEnabled = false, want true")
205+
}
206+
if !queue.StateLabelsEnabled {
207+
t.Error("StateLabelsEnabled = false, want true")
208+
}
189209
if queue.RequiredStatuses == nil || len(*queue.RequiredStatuses) != 2 {
190210
t.Fatalf("RequiredStatuses = %v, want 2 elements", queue.RequiredStatuses)
191211
}
@@ -254,6 +274,7 @@ func TestUpdateQueue_OmitsNilFields(t *testing.T) {
254274
for _, field := range []string{
255275
"mode", "concurrency", "state", "mergeMethod", "batch",
256276
"deleteRequiredStatuses", "testingTimeoutMinutes", "requiredStatuses",
277+
"extensionEnabled", "enqueueingLabel", "labelCommandsEnabled", "stateLabelsEnabled",
257278
} {
258279
if _, present := rawBody[field]; present {
259280
t.Errorf("field %q should be absent when nil, but was present in request body", field)
@@ -274,14 +295,22 @@ func TestUpdateQueue_IncludesNonNilFields(t *testing.T) {
274295
concurrency := 3
275296
mergeMethod := "squash"
276297
batch := true
298+
extensionEnabled := true
299+
enqueueingLabel := "merge-queue"
300+
labelCommandsEnabled := true
301+
stateLabelsEnabled := true
277302
c := newTestClient("key", server.URL)
278303
if _, err := c.UpdateQueue(context.Background(), UpdateQueueRequest{
279-
Repo: Repo{Host: "github.com", Owner: "my-org", Name: "my-repo"},
280-
TargetBranch: "main",
281-
Mode: &mode,
282-
Concurrency: &concurrency,
283-
MergeMethod: &mergeMethod,
284-
Batch: &batch,
304+
Repo: Repo{Host: "github.com", Owner: "my-org", Name: "my-repo"},
305+
TargetBranch: "main",
306+
Mode: &mode,
307+
Concurrency: &concurrency,
308+
MergeMethod: &mergeMethod,
309+
Batch: &batch,
310+
ExtensionEnabled: &extensionEnabled,
311+
EnqueueingLabel: &enqueueingLabel,
312+
LabelCommandsEnabled: &labelCommandsEnabled,
313+
StateLabelsEnabled: &stateLabelsEnabled,
285314
}); err != nil {
286315
t.Fatalf("UpdateQueue error: %v", err)
287316
}
@@ -297,6 +326,18 @@ func TestUpdateQueue_IncludesNonNilFields(t *testing.T) {
297326
if rawBody["batch"] != true {
298327
t.Errorf("batch = %v, want true", rawBody["batch"])
299328
}
329+
if rawBody["extensionEnabled"] != true {
330+
t.Errorf("extensionEnabled = %v, want true", rawBody["extensionEnabled"])
331+
}
332+
if rawBody["enqueueingLabel"] != "merge-queue" {
333+
t.Errorf("enqueueingLabel = %v, want %q", rawBody["enqueueingLabel"], "merge-queue")
334+
}
335+
if rawBody["labelCommandsEnabled"] != true {
336+
t.Errorf("labelCommandsEnabled = %v, want true", rawBody["labelCommandsEnabled"])
337+
}
338+
if rawBody["stateLabelsEnabled"] != true {
339+
t.Errorf("stateLabelsEnabled = %v, want true", rawBody["stateLabelsEnabled"])
340+
}
300341
}
301342

302343
func TestUpdateQueue_ReturnsQueue(t *testing.T) {

internal/client/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ type Queue struct {
3333
DirectMergeMode string `json:"directMergeMode"`
3434
OptimizationMode string `json:"optimizationMode"`
3535
BisectionConcurrency int `json:"bisectionConcurrency"`
36+
ExtensionEnabled bool `json:"extensionEnabled"`
37+
EnqueueingLabel string `json:"enqueueingLabel"`
38+
LabelCommandsEnabled bool `json:"labelCommandsEnabled"`
39+
StateLabelsEnabled bool `json:"stateLabelsEnabled"`
3640

3741
// RequiredStatuses is null when no manual override is set (uses branch protection / trunk.yaml defaults).
3842
RequiredStatuses *[]string `json:"requiredStatuses"`
@@ -88,6 +92,10 @@ type UpdateQueueRequest struct {
8892
DirectMergeMode *string `json:"directMergeMode,omitempty"`
8993
OptimizationMode *string `json:"optimizationMode,omitempty"`
9094
BisectionConcurrency *int `json:"bisectionConcurrency,omitempty"`
95+
ExtensionEnabled *bool `json:"extensionEnabled,omitempty"`
96+
EnqueueingLabel *string `json:"enqueueingLabel,omitempty"`
97+
LabelCommandsEnabled *bool `json:"labelCommandsEnabled,omitempty"`
98+
StateLabelsEnabled *bool `json:"stateLabelsEnabled,omitempty"`
9199
RequiredStatuses *[]string `json:"requiredStatuses,omitempty"`
92100

93101
// DeleteRequiredStatuses reverts required statuses to branch protection / trunk.yaml defaults

internal/provider/merge_queue_resource.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,41 @@ func (r *mergeQueueResource) Schema(_ context.Context, _ resource.SchemaRequest,
254254
int64planmodifier.UseStateForUnknown(),
255255
},
256256
},
257+
"extension_enabled": schema.BoolAttribute{
258+
Description: "Whether the Trunk Merge Queue browser extension is enabled (shown) for this repository.",
259+
Optional: true,
260+
Computed: true,
261+
PlanModifiers: []planmodifier.Bool{
262+
boolplanmodifier.UseStateForUnknown(),
263+
},
264+
},
265+
"enqueueing_label": schema.StringAttribute{
266+
Description: "The GitHub label whose application enqueues a PR onto the merge queue.",
267+
Optional: true,
268+
Computed: true,
269+
Validators: []validator.String{
270+
stringvalidator.LengthAtLeast(1),
271+
},
272+
PlanModifiers: []planmodifier.String{
273+
stringplanmodifier.UseStateForUnknown(),
274+
},
275+
},
276+
"label_commands_enabled": schema.BoolAttribute{
277+
Description: "Whether label-based commands (e.g. enqueue/dequeue via labels) are enabled on the merge queue.",
278+
Optional: true,
279+
Computed: true,
280+
PlanModifiers: []planmodifier.Bool{
281+
boolplanmodifier.UseStateForUnknown(),
282+
},
283+
},
284+
"state_labels_enabled": schema.BoolAttribute{
285+
Description: "Whether the merge queue applies labels to PRs reflecting their merge queue state.",
286+
Optional: true,
287+
Computed: true,
288+
PlanModifiers: []planmodifier.Bool{
289+
boolplanmodifier.UseStateForUnknown(),
290+
},
291+
},
257292
"required_statuses": schema.ListAttribute{
258293
Description: "Override required status checks. Set to null to revert to branch protection or trunk.yaml defaults; set to [] to explicitly require no statuses.",
259294
Optional: true,
@@ -462,6 +497,10 @@ func (r *mergeQueueResource) ImportState(ctx context.Context, req resource.Impor
462497
DirectMergeMode: types.StringNull(),
463498
OptimizationMode: types.StringNull(),
464499
BisectionConcurrency: types.Int64Null(),
500+
ExtensionEnabled: types.BoolNull(),
501+
EnqueueingLabel: types.StringNull(),
502+
LabelCommandsEnabled: types.BoolNull(),
503+
StateLabelsEnabled: types.BoolNull(),
465504
RequiredStatuses: types.ListNull(types.StringType),
466505
}
467506

internal/provider/merge_queue_resource_model.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ type mergeQueueResourceModel struct {
3636
DirectMergeMode types.String `tfsdk:"direct_merge_mode"`
3737
OptimizationMode types.String `tfsdk:"optimization_mode"`
3838
BisectionConcurrency types.Int64 `tfsdk:"bisection_concurrency"`
39+
ExtensionEnabled types.Bool `tfsdk:"extension_enabled"`
40+
EnqueueingLabel types.String `tfsdk:"enqueueing_label"`
41+
LabelCommandsEnabled types.Bool `tfsdk:"label_commands_enabled"`
42+
StateLabelsEnabled types.Bool `tfsdk:"state_labels_enabled"`
3943
RequiredStatuses types.List `tfsdk:"required_statuses"`
4044
}
4145

@@ -135,6 +139,22 @@ func (m *mergeQueueResourceModel) toUpdateRequest(config *mergeQueueResourceMode
135139
v := int(m.BisectionConcurrency.ValueInt64())
136140
req.BisectionConcurrency = &v
137141
}
142+
if !config.ExtensionEnabled.IsNull() {
143+
v := m.ExtensionEnabled.ValueBool()
144+
req.ExtensionEnabled = &v
145+
}
146+
if !config.EnqueueingLabel.IsNull() {
147+
v := m.EnqueueingLabel.ValueString()
148+
req.EnqueueingLabel = &v
149+
}
150+
if !config.LabelCommandsEnabled.IsNull() {
151+
v := m.LabelCommandsEnabled.ValueBool()
152+
req.LabelCommandsEnabled = &v
153+
}
154+
if !config.StateLabelsEnabled.IsNull() {
155+
v := m.StateLabelsEnabled.ValueBool()
156+
req.StateLabelsEnabled = &v
157+
}
138158

139159
// required_statuses: null in config means revert to branch protection / trunk.yaml defaults.
140160
if config.RequiredStatuses.IsNull() {
@@ -184,6 +204,10 @@ func (m *mergeQueueResourceModel) fromQueue(q *client.Queue) {
184204
m.DirectMergeMode = types.StringValue(q.DirectMergeMode)
185205
m.OptimizationMode = types.StringValue(q.OptimizationMode)
186206
m.BisectionConcurrency = types.Int64Value(int64(q.BisectionConcurrency))
207+
m.ExtensionEnabled = types.BoolValue(q.ExtensionEnabled)
208+
m.EnqueueingLabel = types.StringValue(q.EnqueueingLabel)
209+
m.LabelCommandsEnabled = types.BoolValue(q.LabelCommandsEnabled)
210+
m.StateLabelsEnabled = types.BoolValue(q.StateLabelsEnabled)
187211

188212
if q.RequiredStatuses != nil {
189213
elems := make([]attr.Value, len(*q.RequiredStatuses))

0 commit comments

Comments
 (0)