Skip to content

Commit 85782b6

Browse files
authored
Merge branch 'main' into fix/deleteRepositoryFIle
2 parents ad479a3 + d38b99c commit 85782b6

112 files changed

Lines changed: 6130 additions & 1181 deletions

File tree

Some content is hidden

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

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ jobs:
2828
cache: true
2929

3030
- name: Import GPG key
31-
uses: crazy-max/ghaction-import-gpg@cb9bde2e2525e640591a934b1fd28eef1dcaf5e5 # v6.2.0
31+
uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0
3232
id: import_gpg
3333
with:
3434
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
3535
passphrase: ${{ secrets.PASSPHRASE }}
3636

3737
- name: Run GoReleaser
38-
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0
38+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
3939
with:
4040
args: release --clean
4141
version: latest

.markdownlint.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MD013: false
2+
MD024:
3+
siblings_only: true
4+
MD028: false

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

GNUmakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ lint:
2424
golangci-lint run ./...
2525

2626
test:
27-
go test ./...
27+
CGO_ENABLED=0 go test ./...
2828
# commenting this out for release tooling, please run testacc instead
2929

3030
testacc: fmtcheck
31-
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
31+
TF_ACC=1 CGO_ENABLED=0 go test $(TEST) -v $(TESTARGS) -timeout 120m
3232

3333
test-compile:
3434
@if [ "$(TEST)" = "./..." ]; then \
3535
echo "ERROR: Set TEST to a specific package. For example,"; \
3636
echo " make test-compile TEST=./$(PKG_NAME)"; \
3737
exit 1; \
3838
fi
39-
go test -c $(TEST) $(TESTARGS)
39+
CGO_ENABLED=0 go test -c $(TEST) $(TESTARGS)
4040

4141
vet:
4242
@echo "go vet ."

examples/secret-drifting/main.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
provider "github" {
2+
}
3+
4+
terraform {
5+
required_providers {
6+
github = {
7+
source = "integrations/github"
8+
}
9+
}
10+
}
11+
12+
resource "github_actions_organization_secret" "plaintext_secret" {
13+
secret_name = "test_plaintext_secret"
14+
plaintext_value = "123"
15+
visibility = "private"
16+
}
17+
18+
resource "github_actions_organization_secret" "encrypted_secret" {
19+
secret_name = "test_encrypted_secret"
20+
plaintext_value = "123"
21+
visibility = "private"
22+
destroy_on_drift = false
23+
}

github/data_source_github_issue_labels.go

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package github
22

33
import (
44
"context"
5-
"fmt"
65

7-
"github.com/google/go-github/v66/github"
86
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
97
)
108

@@ -49,59 +47,19 @@ func dataSourceGithubIssueLabelsRead(d *schema.ResourceData, meta interface{}) e
4947
client := meta.(*Owner).v3client
5048
owner := meta.(*Owner).name
5149
repository := d.Get("repository").(string)
52-
5350
ctx := context.Background()
54-
opts := &github.ListOptions{
55-
PerPage: maxPerPage,
56-
}
5751

5852
d.SetId(repository)
5953

