Skip to content

Commit c9b18f1

Browse files
authored
Merge branch 'main' into exempt-bypass
2 parents 1bb4a02 + 1d3427e commit c9b18f1

27 files changed

Lines changed: 473 additions & 62 deletions

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ export GITHUB_OWNER=
149149
# enable testing of enterprise appliances
150150
export GITHUB_BASE_URL=
151151

152+
# enable testing of GitHub Paid features, these normally also require an organization e.g. repository push rulesets
153+
export GITHUB_PAID_FEATURES=true
154+
152155
# leverage helper accounts for tests requiring them
153156
# examples include:
154157
# - https://github.com/github-terraform-test-user

github/data_source_github_organization_teams.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package github
22

33
import (
4+
"context"
5+
"strconv"
6+
7+
"github.com/google/go-github/v66/github"
48
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
59
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
610
"github.com/shurcooL/githubv4"
@@ -67,9 +71,18 @@ func dataSourceGithubOrganizationTeams() *schema.Resource {
6771
Elem: &schema.Schema{Type: schema.TypeString},
6872
},
6973
"parent": {
70-
Type: schema.TypeMap,
74+
Deprecated: "Use parent_team_id and parent_team_slug instead.",
75+
Type: schema.TypeMap,
76+
Computed: true,
77+
Elem: &schema.Schema{Type: schema.TypeString},
78+
},
79+
"parent_team_id": {
80+
Type: schema.TypeString,
81+
Computed: true,
82+
},
83+
"parent_team_slug": {
84+
Type: schema.TypeString,
7185
Computed: true,
72-
Elem: &schema.Schema{Type: schema.TypeString},
7386
},
7487
},
7588
},
@@ -84,6 +97,7 @@ func dataSourceGithubOrganizationTeamsRead(d *schema.ResourceData, meta interfac
8497
return err
8598
}
8699

100+
clientv3 := meta.(*Owner).v3client
87101
client := meta.(*Owner).v4client
88102
orgName := meta.(*Owner).name
89103
rootTeamsOnly := d.Get("root_teams_only").(bool)
@@ -107,7 +121,10 @@ func dataSourceGithubOrganizationTeamsRead(d *schema.ResourceData, meta interfac
107121
return err
108122
}
109123

110-
additionalTeams := flattenGitHubTeams(query)
124+
additionalTeams, err := flattenGitHubTeams(clientv3, meta.(*Owner).StopContext, orgName, query)
125+
if err != nil {
126+
return err
127+
}
111128
teams = append(teams, additionalTeams...)
112129

