From 0dfbaf82bb32e7fabc2a9e6b0cffcc25436a8bce Mon Sep 17 00:00:00 2001 From: Pier-Luc Gagnon Date: Thu, 7 Nov 2024 10:26:22 -0500 Subject: [PATCH 1/3] feat: support github team notification setting --- github/data_source_github_team.go | 9 ++++++++- github/resource_github_team.go | 26 +++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/github/data_source_github_team.go b/github/data_source_github_team.go index 4e5f534175..9a822f6f42 100644 --- a/github/data_source_github_team.go +++ b/github/data_source_github_team.go @@ -4,7 +4,7 @@ import ( "context" "strconv" - "github.com/google/go-github/v65/github" + "github.com/google/go-github/v66/github" "github.com/shurcooL/githubv4" @@ -33,6 +33,10 @@ func dataSourceGithubTeam() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "notification_setting": { + Type: schema.TypeString, + Computed: true, + }, "permission": { Type: schema.TypeString, Computed: true, @@ -210,6 +214,9 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error { if err = d.Set("privacy", team.GetPrivacy()); err != nil { return err } + if err = d.Set("notification_setting", team.GetNotificationSetting()); err != nil { + return err + } if err = d.Set("permission", team.GetPermission()); err != nil { return err } diff --git a/github/resource_github_team.go b/github/resource_github_team.go index 9943e1c34c..8b5e5efa32 100644 --- a/github/resource_github_team.go +++ b/github/resource_github_team.go @@ -6,7 +6,7 @@ import ( "net/http" "strconv" - "github.com/google/go-github/v65/github" + "github.com/google/go-github/v66/github" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/shurcooL/githubv4" @@ -46,6 +46,13 @@ func resourceGithubTeam() *schema.Resource { Description: "The level of privacy for the team. Must be one of 'secret' or 'closed'.", ValidateDiagFunc: validateValueFunc([]string{"secret", "closed"}), }, + "notification_setting": { + Type: schema.TypeString, + Optional: true, + Default: "notifications_enabled", + Description: "The notification setting for the team. Must be one of 'notifications_enabled' or 'notifications_disabled'.", + ValidateDiagFunc: validateValueFunc([]string{"notifications_enabled", "notifications_disabled"}), + }, "parent_team_id": { Type: schema.TypeString, Optional: true, @@ -115,9 +122,10 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error { name := d.Get("name").(string) newTeam := github.NewTeam{ - Name: name, - Description: github.String(d.Get("description").(string)), - Privacy: github.String(d.Get("privacy").(string)), + Name: name, + Description: github.String(d.Get("description").(string)), + Privacy: github.String(d.Get("privacy").(string)), + NotificationSetting: github.String(d.Get("notification_setting").(string)), } if ldapDN := d.Get("ldap_dn").(string); ldapDN != "" { @@ -222,6 +230,9 @@ func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error { if err = d.Set("privacy", team.GetPrivacy()); err != nil { return err } + if err = d.Set("notification_setting", team.GetNotificationSetting()); err != nil { + return err + } if parent := team.Parent; parent != nil { if err = d.Set("parent_team_id", strconv.FormatInt(team.Parent.GetID(), 10)); err != nil { return err @@ -270,9 +281,10 @@ func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error { var removeParentTeam bool editedTeam := github.NewTeam{ - Name: d.Get("name").(string), - Description: github.String(d.Get("description").(string)), - Privacy: github.String(d.Get("privacy").(string)), + Name: d.Get("name").(string), + Description: github.String(d.Get("description").(string)), + Privacy: github.String(d.Get("privacy").(string)), + NotificationSetting: github.String(d.Get("notification_setting").(string)), } if parentTeamID, ok := d.GetOk("parent_team_id"); ok { teamId, err := getTeamID(parentTeamID.(string), meta) From 1cbfa25bed9b5d027ae673ff538b0dc2f2bf25ed Mon Sep 17 00:00:00 2001 From: Pier-Luc Gagnon Date: Thu, 7 Nov 2024 10:36:50 -0500 Subject: [PATCH 2/3] docs --- website/docs/d/team.html.markdown | 1 + website/docs/r/team.html.markdown | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/website/docs/d/team.html.markdown b/website/docs/d/team.html.markdown index 85ded315b8..db47998181 100644 --- a/website/docs/d/team.html.markdown +++ b/website/docs/d/team.html.markdown @@ -31,6 +31,7 @@ data "github_team" "example" { * `name` - the team's full name. * `description` - the team's description. * `privacy` - the team's privacy type. +* `notification_setting` - the team's notification setting. * `permission` - the team's permission level. * `members` - List of team members (list of GitHub usernames). Not returned if `summary_only = true` * `repositories` - List of team repositories (list of repo names). Not returned if `summary_only = true` diff --git a/website/docs/r/team.html.markdown b/website/docs/r/team.html.markdown index 491467f7f0..5236c402ca 100644 --- a/website/docs/r/team.html.markdown +++ b/website/docs/r/team.html.markdown @@ -17,9 +17,10 @@ a new team will be created. When destroyed, that team will be removed. ```hcl # Add a team to the organization resource "github_team" "some_team" { - name = "some-team" - description = "Some cool team" - privacy = "closed" + name = "some-team" + description = "Some cool team" + privacy = "closed" + notification_setting = "notifications_enabled" } ``` @@ -31,6 +32,8 @@ The following arguments are supported: * `description` - (Optional) A description of the team. * `privacy` - (Optional) The level of privacy for the team. Must be one of `secret` or `closed`. Defaults to `secret`. +* `notification_setting` - (Optional) The notification setting for the team. Must be one of `notifications_enabled` or `notifications_disabled`. + Defaults to `notifications_disabled` * `parent_team_id` - (Optional) The ID or slug of the parent team, if this is a nested team. * `ldap_dn` - (Optional) The LDAP Distinguished Name of the group where membership will be synchronized. Only available in GitHub Enterprise Server. * `create_default_maintainer` - (Optional) Adds a default maintainer to the team. Defaults to `false` and adds the creating user to the team when `true`. From cf6caf25783e64c8a61d19beb9357b9e544e14c5 Mon Sep 17 00:00:00 2001 From: Nepoxx <1477090+Nepoxx@users.noreply.github.com> Date: Wed, 6 Aug 2025 09:03:01 -0400 Subject: [PATCH 3/3] Add tests for team notification_setting field - Add resource tests covering default, enabled, and disabled notification settings - Add data source tests verifying notification_setting is properly exposed - Include update scenarios to test field mutability --- github/data_source_github_team_test.go | 54 ++++++++++++++++++ github/resource_github_team_test.go | 77 ++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/github/data_source_github_team_test.go b/github/data_source_github_team_test.go index c9a76d8a85..058f34a4a1 100644 --- a/github/data_source_github_team_test.go +++ b/github/data_source_github_team_test.go @@ -228,6 +228,60 @@ func TestAccGithubTeamDataSource(t *testing.T) { }) + t.Run("queries teams with notification settings", func(t *testing.T) { + + config := fmt.Sprintf(` + resource "github_team" "test_enabled" { + name = "tf-acc-test-enabled-%s" + notification_setting = "notifications_enabled" + } + + resource "github_team" "test_disabled" { + name = "tf-acc-test-disabled-%s" + notification_setting = "notifications_disabled" + } + + data "github_team" "test_enabled" { + slug = github_team.test_enabled.slug + } + + data "github_team" "test_disabled" { + slug = github_team.test_disabled.slug + } + `, randomID, randomID) + + check := resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.github_team.test_enabled", "notification_setting", "notifications_enabled"), + resource.TestCheckResourceAttr("data.github_team.test_disabled", "notification_setting", "notifications_disabled"), + ) + + testCase := func(t *testing.T, mode string) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnlessMode(t, mode) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: config, + Check: check, + }, + }, + }) + } + + t.Run("with an anonymous account", func(t *testing.T) { + t.Skip("anonymous account not supported for this operation") + }) + + t.Run("with an individual account", func(t *testing.T) { + t.Skip("individual account not supported for this operation") + }) + + t.Run("with an organization account", func(t *testing.T) { + testCase(t, organization) + }) + + }) + t.Run("queries an existing team with connected repositories", func(t *testing.T) { config := fmt.Sprintf(` diff --git a/github/resource_github_team_test.go b/github/resource_github_team_test.go index 93ed1f4c68..e4b1912f58 100644 --- a/github/resource_github_team_test.go +++ b/github/resource_github_team_test.go @@ -193,6 +193,83 @@ func TestAccGithubTeamRemovesDefaultMaintainer(t *testing.T) { } +func TestAccGithubTeamNotificationSetting(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + + t.Run("creates teams with different notification settings", func(t *testing.T) { + + config := fmt.Sprintf(` + resource "github_team" "test_default" { + name = "tf-acc-default-%s" + } + + resource "github_team" "test_enabled" { + name = "tf-acc-enabled-%s" + notification_setting = "notifications_enabled" + } + + resource "github_team" "test_disabled" { + name = "tf-acc-disabled-%s" + notification_setting = "notifications_disabled" + } + `, randomID, randomID, randomID) + + configUpdated := fmt.Sprintf(` + resource "github_team" "test_default" { + name = "tf-acc-default-%s" + } + + resource "github_team" "test_enabled" { + name = "tf-acc-enabled-%s" + notification_setting = "notifications_disabled" + } + + resource "github_team" "test_disabled" { + name = "tf-acc-disabled-%s" + notification_setting = "notifications_enabled" + } + `, randomID, randomID, randomID) + + testCase := func(t *testing.T, mode string) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnlessMode(t, mode) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("github_team.test_default", "notification_setting", "notifications_enabled"), + resource.TestCheckResourceAttr("github_team.test_enabled", "notification_setting", "notifications_enabled"), + resource.TestCheckResourceAttr("github_team.test_disabled", "notification_setting", "notifications_disabled"), + ), + }, + { + Config: configUpdated, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("github_team.test_default", "notification_setting", "notifications_enabled"), + resource.TestCheckResourceAttr("github_team.test_enabled", "notification_setting", "notifications_disabled"), + resource.TestCheckResourceAttr("github_team.test_disabled", "notification_setting", "notifications_enabled"), + ), + }, + }, + }) + } + + t.Run("with an anonymous account", func(t *testing.T) { + t.Skip("anonymous account not supported for this operation") + }) + + t.Run("with an individual account", func(t *testing.T) { + t.Skip("individual account not supported for this operation") + }) + + t.Run("with an organization account", func(t *testing.T) { + testCase(t, organization) + }) + + }) +} + func TestAccGithubTeamUpdateName(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)