Skip to content

Commit f85c282

Browse files
committed
support linear labels for workflows
1 parent 11f221e commit f85c282

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

internal/client/models.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ type Secret struct {
6161
}
6262

6363
type Workflow struct {
64-
Id string `json:"id"`
65-
Name string `json:"name"`
66-
Inputs []WorkflowInput `json:"inputs"`
67-
Steps []WorkflowStep `json:"steps"`
64+
Id string `json:"id"`
65+
Name string `json:"name"`
66+
TriggerLinearLabel TriggerLinearLabel `json:"trigger_linear_label"`
67+
Inputs []WorkflowInput `json:"inputs"`
68+
Steps []WorkflowStep `json:"steps"`
69+
}
70+
71+
type TriggerLinearLabel struct {
72+
Name string `json:"name"`
6873
}
6974

7075
type WorkflowInput struct {

internal/provider/devhub_workflow_resource.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ func WorkflowResource() resource.Resource {
3232

3333
// WorkflowResourceModel describes the resource data model.
3434
type workflowResourceModel struct {
35-
Id types.String `tfsdk:"id"`
36-
Name types.String `tfsdk:"name"`
37-
Inputs []workflowInputModel `tfsdk:"inputs"`
38-
Steps []workflowStepModel `tfsdk:"steps"`
35+
Id types.String `tfsdk:"id"`
36+
Name types.String `tfsdk:"name"`
37+
TriggerLinearLabelName types.String `tfsdk:"trigger_linear_label_name"`
38+
Inputs []workflowInputModel `tfsdk:"inputs"`
39+
Steps []workflowStepModel `tfsdk:"steps"`
3940
}
4041

4142
type workflowInputModel struct {
@@ -114,6 +115,10 @@ func (r *workflowResource) Schema(_ context.Context, _ resource.SchemaRequest, r
114115
MarkdownDescription: "The name of the workflow.",
115116
Required: true,
116117
},
118+
"trigger_linear_label_name": schema.StringAttribute{
119+
MarkdownDescription: "The name of the Linear label that should trigger the workflow.",
120+
Optional: true,
121+
},
117122
"inputs": schema.ListNestedAttribute{
118123
Optional: true,
119124
NestedObject: schema.NestedAttributeObject{
@@ -349,9 +354,10 @@ func (r *workflowResource) Create(ctx context.Context, req resource.CreateReques
349354
}
350355

351356
input := devhub.Workflow{
352-
Name: plan.Name.ValueString(),
353-
Inputs: inputs,
354-
Steps: steps,
357+
Name: plan.Name.ValueString(),
358+
TriggerLinearLabel: devhub.TriggerLinearLabel{Name: plan.TriggerLinearLabelName.ValueString()},
359+
Inputs: inputs,
360+
Steps: steps,
355361
}
356362

357363
createdWorkflow, err := r.client.CreateWorkflow(input)
@@ -403,6 +409,12 @@ func (r *workflowResource) Read(ctx context.Context, req resource.ReadRequest, r
403409
state.Id = types.StringValue(workflow.Id)
404410
state.Name = types.StringValue(workflow.Name)
405411

412+
if workflow.TriggerLinearLabel.Name == "" {
413+
state.TriggerLinearLabelName = types.StringNull()
414+
} else {
415+
state.TriggerLinearLabelName = types.StringValue(workflow.TriggerLinearLabel.Name)
416+
}
417+
406418
var stateInputs []workflowInputModel
407419
for _, input := range workflow.Inputs {
408420
stateInputs = append(stateInputs, workflowInputModel{
@@ -550,10 +562,11 @@ func (r *workflowResource) Update(ctx context.Context, req resource.UpdateReques
550562
}
551563

552564
workflow := devhub.Workflow{
553-
Id: plan.Id.ValueString(),
554-
Name: plan.Name.ValueString(),
555-
Inputs: inputs,
556-
Steps: steps,
565+
Id: plan.Id.ValueString(),
566+
Name: plan.Name.ValueString(),
567+
TriggerLinearLabel: devhub.TriggerLinearLabel{Name: plan.TriggerLinearLabelName.ValueString()},
568+
Inputs: inputs,
569+
Steps: steps,
557570
}
558571

559572
updatedWorkflow, err := r.client.UpdateWorkflow(plan.Id.ValueString(), workflow)

0 commit comments

Comments
 (0)