113130
if !query.Organization.Teams.PageInfo.HasNextPage {
@@ -125,11 +142,11 @@ func dataSourceGithubOrganizationTeamsRead(d *schema.ResourceData, meta interfac
125142
return nil
126143
}
127144

128-
func flattenGitHubTeams(tq TeamsQuery) []interface{} {
145+
func flattenGitHubTeams(client *github.Client, ctx context.Context, org string, tq TeamsQuery) ([]interface{}, error) {
129146
teams := tq.Organization.Teams.Nodes
130147

131148
if len(teams) == 0 {
132-
return make([]interface{}, 0)
149+
return make([]interface{}, 0), nil
133150
}
134151

135152
flatTeams := make([]interface{}, len(teams))
@@ -152,6 +169,18 @@ func flattenGitHubTeams(tq TeamsQuery) []interface{} {
152169

153170
t["members"] = flatMembers
154171

172+
var parentTeamId string
173+
if len(team.Parent.Slug) != 0 {
174+
parentTeam, _, err := client.Teams.GetTeamBySlug(ctx, org, string(team.Parent.Slug))
175+
if err != nil {
176+
return nil, err
177+
}
178+
parentTeamId = strconv.FormatInt(parentTeam.GetID(), 10)
179+
}
180+
181+
t["parent_team_id"] = parentTeamId
182+
t["parent_team_slug"] = team.Parent.Slug
183+
155184
parentTeam := make(map[string]interface{})
156185
parentTeam["id"] = team.Parent.ID
157186
parentTeam["slug"] = team.Parent.Slug
@@ -171,5 +200,5 @@ func flattenGitHubTeams(tq TeamsQuery) []interface{} {
171200
flatTeams[i] = t
172201
}
173202

174-
return flatTeams
203+
return flatTeams, nil
175204
}

github/data_source_github_team.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ func dataSourceGithubTeam() *schema.Resource {
4343
Elem: &schema.Schema{Type: schema.TypeString},
4444
},
4545
"repositories": {
46-
Type: schema.TypeList,
47-
Computed: true,
48-
Elem: &schema.Schema{Type: schema.TypeString},
46+
Deprecated: "Use repositories_detailed instead.",
47+
Type: schema.TypeList,
48+
Computed: true,
49+
Elem: &schema.Schema{Type: schema.TypeString},
4950
},
5051
"repositories_detailed": {
5152
Type: schema.TypeList,
@@ -56,6 +57,10 @@ func dataSourceGithubTeam() *schema.Resource {
5657
Type: schema.TypeInt,
5758
Computed: true,
5859
},
60+
"repo_name": {
61+
Type: schema.TypeString,
62+
Computed: true,
63+
},
5964
"role_name": {
6065
Type: schema.TypeString,
6166
Computed: true,
@@ -168,7 +173,7 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
168173
}
169174
}
170175

171-
repositories_detailed = make([]interface{}, 0, resultsPerPage) //removed this from the loop
176+
repositories_detailed = make([]interface{}, 0, resultsPerPage) // removed this from the loop
172177

173178
for {
174179
repository, resp, err := client.Teams.ListTeamReposByID(ctx, orgId, team.GetID(), &options.ListOptions)
@@ -180,6 +185,7 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
180185
repositories = append(repositories, v.GetName())
181186
repositories_detailed = append(repositories_detailed, map[string]interface{}{
182187
"repo_id": v.GetID(),
188+
"repo_name": v.GetName(),
183189
"role_name": v.GetRoleName(),
184190
})
185191
}

github/provider_utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
var testCollaborator = os.Getenv("GITHUB_TEST_COLLABORATOR")
1111
var isEnterprise = os.Getenv("ENTERPRISE_ACCOUNT")
12+
var isPaidPlan = os.Getenv("GITHUB_PAID_FEATURES")
1213
var testEnterprise = os.Getenv("ENTERPRISE_SLUG")
1314
var testOrganization = testOrganizationFunc()
1415
var testOwner = os.Getenv("GITHUB_OWNER")

github/resource_github_branch_protection_v3.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func resourceGithubBranchProtectionV3() *schema.Resource {
5959
"contexts": {
6060
Type: schema.TypeSet,
6161
Optional: true,
62+
Computed: true,
6263
Deprecated: "GitHub is deprecating the use of `contexts`. Use a `checks` array instead.",
6364
Elem: &schema.Schema{
6465
Type: schema.TypeString,
@@ -67,10 +68,12 @@ func resourceGithubBranchProtectionV3() *schema.Resource {
6768
"checks": {
6869
Type: schema.TypeSet,
6970
Optional: true,
71+
Computed: true,
7072
Description: "The list of status checks to require in order to merge into this branch. No status checks are required by default. Checks should be strings containing the 'context' and 'app_id' like so 'context:app_id'",
7173
Elem: &schema.Schema{
7274
Type: schema.TypeString,
7375
},
76+
ConflictsWith: []string{"required_status_checks.0.contexts"},
7477
},
7578
},
7679
},

github/resource_github_organization_project.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313

1414
func resourceGithubOrganizationProject() *schema.Resource {
1515
return &schema.Resource{
16+
DeprecationMessage: "This resource is deprecated as the API endpoints for classic projects have been removed. This resource no longer works and will be removed in a future version.",
17+
1618
Create: resourceGithubOrganizationProjectCreate,
1719
Read: resourceGithubOrganizationProjectRead,
1820
Update: resourceGithubOrganizationProjectUpdate,

github/resource_github_organization_project_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
)
1414

1515
func TestAccGithubOrganizationProject_basic(t *testing.T) {
16+
t.Skip("Skipping test as the GitHub REST API no longer supports classic projects")
17+
1618
if err := testAccCheckOrganization(); err != nil {
1719
t.Skipf("Skipping because %s.", err.Error())
1820
}
@@ -102,7 +104,6 @@ type testAccGithubOrganizationProjectExpectedAttributes struct {
102104

103105
func testAccCheckGithubOrganizationProjectAttributes(project *github.Project, want *testAccGithubOrganizationProjectExpectedAttributes) resource.TestCheckFunc {
104106
return func(s *terraform.State) error {
105-
106107
if name := project.GetName(); name != want.Name {
107108
return fmt.Errorf("got project %q; want %q", name, want.Name)
108109
}

github/resource_github_organization_ruleset.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
261261
Optional: true,
262262
Description: "Whether pull requests targeting a matching branch must be tested with the latest code. This setting will not take effect unless at least one status check is enabled. Defaults to `false`.",
263263
},
264+
"do_not_enforce_on_create": {
265+
Type: schema.TypeBool,
266+
Optional: true,
267+
Description: "Allow repositories and branches to be created if a check would otherwise prohibit it.",
268+
Default: false,
269+
},
264270
},
265271
},
266272
},

github/resource_github_organization_ruleset_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func TestGithubOrganizationRulesets(t *testing.T) {
6060
}
6161
6262
strict_required_status_checks_policy = true
63+
do_not_enforce_on_create = true
6364
}
6465
6566
required_workflows {
@@ -251,6 +252,7 @@ func TestGithubOrganizationRulesets(t *testing.T) {
251252
}
252253
253254
strict_required_status_checks_policy = true
255+
do_not_enforce_on_create = true
254256
}
255257
256258
branch_name_pattern {

github/resource_github_project_card.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414

1515
func resourceGithubProjectCard() *schema.Resource {
1616
return &schema.Resource{
17+
DeprecationMessage: "This resource is deprecated as the API endpoints for classic projects have been removed. This resource no longer works and will be removed in a future version.",
18+
1719
Create: resourceGithubProjectCardCreate,
1820
Read: resourceGithubProjectCardRead,
1921
Update: resourceGithubProjectCardUpdate,
@@ -184,7 +186,6 @@ func resourceGithubProjectCardDelete(d *schema.ResourceData, meta interface{}) e
184186
}
185187

186188
func resourceGithubProjectCardImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
187-
188189
cardIDStr := d.Id()
189190
cardID, err := strconv.ParseInt(cardIDStr, 10, 64)
190191
if err != nil {
@@ -205,5 +206,4 @@ func resourceGithubProjectCardImport(d *schema.ResourceData, meta interface{}) (
205206
}
206207

207208
return []*schema.ResourceData{d}, nil
208-
209209
}

0 commit comments

Comments
 (0)