Skip to content

Commit

Permalink
Merge pull request #34 from sandrogattuso/feature/is_public
Browse files Browse the repository at this point in the history
Add support for isPublic attribute in pipelines
  • Loading branch information
vadimgusev-codefresh authored Feb 16, 2021
2 parents 7c53585 + 4f8421b commit 0b732c2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Labels struct {
type Metadata struct {
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
IsPublic bool `json:"isPublic,omitempty"`
Labels Labels `json:"labels,omitempty"`
OriginalYamlString string `json:"originalYamlString,omitempty"`
Project string `json:"project,omitempty"`
Expand Down
11 changes: 11 additions & 0 deletions codefresh/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func resourcePipeline() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"is_public": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"revision": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -392,6 +397,11 @@ func mapPipelineToResource(pipeline cfClient.Pipeline, d *schema.ResourceData) e
return err
}

err = d.Set("is_public", pipeline.Metadata.IsPublic)
if err != nil {
return err
}

err = d.Set("spec", flattenSpec(pipeline.Spec))
if err != nil {
return err
Expand Down Expand Up @@ -542,6 +552,7 @@ func mapResourceToPipeline(d *schema.ResourceData) *cfClient.Pipeline {
Name: d.Get("name").(string),
Revision: d.Get("revision").(int),
ProjectId: d.Get("project_id").(string),
IsPublic: d.Get("is_public").(bool),
Labels: cfClient.Labels{
Tags: convertStringArr(tags),
},
Expand Down
61 changes: 60 additions & 1 deletion codefresh/resource_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,38 @@ func TestAccCodefreshPipeline_Revision(t *testing.T) {
})
}

func TestAccCodefreshPipeline_IsPublic(t *testing.T) {
name := pipelineNamePrefix + acctest.RandString(10)
resourceName := "codefresh_pipeline.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCodefreshPipelineDestroy,
Steps: []resource.TestStep{
{
Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCodefreshPipelineExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "is_public", "false"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccCodefreshPipelineIsPublic(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "development", "git", true),
Check: resource.ComposeTestCheckFunc(
testAccCheckCodefreshPipelineExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "is_public", "true"),
),
},
},
})
}

func TestAccCodefreshPipelineOnCreateBranchIgnoreTrigger(t *testing.T) {
name := pipelineNamePrefix + acctest.RandString(10)
resourceName := "codefresh_pipeline.test"
Expand Down Expand Up @@ -584,7 +616,7 @@ resource "codefresh_pipeline" "test" {
branch_regex_input = %q
pull_request_target_branch_regex = %q
comment_regex = %q
context = %q
contexts = [
%q
Expand Down Expand Up @@ -791,3 +823,30 @@ resource "codefresh_pipeline" "test" {
}
`, rName, repo, path, revision, context, branchName, ignoreTrigger)
}

func testAccCodefreshPipelineIsPublic(rName, repo, path, revision, context string, isPublic bool) string {
return fmt.Sprintf(`
resource "codefresh_pipeline" "test" {
lifecycle {
ignore_changes = [
revision
]
}
name = "%s"
spec {
spec_template {
repo = %q
path = %q
revision = %q
context = %q
}
}
is_public = %t
}
`, rName, repo, path, revision, context, isPublic)
}
1 change: 1 addition & 0 deletions docs/resources/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ resource "codefresh_pipeline" "test" {

- `name` - (Required) The display name for the pipeline.
- `revision` - (Optional) The pipeline's revision. Should be added to the **lifecycle/ignore_changes** or incremented mannually each update.
- `is_public` - (Optional) Boolean that specifies if the build logs are publicly accessible. Default: false
- `tags` - (Optional) A list of tags to mark a project for easy management and access control.
- `spec` - (Required) A collection of `spec` blocks as documented below.
- `original_yaml_string` - (Optional) A string with original yaml pipeline.
Expand Down

0 comments on commit 0b732c2

Please sign in to comment.