Skip to content

Commit

Permalink
Merge branch 'main' into tooling-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehipwell authored Mar 25, 2024
2 parents ec70d06 + 0ff85ac commit 244d0a0
Show file tree
Hide file tree
Showing 368 changed files with 18,403 additions and 11,878 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/add_to_octokit_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/add-to-project@0609a2702eefb44781da00f8e04901d6e5cd2b92 # v0.6.0
- uses: actions/add-to-project@1b844f0c5ac6446a402e0cb3693f9be5eca188c5 # v0.6.1
with:
project-url: https://github.com/orgs/octokit/projects/10
github-token: ${{ secrets.OCTOKITBOT_PROJECT_ACTION_TOKEN }}
Expand Down
9 changes: 9 additions & 0 deletions github/data_source_github_enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ func dataSourceGithubEnterprise() *schema.Resource {
return &schema.Resource{
Read: dataSourceGithubEnterpriseRead,
Schema: map[string]*schema.Schema{
"database_id": {
Type: schema.TypeInt,
Computed: true,
},
"slug": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -40,6 +44,7 @@ func dataSourceGithubEnterpriseRead(data *schema.ResourceData, meta interface{})
var query struct {
Enterprise struct {
ID githubv4.String
DatabaseId githubv4.Int
Name githubv4.String
Description githubv4.String
CreatedAt githubv4.String
Expand Down Expand Up @@ -76,6 +81,10 @@ func dataSourceGithubEnterpriseRead(data *schema.ResourceData, meta interface{})
if err != nil {
return err
}
err = data.Set("database_id", query.Enterprise.DatabaseId)
if err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func Provider() *schema.Provider {
"github_user_invitation_accepter": resourceGithubUserInvitationAccepter(),
"github_user_ssh_key": resourceGithubUserSshKey(),
"github_enterprise_organization": resourceGithubEnterpriseOrganization(),
"github_enterprise_actions_runner_group": resourceGithubActionsEnterpriseRunnerGroup(),
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down
6 changes: 6 additions & 0 deletions github/resource_github_branch_protection_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ func resourceGithubBranchProtectionV3() *schema.Resource {
Description: "Require 'x' number of approvals to satisfy branch protection requirements. If this is specified it must be a number between 0-6.",
ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 6), "required_approving_review_count"),
},
"require_last_push_approval": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Require that the most recent push must be approved by someone other than the last pusher.",
},
"bypass_pull_request_allowances": {
Type: schema.TypeList,
Optional: true,
Expand Down
4 changes: 4 additions & 0 deletions github/resource_github_branch_protection_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ func TestAccGithubBranchProtectionV3_required_pull_request_reviews(t *testing.T)
dismiss_stale_reviews = true
require_code_owner_reviews = true
required_approving_review_count = 1
require_last_push_approval = true
dismissal_users = ["a"]
dismissal_teams = ["b"]
dismissal_apps = ["c"]
Expand Down Expand Up @@ -347,6 +348,9 @@ func TestAccGithubBranchProtectionV3_required_pull_request_reviews(t *testing.T)
resource.TestCheckResourceAttr(
"github_branch_protection_v3.test", "required_pull_request_reviews.0.required_approving_review_count", "1",
),
resource.TestCheckResourceAttr(
"github_branch_protection_v3.test", "required_pull_request_reviews.0.require_last_push_approval", "true",
),
resource.TestCheckResourceAttr(
"github_branch_protection_v3.test", "required_pull_request_reviews.0.dismissal_users.#", "1",
),
Expand Down
3 changes: 3 additions & 0 deletions github/resource_github_branch_protection_v3_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func flattenAndSetRequiredPullRequestReviews(d *schema.ResourceData, protection
"dismissal_teams": schema.NewSet(schema.HashString, teams),
"dismissal_apps": schema.NewSet(schema.HashString, apps),
"require_code_owner_reviews": rprr.RequireCodeOwnerReviews,
"require_last_push_approval": rprr.RequireLastPushApproval,
"required_approving_review_count": rprr.RequiredApprovingReviewCount,
"bypass_pull_request_allowances": bpra,
},
Expand Down Expand Up @@ -351,6 +352,8 @@ func expandRequiredPullRequestReviews(d *schema.ResourceData) (*github.PullReque
rprr.DismissStaleReviews = m["dismiss_stale_reviews"].(bool)
rprr.RequireCodeOwnerReviews = m["require_code_owner_reviews"].(bool)
rprr.RequiredApprovingReviewCount = m["required_approving_review_count"].(int)
requireLastPushApproval := m["require_last_push_approval"].(bool)
rprr.RequireLastPushApproval = &requireLastPushApproval
rprr.BypassPullRequestAllowancesRequest = bpra
}

Expand Down
228 changes: 228 additions & 0 deletions github/resource_github_enteprise_actions_runner_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
package github

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccGithubActionsEnterpriseRunnerGroup(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

if isEnterprise != "true" {
t.Skip("Skipping because `ENTERPRISE_ACCOUNT` is not set or set to false")
}

if testEnterprise == "" {
t.Skip("Skipping because `ENTERPRISE_SLUG` is not set")
}

t.Run("creates enterprise runner groups without error", func(t *testing.T) {
config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
resource "github_enterprise_actions_runner_group" "test" {
enterprise_slug = data.github_enterprise.enterprise.slug
name = "tf-acc-test-%s"
visibility = "all"
allows_public_repositories = true
}
`, testEnterprise, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"github_enterprise_actions_runner_group.test", "name",
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "name",
fmt.Sprintf(`tf-acc-test-%s`, randomID),
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "visibility",
"all",
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "allows_public_repositories",
"true",
),
)

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 enterprise account", func(t *testing.T) {
testCase(t, enterprise)
})
})

t.Run("manages runner group visibility to selected orgs", func(t *testing.T) {

config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
data "github_organization" "org" {
name = "%s"
}
resource "github_enterprise_actions_runner_group" "test" {
enterprise_slug = data.github_enterprise.enterprise.slug
name = "tf-acc-test-%s"
visibility = "selected"
selected_organization_ids = [data.github_organization.org.id]
}
`, testEnterprise, testOrganization, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"github_enterprise_actions_runner_group.test", "name",
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "name",
fmt.Sprintf(`tf-acc-test-%s`, randomID),
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "visibility",
"selected",
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "selected_organization_ids.#",
"1",
),
resource.TestCheckResourceAttrSet(
"github_enterprise_actions_runner_group.test", "selected_organizations_url",
),
)

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 enterprise account", func(t *testing.T) {
testCase(t, enterprise)
})
})

t.Run("imports an all runner group without error", func(t *testing.T) {
config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
resource "github_enterprise_actions_runner_group" "test" {
enterprise_slug = data.github_enterprise.enterprise.slug
name = "tf-acc-test-%s"
visibility = "all"
}
`, testEnterprise, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("github_enterprise_actions_runner_group.test", "name"),
resource.TestCheckResourceAttrSet("github_enterprise_actions_runner_group.test", "visibility"),
resource.TestCheckResourceAttr("github_enterprise_actions_runner_group.test", "visibility", "all"),
resource.TestCheckResourceAttr("github_enterprise_actions_runner_group.test", "name", fmt.Sprintf(`tf-acc-test-%s`, 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: check,
},
{
ResourceName: "github_enterprise_actions_runner_group.test",
ImportState: true,
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf(`%s/`, testEnterprise),
},
},
})
}

t.Run("with an enterprise account", func(t *testing.T) {
testCase(t, enterprise)
})
})

t.Run("imports a runner group with selected orgs without error", func(t *testing.T) {

config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
data "github_organization" "org" {
name = "%s"
}
resource "github_enterprise_actions_runner_group" "test" {
enterprise_slug = data.github_enterprise.enterprise.slug
name = "tf-acc-test-%s"
visibility = "selected"
selected_organization_ids = [data.github_organization.org.id]
}
`, testEnterprise, testOrganization, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("github_enterprise_actions_runner_group.test", "name"),
resource.TestCheckResourceAttr("github_enterprise_actions_runner_group.test", "name", fmt.Sprintf(`tf-acc-test-%s`, randomID)),
resource.TestCheckResourceAttrSet("github_enterprise_actions_runner_group.test", "visibility"),
resource.TestCheckResourceAttr("github_enterprise_actions_runner_group.test", "visibility", "selected"),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "selected_organization_ids.#",
"1",
),
)

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,
},
{
ResourceName: "github_enterprise_actions_runner_group.test",
ImportState: true,
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf(`%s/`, testEnterprise),
},
},
})
}

t.Run("with an enterprise account", func(t *testing.T) {
testCase(t, enterprise)
})
})
}
Loading

0 comments on commit 244d0a0

Please sign in to comment.