Skip to content

Commit 10b2d6a

Browse files
authored
Merge branch 'main' into fix-org-teams-parent
2 parents 11f089b + ca3d01c commit 10b2d6a

14 files changed

Lines changed: 61 additions & 28 deletions

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_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
}

github/resource_github_project_card_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ package github
22

33
import (
44
"fmt"
5-
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
65
"testing"
76

7+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
8+
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1011
)
1112

1213
func TestAccGithubProjectCard(t *testing.T) {
14+
t.Skip("Skipping test as the GitHub REST API no longer supports classic projects")
1315

1416
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1517

1618
t.Run("creates a project card using a note", func(t *testing.T) {
17-
1819
config := fmt.Sprintf(`
1920
2021
resource "github_organization_project" "project" {
@@ -64,11 +65,9 @@ func TestAccGithubProjectCard(t *testing.T) {
6465
t.Run("with an organization account", func(t *testing.T) {
6566
testCase(t, organization)
6667
})
67-
6868
})
6969

7070
t.Run("creates a project card using an issue", func(t *testing.T) {
71-
7271
config := fmt.Sprintf(`
7372
7473
resource "github_repository" "test" {
@@ -97,7 +96,7 @@ func TestAccGithubProjectCard(t *testing.T) {
9796
resource "github_project_card" "test" {
9897
column_id = github_project_column.test.column_id
9998
content_id = github_issue.test.issue_id
100-
content_type = "Issue"
99+
content_type = "Issue"
101100
}
102101
103102
`, randomID)
@@ -141,6 +140,5 @@ func TestAccGithubProjectCard(t *testing.T) {
141140
t.Run("with an organization account", func(t *testing.T) {
142141
testCase(t, organization)
143142
})
144-
145143
})
146144
}

github/resource_github_project_column.go

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

1414
func resourceGithubProjectColumn() *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: resourceGithubProjectColumnCreate,
1719
Read: resourceGithubProjectColumnRead,
1820
Update: resourceGithubProjectColumnUpdate,

github/resource_github_project_column_test.go

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

1414
func TestAccGithubProjectColumn_basic(t *testing.T) {
15+
t.Skip("Skipping test as the GitHub REST API no longer supports classic projects")
16+
1517
if err := testAccCheckOrganization(); err != nil {
1618
t.Skipf("Skipping because %s.", err.Error())
1719
}
@@ -107,7 +109,6 @@ type testAccGithubProjectColumnExpectedAttributes struct {
107109

108110
func testAccCheckGithubProjectColumnAttributes(column *github.ProjectColumn, want *testAccGithubProjectColumnExpectedAttributes) resource.TestCheckFunc {
109111
return func(s *terraform.State) error {
110-
111112
if name := column.GetName(); name != want.Name {
112113
return fmt.Errorf("got project column %q; want %q", name, want.Name)
113114
}

github/resource_github_repository.go

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ func resourceGithubRepository() *schema.Resource {
320320
"vulnerability_alerts": {
321321
Type: schema.TypeBool,
322322
Optional: true,
323+
Computed: true,
323324
Description: "Set to 'true' to enable security alerts for vulnerable dependencies. Enabling requires alerts to be enabled on the owner level. (Note for importing: GitHub enables the alerts on public repos but disables them on private repos by default). Note that vulnerability alerts have not been successfully tested on any GitHub Enterprise instance and may be unavailable in those settings.",
324325
},
325326
"ignore_vulnerability_alerts_during_read": {
@@ -412,7 +413,6 @@ func resourceGithubRepository() *schema.Resource {
412413
}
413414

414415
func calculateVisibility(d *schema.ResourceData) string {
415-
416416
if value, ok := d.GetOk("visibility"); ok {
417417
return value.(string)
418418
}
@@ -619,6 +619,11 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er
619619
}
620620
}
621621

622+
err := updateVulnerabilityAlerts(d, client, ctx, owner, repoName)
623+
if err != nil {
624+
return err
625+
}
626+
622627
return resourceGithubRepositoryUpdate(d, meta)
623628
}
624629

@@ -817,12 +822,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er
817822
}
818823

819824
if d.HasChange("vulnerability_alerts") {
820-
updateVulnerabilityAlerts := client.Repositories.DisableVulnerabilityAlerts
821-
if vulnerabilityAlerts, ok := d.GetOk("vulnerability_alerts"); ok && vulnerabilityAlerts.(bool) {
822-
updateVulnerabilityAlerts = client.Repositories.EnableVulnerabilityAlerts
823-
}
824-
825-
_, err = updateVulnerabilityAlerts(ctx, owner, repoName)
825+
err = updateVulnerabilityAlerts(d, client, ctx, owner, repoName)
826826
if err != nil {
827827
return err
828828
}
@@ -957,13 +957,19 @@ func flattenPages(pages *github.Pages) []interface{} {
957957
return []interface{}{}
958958
}
959959

960-
sourceMap := make(map[string]interface{})
961-
sourceMap["branch"] = pages.GetSource().GetBranch()
962-
sourceMap["path"] = pages.GetSource().GetPath()
963-
964960
pagesMap := make(map[string]interface{})
965-
pagesMap["source"] = []interface{}{sourceMap}
966-
pagesMap["build_type"] = pages.GetBuildType()
961+
buildType := pages.GetBuildType()
962+
pagesMap["build_type"] = buildType
963+
964+
if buildType == "legacy" {
965+
sourceMap := make(map[string]interface{})
966+
sourceMap["branch"] = pages.GetSource().GetBranch()
967+
sourceMap["path"] = pages.GetSource().GetPath()
968+
pagesMap["source"] = []interface{}{sourceMap}
969+
} else {
970+
pagesMap["source"] = nil
971+
}
972+
967973
pagesMap["url"] = pages.GetURL()
968974
pagesMap["status"] = pages.GetStatus()
969975
pagesMap["cname"] = pages.GetCNAME()
@@ -1038,7 +1044,8 @@ func flattenSecurityAndAnalysis(securityAndAnalysis *github.SecurityAndAnalysis)
10381044
// resourceGithubParseFullName will return "myorg", "myrepo", true when full_name is "myorg/myrepo".
10391045
func resourceGithubParseFullName(resourceDataLike interface {
10401046
GetOk(string) (interface{}, bool)
1041-
}) (string, string, bool) {
1047+
},
1048+
) (string, string, bool) {
10421049
x, ok := resourceDataLike.GetOk("full_name")
10431050
if !ok {
10441051
return "", "", false
@@ -1062,3 +1069,13 @@ func customDiffFunction(_ context.Context, diff *schema.ResourceDiff, v interfac
10621069
}
10631070
return nil
10641071
}
1072+
1073+
func updateVulnerabilityAlerts(d *schema.ResourceData, client *github.Client, ctx context.Context, owner, repoName string) error {
1074+
updateVulnerabilityAlerts := client.Repositories.DisableVulnerabilityAlerts
1075+
if vulnerabilityAlerts, ok := d.GetOk("vulnerability_alerts"); ok && vulnerabilityAlerts.(bool) {
1076+
updateVulnerabilityAlerts = client.Repositories.EnableVulnerabilityAlerts
1077+
}
1078+
1079+
_, err := updateVulnerabilityAlerts(ctx, owner, repoName)
1080+
return err
1081+
}

github/resource_github_repository_project.go

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

1515
func resourceGithubRepositoryProject() *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: resourceGithubRepositoryProjectCreate,
1820
Read: resourceGithubRepositoryProjectRead,
1921
Update: resourceGithubRepositoryProjectUpdate,

github/resource_github_repository_project_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
)
1111

1212
func TestAccGithubRepositoryProject(t *testing.T) {
13+
t.Skip("Skipping test as the GitHub REST API no longer supports classic projects")
1314

1415
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1516

1617
t.Run("creates a repository project", func(t *testing.T) {
17-
1818
config := fmt.Sprintf(`
1919
2020
resource "github_repository" "test" {
@@ -60,6 +60,5 @@ func TestAccGithubRepositoryProject(t *testing.T) {
6060
t.Run("with an organization account", func(t *testing.T) {
6161
testCase(t, organization)
6262
})
63-
6463
})
6564
}

0 commit comments

Comments
 (0)