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

Add Microsoft Teams notification destination type #389

Merged
merged 2 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# v1.2.0 (Unreleased)
# v1.3.0 (Unreleased)

## Enhancements
* Adds support for Microsoft Teams notification configuration by @JarrettSpiker [#398](https://github.com/hashicorp/go-tfe/pull/389)

# v1.2.0

## Enhancements
* Adds support for reading current state version outputs to StateVersionOutputs, which can be useful for reading outputs when users don't have the necessary permissions to read the entire state by @brandonc [#370](https://github.com/hashicorp/go-tfe/pull/370)
Expand Down
12 changes: 8 additions & 4 deletions notification_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ type NotificationDestinationType string

// List of available notification destination types.
const (
NotificationDestinationTypeEmail NotificationDestinationType = "email"
NotificationDestinationTypeGeneric NotificationDestinationType = "generic"
NotificationDestinationTypeSlack NotificationDestinationType = "slack"
NotificationDestinationTypeEmail NotificationDestinationType = "email"
NotificationDestinationTypeGeneric NotificationDestinationType = "generic"
NotificationDestinationTypeSlack NotificationDestinationType = "slack"
NotificationDestinationTypeMicrosoftTeams NotificationDestinationType = "microsoft-teams"
)

// NotificationConfigurationList represents a list of Notification
Expand Down Expand Up @@ -319,7 +320,10 @@ func (o NotificationConfigurationCreateOptions) valid() error {
return ErrInvalidNotificationTrigger
}

if *o.DestinationType == NotificationDestinationTypeGeneric || *o.DestinationType == NotificationDestinationTypeSlack {
if *o.DestinationType == NotificationDestinationTypeGeneric ||
*o.DestinationType == NotificationDestinationTypeSlack ||
*o.DestinationType == NotificationDestinationTypeMicrosoftTeams {

if o.URL == nil {
return ErrRequiredURL
}
Expand Down
26 changes: 26 additions & 0 deletions notification_configuration_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,32 @@ func TestNotificationConfigurationCreate(t *testing.T) {
assert.Equal(t, err, ErrRequiredURL)
})

t.Run("without a required value URL when destination type is slack", func(t *testing.T) {
options := NotificationConfigurationCreateOptions{
DestinationType: NotificationDestination(NotificationDestinationTypeSlack),
Enabled: Bool(false),
Name: String(randomString(t)),
Triggers: []NotificationTriggerType{NotificationTriggerCreated},
}

nc, err := client.NotificationConfigurations.Create(ctx, wTest.ID, options)
assert.Nil(t, nc)
assert.Equal(t, err, ErrRequiredURL)
})

t.Run("without a required value URL when destination type is MS Teams", func(t *testing.T) {
options := NotificationConfigurationCreateOptions{
DestinationType: NotificationDestination(NotificationDestinationTypeMicrosoftTeams),
Enabled: Bool(false),
Name: String(randomString(t)),
Triggers: []NotificationTriggerType{NotificationTriggerCreated},
}

nc, err := client.NotificationConfigurations.Create(ctx, wTest.ID, options)
assert.Nil(t, nc)
assert.Equal(t, err, ErrRequiredURL)
})

t.Run("without a valid workspace", func(t *testing.T) {
nc, err := client.NotificationConfigurations.Create(ctx, badIdentifier, NotificationConfigurationCreateOptions{})
assert.Nil(t, nc)
Expand Down