Skip to content

Commit 3d9beaa

Browse files
authored
Merge branch 'main' into feature/deployment-policy-tag-pattern
2 parents 82749d6 + 84e8d55 commit 3d9beaa

File tree

77 files changed

+3581
-1084
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3581
-1084
lines changed

.github/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes
2+
3+
changelog:
4+
categories:
5+
- title: 💥 Breaking Changes
6+
labels:
7+
- "Type: Breaking change"
8+
9+
- title: 🚀 New Features
10+
labels:
11+
- "Type: Feature"
12+
- "New data source"
13+
- "New resource"
14+
15+
- title: 🐛 Bugfixes
16+
labels:
17+
- "Type: Bug"
18+
19+
- title: 🪦 Deprecations
20+
labels:
21+
- "Deprecation"
22+
23+
- title: 🛠️ Maintenance
24+
labels:
25+
- "Type: Maintenance"
26+
- "dependencies"
27+
28+
- title: 📝 Documentation
29+
labels:
30+
- "Type: Documentation"
31+
32+
- title: 🏷 Other Changes
33+
labels:
34+
- "*"

.github/workflows/add_to_octokit_project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
continue-on-error: true
1414
steps:
15-
- uses: actions/add-to-project@v0.5.0
15+
- uses: actions/add-to-project@v0.6.0
1616
with:
1717
project-url: https://github.com/orgs/octokit/projects/10
1818
github-token: ${{ secrets.OCTOKITBOT_PROJECT_ACTION_TOKEN }}

