Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add enable notifications on pipeline level (credit @nickborysov) #136

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions codefresh/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,11 @@ Pipeline concurrency policy: Builds on 'Pending Approval' state should be:
Type: schema.TypeBool,
Optional: true,
},
"enable_notifications": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
Expand Down Expand Up @@ -762,6 +767,8 @@ func flattenSpec(spec cfclient.Spec) []interface{} {
options["keep_pvcs_for_pending_approval"] = valueOption
case keyOption == "pendingApprovalConcurrencyApplied":
options["pending_approval_concurrency_applied"] = valueOption
case keyOption == "enableNotifications":
options["enable_notifications"] = valueOption
}
}
resOptions = append(resOptions, options)
Expand Down Expand Up @@ -1074,6 +1081,9 @@ func mapResourceToPipeline(d *schema.ResourceData) (*cfclient.Pipeline, error) {
if pendingApprovalConcurrencyApplied, ok := d.GetOkExists("spec.0.options.0.pending_approval_concurrency_applied"); ok {
pipelineSpecOption["pendingApprovalConcurrencyApplied"] = pendingApprovalConcurrencyApplied.(bool)
}
if enableNotifications, ok := d.GetOkExists("spec.0.options.0.enable_notifications"); ok {
pipelineSpecOption["enableNotifications"] = enableNotifications.(bool)
}
pipeline.Spec.Options = pipelineSpecOption
} else {
pipeline.Spec.Options = nil
Expand Down
8 changes: 5 additions & 3 deletions codefresh/resource_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,14 @@ func TestAccCodefreshPipelineOptions(t *testing.T) {
CheckDestroy: testAccCheckCodefreshPipelineDestroy,
Steps: []resource.TestStep{
{
Config: testAccCodefreshPipelineOptions(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", true, false),
Config: testAccCodefreshPipelineOptions(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", true, false, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckCodefreshPipelineExists(resourceName, &pipeline),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "spec.0.options.*", map[string]string{
"keep_pvcs_for_pending_approval": "true",
"pending_approval_concurrency_applied": "false",
"enable_notifications": "false",
}),
),
},
Expand Down Expand Up @@ -1278,7 +1279,7 @@ func TestAccCodefreshPipeline_Contexts(t *testing.T) {
})
}

func testAccCodefreshPipelineOptions(rName, repo, path, revision, context string, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied bool) string {
func testAccCodefreshPipelineOptions(rName, repo, path, revision, context string, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied bool, enableNotifications bool) string {
return fmt.Sprintf(`
resource "codefresh_pipeline" "test" {

Expand All @@ -1300,10 +1301,11 @@ resource "codefresh_pipeline" "test" {
options {
keep_pvcs_for_pending_approval = %t
pending_approval_concurrency_applied = %t
enable_notifications = %t
}
}
}
`, rName, repo, path, revision, context, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied)
`, rName, repo, path, revision, context, keepPVCsForPendingApproval, pendingApprovalConcurrencyApplied, enableNotifications)
}

func testAccCodefreshPipelineOnCreateBranchIgnoreTrigger(rName, repo, path, revision, context string, ignoreTrigger bool) string {
Expand Down
1 change: 1 addition & 0 deletions docs/resources/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ Optional:

Optional:

- `enable_notifications` (Boolean)
- `keep_pvcs_for_pending_approval` (Boolean) When build enters 'Pending Approval' state, volume should:
* Default (attribute not specified): "Use Setting accounts"
* true: "Remain (build remains active)"
Expand Down
Loading