60-
allLabels := make([]interface{}, 0)
61-
for {
62-
labels, resp, err := client.Issues.ListLabels(ctx, owner, repository, opts)
63-
if err != nil {
64-
return err
65-
}
66-
67-
result, err := flattenLabels(labels)
68-
if err != nil {
69-
return fmt.Errorf("unable to flatten GitHub Labels (Owner: %q/Repository: %q) : %+v", owner, repository, err)
70-
}
71-
72-
allLabels = append(allLabels, result...)
73-
74-
if resp.NextPage == 0 {
75-
break
76-
}
77-
opts.Page = resp.NextPage
54+
labels, err := listLabels(client, ctx, owner, repository)
55+
if err != nil {
56+
return err
7857
}
7958

80-
err := d.Set("labels", allLabels)
59+
err = d.Set("labels", flattenLabels(labels))
8160
if err != nil {
8261
return err
8362
}
8463

8564
return nil
8665
}
87-
88-
func flattenLabels(labels []*github.Label) ([]interface{}, error) {
89-
if labels == nil {
90-
return make([]interface{}, 0), nil
91-
}
92-
93-
results := make([]interface{}, 0)
94-
95-
for _, l := range labels {
96-
result := make(map[string]interface{})
97-
98-
result["name"] = l.GetName()
99-
result["color"] = l.GetColor()
100-
result["description"] = l.GetDescription()
101-
result["url"] = l.GetURL()
102-
103-
results = append(results, result)
104-
}
105-
106-
return results, nil
107-
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package github
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
)
9+
10+
func dataSourceGithubOrganizationCustomProperties() *schema.Resource {
11+
return &schema.Resource{
12+
Read: dataSourceGithubOrganizationCustomPropertiesRead,
13+
14+
Schema: map[string]*schema.Schema{
15+
"property_name": {
16+
Type: schema.TypeString,
17+
Required: true,
18+
},
19+
"value_type": {
20+
Type: schema.TypeString,
21+
Optional: true,
22+
},
23+
"required": {
24+
Type: schema.TypeBool,
25+
Optional: true,
26+
},
27+
"default_value": {
28+
Type: schema.TypeString,
29+
Optional: true,
30+
Computed: true,
31+
},
32+
"description": {
33+
Type: schema.TypeString,
34+
Optional: true,
35+
Computed: true,
36+
},
37+
"allowed_values": {
38+
Type: schema.TypeList,
39+
Optional: true,
40+
Computed: true,
41+
Elem: &schema.Schema{Type: schema.TypeString},
42+
},
43+
},
44+
}
45+
}
46+
47+
func dataSourceGithubOrganizationCustomPropertiesRead(d *schema.ResourceData, meta interface{}) error {
48+
client := meta.(*Owner).v3client
49+
ctx := context.Background()
50+
orgName := meta.(*Owner).name
51+
52+
err := checkOrganization(meta)
53+
if err != nil {
54+
return err
55+
}
56+
57+
propertyAttributes, _, err := client.Organizations.GetCustomProperty(ctx, orgName, d.Get("property_name").(string))
58+
if err != nil {
59+
return fmt.Errorf("error querying GitHub custom properties %s: %s", orgName, err)
60+
}
61+
62+
d.SetId("org-custom-properties")
63+
d.Set("allowed_values", propertyAttributes.AllowedValues)
64+
d.Set("default_value", propertyAttributes.DefaultValue)
65+
d.Set("description", propertyAttributes.Description)
66+
d.Set("property_name", propertyAttributes.PropertyName)
67+
d.Set("required", propertyAttributes.Required)
68+
d.Set("value_type", propertyAttributes.ValueType)
69+
70+
return nil
71+
}

github/data_source_github_organization_custom_role.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212

