@@ -320,6 +320,7 @@ func resourceGithubRepository() *schema.Resource {
320
320
"vulnerability_alerts" : {
321
321
Type : schema .TypeBool ,
322
322
Optional : true ,
323
+ Computed : true ,
323
324
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." ,
324
325
},
325
326
"ignore_vulnerability_alerts_during_read" : {
@@ -412,7 +413,6 @@ func resourceGithubRepository() *schema.Resource {
412
413
}
413
414
414
415
func calculateVisibility (d * schema.ResourceData ) string {
415
-
416
416
if value , ok := d .GetOk ("visibility" ); ok {
417
417
return value .(string )
418
418
}
@@ -619,6 +619,11 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er
619
619
}
620
620
}
621
621
622
+ err := updateVulnerabilityAlerts (d , client , ctx , owner , repoName )
623
+ if err != nil {
624
+ return err
625
+ }
626
+
622
627
return resourceGithubRepositoryUpdate (d , meta )
623
628
}
624
629
@@ -817,12 +822,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er
817
822
}
818
823
819
824
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 )
826
826
if err != nil {
827
827
return err
828
828
}
@@ -957,13 +957,19 @@ func flattenPages(pages *github.Pages) []interface{} {
957
957
return []interface {}{}
958
958
}
959
959
960
- sourceMap := make (map [string ]interface {})
961
- sourceMap ["branch" ] = pages .GetSource ().GetBranch ()
962
- sourceMap ["path" ] = pages .GetSource ().GetPath ()
963
-
964
960
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
+
967
973
pagesMap ["url" ] = pages .GetURL ()
968
974
pagesMap ["status" ] = pages .GetStatus ()
969
975
pagesMap ["cname" ] = pages .GetCNAME ()
@@ -1038,7 +1044,8 @@ func flattenSecurityAndAnalysis(securityAndAnalysis *github.SecurityAndAnalysis)
1038
1044
// resourceGithubParseFullName will return "myorg", "myrepo", true when full_name is "myorg/myrepo".
1039
1045
func resourceGithubParseFullName (resourceDataLike interface {
1040
1046
GetOk (string ) (interface {}, bool )
1041
- }) (string , string , bool ) {
1047
+ },
1048
+ ) (string , string , bool ) {
1042
1049
x , ok := resourceDataLike .GetOk ("full_name" )
1043
1050
if ! ok {
1044
1051
return "" , "" , false
@@ -1062,3 +1069,13 @@ func customDiffFunction(_ context.Context, diff *schema.ResourceDiff, v interfac
1062
1069
}
1063
1070
return nil
1064
1071
}
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
+ }
0 commit comments