github/data_source_github_enterprise.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ func dataSourceGithubEnterprise() *schema.Resource {
1212
return &schema.Resource{
1313
Read: dataSourceGithubEnterpriseRead,
1414
Schema: map[string]*schema.Schema{
15+
"database_id": {
16+
Type: schema.TypeInt,
17+
Computed: true,
18+
},
1519
"slug": {
1620
Type: schema.TypeString,
1721
Required: true,
@@ -40,6 +44,7 @@ func dataSourceGithubEnterpriseRead(data *schema.ResourceData, meta interface{})
4044
var query struct {
4145
Enterprise struct {
4246
ID githubv4.String
47+
DatabaseId githubv4.Int
4348
Name githubv4.String
4449
Description githubv4.String
4550
CreatedAt githubv4.String
@@ -76,6 +81,10 @@ func dataSourceGithubEnterpriseRead(data *schema.ResourceData, meta interface{})
7681
if err != nil {
7782
return err
7883
}
84+
err = data.Set("database_id", query.Enterprise.DatabaseId)
85+
if err != nil {
86+
return err
87+
}
7988

8089
return nil
8190
}

github/data_source_github_repositories.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func dataSourceGithubRepositories() *schema.Resource {
3232
Type: schema.TypeInt,
3333
Optional: true,
3434
Default: 100,
35-
ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 100), "results_per_page"),
35+
ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 1000), "results_per_page"),
3636
},
3737
"full_names": {
3838
Type: schema.TypeList,

github/data_source_github_rest_api.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package github
33
import (
44
"context"
55
"encoding/json"
6+
"io"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
89
)
@@ -43,21 +44,22 @@ func dataSourceGithubRestApiRead(d *schema.ResourceData, meta interface{}) error
4344
client := meta.(*Owner).v3client
4445
ctx := context.Background()
4546

46-
var body map[string]interface{}
47-
4847
req, err := client.NewRequest("GET", u, nil)
4948
if err != nil {
5049
return err
5150
}
5251

53-
resp, _ := client.Do(ctx, req, &body)
52+
resp, err := client.Do(ctx, req, nil)
53+
if err != nil && resp.StatusCode != 404 {
54+
return err
55+
}
5456

5557
h, err := json.Marshal(resp.Header)
5658
if err != nil {
5759
return err
5860
}
5961

60-
b, err := json.Marshal(body)
62+
b, err := io.ReadAll(resp.Body)
6163
if err != nil {
6264
return err
6365
}

github/data_source_github_rest_api_test.go

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package github
33
import (
44
"fmt"
55
"regexp"
6+
"strings"
67
"testing"
78

89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
@@ -33,7 +34,7 @@ func TestAccGithubRestApiDataSource(t *testing.T) {
3334
resource.TestMatchResourceAttr(
3435
"data.github_rest_api.test", "status", regexp.MustCompile("200 OK"),
3536
),
36-
resource.TestCheckResourceAttrSet("data.github_rest_api.test", "body"),
37+
resource.TestMatchResourceAttr("data.github_rest_api.test", "body", regexp.MustCompile(".*refs/heads/.*")),
3738
resource.TestCheckResourceAttrSet("data.github_rest_api.test", "headers"),
3839
)
3940

@@ -64,6 +65,50 @@ func TestAccGithubRestApiDataSource(t *testing.T) {
6465

6566
})
6667

68+
t.Run("queries a collection without error", func(t *testing.T) {
69+
70+
config := fmt.Sprintf(`
71+
resource "github_repository" "test" {
72+
name = "tf-acc-test-%[1]s"
73+
auto_init = true
74+
}
75+
76+
data "github_rest_api" "test" {
77+
endpoint = "repos/${github_repository.test.full_name}/git/refs/heads/"
78+
}
79+
`, randomID)
80+
81+
check := resource.ComposeTestCheckFunc(
82+
resource.TestMatchResourceAttr("data.github_rest_api.test", "body", regexp.MustCompile(`\[.*refs/heads/.*\]`)),
83+
)
84+
85+
testCase := func(t *testing.T, mode string) {
86+
resource.Test(t, resource.TestCase{
87+
PreCheck: func() { skipUnlessMode(t, mode) },
88+
Providers: testAccProviders,
89+
Steps: []resource.TestStep{
90+
{
91+
Config: config,
92+
Check: check,
93+
},
94+
},
95+
})
96+
}
97+
98+
t.Run("with an anonymous account", func(t *testing.T) {
99+
t.Skip("anonymous account not supported for this operation")
100+
})
101+
102+
t.Run("with an individual account", func(t *testing.T) {
103+
testCase(t, individual)
104+
})
105+
106+
t.Run("with an organization account", func(t *testing.T) {
107+
testCase(t, organization)
108+
})
109+
110+
})
111+
67112
t.Run("queries an invalid branch without error", func(t *testing.T) {
68113

69114
config := fmt.Sprintf(`
@@ -114,4 +159,41 @@ func TestAccGithubRestApiDataSource(t *testing.T) {
114159
})
115160

116161
})
162+
163+
t.Run("fails for invalid endpoint", func(t *testing.T) {
164+
165+
// 4096 characters is the maximum length for a URL
166+
var endpoint = strings.Repeat("x", 4096)
167+
config := fmt.Sprintf(`
168+
data "github_rest_api" "test" {
169+
endpoint = "/%v"
170+
}
171+
`, endpoint)
172+
173+
testCase := func(t *testing.T, mode string) {
174+
resource.Test(t, resource.TestCase{
175+
PreCheck: func() { skipUnlessMode(t, mode) },
176+
Providers: testAccProviders,
177+
Steps: []resource.TestStep{
178+
{
179+
Config: config,
180+
ExpectError: regexp.MustCompile("Error: GET https://api.github.com/xx.*: 414"),
181+
},
182+
},
183+
})
184+
}
185+
186+
t.Run("with an anonymous account", func(t *testing.T) {
187+
t.Skip("anonymous account not supported for this operation")
188+
})
189+
190+
t.Run("with an individual account", func(t *testing.T) {
191+
testCase(t, individual)
192+
})
193+
194+
t.Run("with an organization account", func(t *testing.T) {
195+
testCase(t, organization)
196+
})
197+
198+
})
117199
}

github/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func Provider() *schema.Provider {
125125
},
126126

127127
ResourcesMap: map[string]*schema.Resource{
128+
"github_enterprise_actions_permissions": resourceGithubActionsEnterprisePermissions(),
128129
"github_actions_environment_secret": resourceGithubActionsEnvironmentSecret(),
129130
"github_actions_environment_variable": resourceGithubActionsEnvironmentVariable(),
130131
"github_actions_organization_oidc_subject_claim_customization_template": resourceGithubActionsOrganizationOIDCSubjectClaimCustomizationTemplate(),
@@ -193,6 +194,7 @@ func Provider() *schema.Provider {
193194
"github_user_invitation_accepter": resourceGithubUserInvitationAccepter(),
194195
"github_user_ssh_key": resourceGithubUserSshKey(),
195196
"github_enterprise_organization": resourceGithubEnterpriseOrganization(),
197+
"github_enterprise_actions_runner_group": resourceGithubActionsEnterpriseRunnerGroup(),
196198
},
197199

198200
DataSourcesMap: map[string]*schema.Resource{

github/repository_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func getAutolinkByKeyPrefix(client *github.Client, owner, repo, keyPrefix string
9898
}
9999
}
100100

101-
return nil, nil
101+
return nil, fmt.Errorf("cannot find autolink reference %s in repo %s/%s", keyPrefix, owner, repo)
102102
}
103103

104104
// listAutolinks returns all autolink references for the given repository.

github/resource_github_actions_organization_permissions.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,14 @@ func resourceGithubActionsOrganizationPermissionsRead(d *schema.ResourceData, me
209209
// only load and fill allowed_actions_config if allowed_actions_config is also set
210210
// in the TF code. (see #2105)
211211
// on initial import there might not be any value in the state, then we have to import the data
212+
// -> but we can only load an existing state if the current config is set to "selected" (see #2182)
212213
allowedActions := d.Get("allowed_actions").(string)
213214
allowedActionsConfig := d.Get("allowed_actions_config").([]interface{})
214-
if (allowedActions == "selected" && len(allowedActionsConfig) > 0) || allowedActions == "" {
215+
216+
serverHasAllowedActionsConfig := actionsPermissions.GetAllowedActions() == "selected"
217+
userWantsAllowedActionsConfig := (allowedActions == "selected" && len(allowedActionsConfig) > 0) || allowedActions == ""
218+
219+
if serverHasAllowedActionsConfig && userWantsAllowedActionsConfig {
215220
actionsAllowed, _, err := client.Actions.GetActionsAllowed(ctx, d.Id())
216221
if err != nil {
217222
return err

github/resource_github_actions_repository_permissions.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,14 @@ func resourceGithubActionsRepositoryPermissionsRead(d *schema.ResourceData, meta
172172
// only load and fill allowed_actions_config if allowed_actions_config is also set
173173
// in the TF code. (see #2105)
174174
// on initial import there might not be any value in the state, then we have to import the data
175+
// -> but we can only load an existing state if the current config is set to "selected" (see #2182)
175176
allowedActions := d.Get("allowed_actions").(string)
176177
allowedActionsConfig := d.Get("allowed_actions_config").([]interface{})
177-
if (allowedActions == "selected" && len(allowedActionsConfig) > 0) || allowedActions == "" {
178+
179+
serverHasAllowedActionsConfig := actionsPermissions.GetAllowedActions() == "selected" && actionsPermissions.GetEnabled()
180+
userWantsAllowedActionsConfig := (allowedActions == "selected" && len(allowedActionsConfig) > 0) || allowedActions == ""
181+
182+
if serverHasAllowedActionsConfig && userWantsAllowedActionsConfig {
178183
actionsAllowed, _, err := client.Repositories.GetActionsAllowed(ctx, owner, repoName)
179184
if err != nil {
180185
return err

0 commit comments

Comments
 (0)