Skip to content

Commit 49c99f4

Browse files
authored
Merge branch 'main' into feat/organization-security-configuration
2 parents 5f3cb9d + 68741e0 commit 49c99f4

5 files changed

Lines changed: 79 additions & 25 deletions

github/resource_github_emu_group_mapping.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func resourceGithubEMUGroupMapping() *schema.Resource {
2424
Description: "Manages the mapping of an external group to a GitHub team.",
2525
Schema: map[string]*schema.Schema{
2626
"team_id": {
27-
Type: schema.TypeString,
27+
Type: schema.TypeInt,
2828
Computed: true,
2929
Description: "ID of the GitHub team.",
3030
},
@@ -99,7 +99,7 @@ func resourceGithubEMUGroupMappingCreate(ctx context.Context, d *schema.Resource
9999
return diag.FromErr(err)
100100
}
101101

102-
if err := d.Set("team_id", teamID); err != nil {
102+
if err := d.Set("team_id", int(teamID)); err != nil {
103103
return diag.FromErr(err)
104104
}
105105

@@ -334,7 +334,7 @@ func resourceGithubEMUGroupMappingImport(ctx context.Context, d *schema.Resource
334334
return nil, err
335335
}
336336

337-
if err := d.Set("team_id", teamID); err != nil {
337+
if err := d.Set("team_id", int(teamID)); err != nil {
338338
return nil, err
339339
}
340340

github/resource_github_emu_group_mapping_migration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func resourceGithubEMUGroupMappingStateUpgradeV0(ctx context.Context, rawState m
5656
if err != nil {
5757
return nil, err
5858
}
59-
rawState["team_id"] = teamID
59+
rawState["team_id"] = int(teamID)
6060
resourceID, err := buildID(strconv.FormatInt(teamID, 10), teamSlug, strconv.FormatInt(group.GetGroupID(), 10))
6161
if err != nil {
6262
return nil, err

github/resource_github_repository.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,11 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository {
630630
}
631631

632632
// only configure allow forking if repository is not public
633-
if allowForking, ok := d.GetOkExists("allow_forking"); ok && visibility != "public" { //nolint:staticcheck,SA1019 // We sometimes need to use GetOkExists for booleans
634-
if val, ok := allowForking.(bool); ok {
635-
repository.AllowForking = github.Ptr(val)
633+
if visibility != "public" && (d.IsNewResource() || d.HasChange("allow_forking")) {
634+
if allowForking, ok := d.GetOkExists("allow_forking"); ok { //nolint:staticcheck,SA1019 // We sometimes need to use GetOkExists for booleans
635+
if val, ok := allowForking.(bool); ok {
636+
repository.AllowForking = github.Ptr(val)
637+
}
636638
}
637639
}
638640

github/resource_github_repository_test.go

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,20 +1078,15 @@ resource "github_repository" "test" {
10781078
}
10791079
`, testRepoName)
10801080

1081-
check := resource.ComposeTestCheckFunc(
1082-
resource.TestCheckResourceAttr(
1083-
"github_repository.private", "visibility",
1084-
"private",
1085-
),
1086-
)
1087-
10881081
resource.Test(t, resource.TestCase{
10891082
PreCheck: func() { skipUnauthenticated(t) },
10901083
ProviderFactories: providerFactories,
10911084
Steps: []resource.TestStep{
10921085
{
1093-
Config: config,
1094-
Check: check,
1086+
Config: fmt.Sprintf(config, testRepoName, "foo"),
1087+
Check: resource.ComposeTestCheckFunc(
1088+
resource.TestCheckResourceAttr("github_repository.private", "visibility", "private"),
1089+
),
10951090
},
10961091
},
10971092
})
@@ -1107,20 +1102,15 @@ resource "github_repository" "test" {
11071102
}
11081103
`, testRepoName)
11091104

1110-
check := resource.ComposeTestCheckFunc(
1111-
resource.TestCheckResourceAttr(
1112-
"github_repository.test", "visibility",
1113-
"internal",
1114-
),
1115-
)
1116-
11171105
resource.Test(t, resource.TestCase{
11181106
PreCheck: func() { skipUnlessMode(t, enterprise) },
11191107
ProviderFactories: providerFactories,
11201108
Steps: []resource.TestStep{
11211109
{
11221110
Config: config,
1123-
Check: check,
1111+
Check: resource.ComposeTestCheckFunc(
1112+
resource.TestCheckResourceAttr("github_repository.test", "visibility", "internal"),
1113+
),
11241114
},
11251115
},
11261116
})
@@ -1327,6 +1317,68 @@ resource "github_repository" "test" {
13271317
},
13281318
})
13291319
})
1320+
1321+
t.Run("check_allow_forking_not_set", func(t *testing.T) {
1322+
t.Skip("This test should be run manually after confirming that the test organization has been correctly configured to disable setting forking at the repo level.")
1323+
1324+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1325+
testRepoName := fmt.Sprintf("%s%s", testResourcePrefix, randomID)
1326+
1327+
config := `
1328+
resource "github_repository" "private" {
1329+
name = "%s"
1330+
description = "%s"
1331+
visibility = "private"
1332+
}
1333+
`
1334+
1335+
resource.Test(t, resource.TestCase{
1336+
PreCheck: func() { skipUnauthenticated(t) },
1337+
ProviderFactories: providerFactories,
1338+
Steps: []resource.TestStep{
1339+
{
1340+
Config: fmt.Sprintf(config, testRepoName, "foo"),
1341+
Check: resource.ComposeTestCheckFunc(
1342+
resource.TestCheckResourceAttr("github_repository.private", "allow_forking", "false"),
1343+
),
1344+
},
1345+
{
1346+
Config: fmt.Sprintf(config, testRepoName, "bar"),
1347+
},
1348+
},
1349+
})
1350+
})
1351+
1352+
t.Run("check_vulnerability_alerts_not_set", func(t *testing.T) {
1353+
t.Skip("This test should be run manually after confirming that the test organization has been correctly configured to disable setting vulnerability alerts at the repo level.")
1354+
1355+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1356+
testRepoName := fmt.Sprintf("%s%s", testResourcePrefix, randomID)
1357+
1358+
config := `
1359+
resource "github_repository" "private" {
1360+
name = "%s"
1361+
description = "%s"
1362+
visibility = "public"
1363+
}
1364+
`
1365+
1366+
resource.Test(t, resource.TestCase{
1367+
PreCheck: func() { skipUnauthenticated(t) },
1368+
ProviderFactories: providerFactories,
1369+
Steps: []resource.TestStep{
1370+
{
1371+
Config: fmt.Sprintf(config, testRepoName, "foo"),
1372+
Check: resource.ComposeTestCheckFunc(
1373+
resource.TestCheckResourceAttr("github_repository.private", "vulnerability_alerts", "true"),
1374+
),
1375+
},
1376+
{
1377+
Config: fmt.Sprintf(config, testRepoName, "bar"),
1378+
},
1379+
},
1380+
})
1381+
})
13301382
}
13311383

13321384
func Test_expandPages(t *testing.T) {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.24.4
44

55
require (
66
github.com/go-jose/go-jose/v3 v3.0.4
7-
github.com/google/go-cmp v0.7.0
87
github.com/google/go-github/v82 v82.0.0
98
github.com/google/uuid v1.6.0
109
github.com/hashicorp/go-cty v1.5.0
@@ -22,6 +21,7 @@ require (
2221
github.com/cloudflare/circl v1.6.1 // indirect
2322
github.com/fatih/color v1.18.0 // indirect
2423
github.com/golang/protobuf v1.5.4 // indirect
24+
github.com/google/go-cmp v0.7.0 // indirect
2525
github.com/google/go-querystring v1.2.0 // indirect
2626
github.com/hashicorp/errwrap v1.0.0 // indirect
2727
github.com/hashicorp/go-checkpoint v0.5.0 // indirect

0 commit comments

Comments
 (0)