Skip to content

Commit

Permalink
Add webhook_url to Bitbucket Cloud integration data source (#484)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcin Białoń <[email protected]>
  • Loading branch information
mbialon authored Nov 27, 2023
1 parent 4961bcb commit 0d6e7d6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/bitbucket_cloud_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ data "spacelift_bitbucket_cloud_integration" "bitbucket_cloud_integration" {}

- `id` (String) The ID of this resource.
- `username` (String) Bitbucket Cloud username
- `webhook_url` (String) Bitbucket Cloud integration webhook URL
15 changes: 12 additions & 3 deletions spacelift/data_bitbucket_cloud_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
)

var bitbucketCloudFields = struct {
Username string
Username string
WebhookURL string
}{
Username: "username",
Username: "username",
WebhookURL: "webhook_url",
}

func dataBitbucketCloudIntegration() *schema.Resource {
Expand All @@ -27,14 +29,20 @@ func dataBitbucketCloudIntegration() *schema.Resource {
Description: "Bitbucket Cloud username",
Computed: true,
},
bitbucketCloudFields.WebhookURL: {
Type: schema.TypeString,
Description: "Bitbucket Cloud integration webhook URL",
Computed: true,
},
},
}
}

func dataBitbucketCloudIntegrationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var query struct {
BitbucketCloudIntegration *struct {
Username string `graphql:"username"`
Username string `graphql:"username"`
WebhookURL string `graphql:"webhookUrl"`
} `graphql:"bitbucketCloudIntegration"`
}

Expand All @@ -49,6 +57,7 @@ func dataBitbucketCloudIntegrationRead(ctx context.Context, d *schema.ResourceDa

d.SetId("spacelift_bitbucket_cloud_integration_id") // TF expects id to be set otherwise it will fail
d.Set(bitbucketCloudFields.Username, bitbucketCloudIntegration.Username)
d.Set(bitbucketCloudFields.WebhookURL, bitbucketCloudIntegration.WebhookURL)

return nil
}
25 changes: 18 additions & 7 deletions spacelift/data_bitbucket_cloud_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ import (
)

func TestBitbucketCloudIntegrationData(t *testing.T) {
testSteps(t, []resource.TestStep{{
Config: `
testSteps(t, []resource.TestStep{
{
Config: `
data "spacelift_bitbucket_cloud_integration" "test" {}
`,
Check: Resource(
"data.spacelift_bitbucket_cloud_integration.test",
Attribute("username", IsNotEmpty()),
),
}})
Check: Resource(
"data.spacelift_bitbucket_cloud_integration.test",
Attribute("username", IsNotEmpty()),
),
},
{
Config: `
data "spacelift_bitbucket_cloud_integration" "test" {}
`,
Check: Resource(
"data.spacelift_bitbucket_cloud_integration.test",
Attribute("webhook_url", IsNotEmpty()),
),
},
})
}

0 comments on commit 0d6e7d6

Please sign in to comment.