1313
func dataSourceGithubOrganizationCustomRole() *schema.Resource {
1414
return &schema.Resource{
15-
Read: dataSourceGithubOrganizationCustomRoleRead,
15+
DeprecationMessage: "This data source is deprecated and will be removed in a future release. Use the github_organization_repository_role data source instead.",
1616

17+
Read: dataSourceGithubOrganizationCustomRoleRead,
1718
Schema: map[string]*schema.Schema{
1819
"name": {
1920
Type: schema.TypeString,
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package github
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"strconv"
7+
8+
"github.com/google/go-github/v66/github"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
)
11+
12+
func dataSourceGithubOrganizationRepositoryRole() *schema.Resource {
13+
return &schema.Resource{
14+
Description: "Lookup a custom organization repository role.",
15+
16+
Read: dataSourceGithubOrganizationRepositoryRoleRead,
17+
18+
Schema: map[string]*schema.Schema{
19+
"role_id": {
20+
Description: "The ID of the organization repository role.",
21+
Type: schema.TypeInt,
22+
Required: true,
23+
},
24+
"name": {
25+
Description: "The name of the organization repository role.",
26+
Type: schema.TypeString,
27+
Computed: true,
28+
},
29+
"description": {
30+
Description: "The description of the organization repository role.",
31+
Type: schema.TypeString,
32+
Computed: true,
33+
},
34+
"base_role": {
35+
Description: "The system role from which this role inherits permissions.",
36+
Type: schema.TypeString,
37+
Computed: true,
38+
},
39+
"permissions": {
40+
Description: "The permissions included in this role.",
41+
Type: schema.TypeSet,
42+
Elem: &schema.Schema{Type: schema.TypeString},
43+
Computed: true,
44+
},
45+
},
46+
}
47+
}
48+
49+
func dataSourceGithubOrganizationRepositoryRoleRead(d *schema.ResourceData, meta interface{}) error {
50+
client := meta.(*Owner).v3client
51+
ctx := context.Background()
52+
orgName := meta.(*Owner).name
53+
54+
roleId := int64(d.Get("role_id").(int))
55+
56+
// TODO: Use this code when go-github adds the functionality to get a custom repo role
57+
// role, _, err := client.Organizations.GetCustomRepoRole(ctx, orgName, roleId)
58+
// if err != nil {
59+
// return err
60+
// }
61+
62+
roles, _, err := client.Organizations.ListCustomRepoRoles(ctx, orgName)
63+
if err != nil {
64+
return err
65+
}
66+
67+
var role *github.CustomRepoRoles
68+
for _, r := range roles.CustomRepoRoles {
69+
if r.GetID() == roleId {
70+
role = r
71+
break
72+
}
73+
}
74+
if role == nil {
75+
return fmt.Errorf("custom organization repo role with ID %d not found", roleId)
76+
}
77+
78+
r := map[string]any{
79+
"role_id": role.GetID(),
80+
"name": role.GetName(),
81+
"description": role.GetDescription(),
82+
"base_role": role.GetBaseRole(),
83+
"permissions": role.Permissions,
84+
}
85+
86+
d.SetId(strconv.FormatInt(role.GetID(), 10))
87+
88+
for k, v := range r {
89+
if err := d.Set(k, v); err != nil {
90+
return err
91+
}
92+
}
93+
94+
return nil
95+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package github
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
)
10+
11+
func TestAccGithubOrganizationRepositoryRoleDataSource(t *testing.T) {
12+
t.Run("queries an organization repository role", func(t *testing.T) {
13+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
14+
roleName := fmt.Sprintf(`tf-acc-test-%s`, randomID)
15+
16+
config := fmt.Sprintf(`
17+
resource "github_organization_repository_role" "test" {
18+
name = "%s"
19+
description = "Test role description"
20+
base_role = "read"
21+
permissions = [
22+
"reopen_issue",
23+
"reopen_pull_request",
24+
]
25+
}
26+
27+
data "github_organization_repository_role" "test" {
28+
role_id = github_organization_repository_role.test.role_id
29+
30+
depends_on = [ github_organization_repository_role.test ]
31+
}
32+
`, roleName)
33+
34+
resource.Test(t, resource.TestCase{
35+
PreCheck: func() { skipUnlessMode(t, enterprise) },
36+
Providers: testAccProviders,
37+
Steps: []resource.TestStep{
38+
{
39+
Config: config,
40+
Check: resource.ComposeTestCheckFunc(
41+
resource.TestCheckResourceAttrPair("data.github_organization_repository_role.test", "name", "github_organization_repository_role.test", "name"),
42+
resource.TestCheckResourceAttrPair("data.github_organization_repository_role.test", "description", "github_organization_repository_role.test", "description"),
43+
resource.TestCheckResourceAttrPair("data.github_organization_repository_role.test", "base_role", "github_organization_repository_role.test", "base_role"),
44+
resource.TestCheckResourceAttrPair("data.github_organization_repository_role.test", "permissions.#", "github_organization_repository_role.test", "permissions.#"),
45+
),
46+
},
47+
},
48+
})
49+
})
50+
}

0 commit comments

Comments
 (0)