@@ -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,15 +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 )
826
- if err != nil {
827
- return err
828
- }
825
+ err = updateVulnerabilityAlerts (d , client , ctx , owner , repoName )
829
826
}
830
827
831
828
if d .HasChange ("visibility" ) {
@@ -957,13 +954,19 @@ func flattenPages(pages *github.Pages) []interface{} {
957
954
return []interface {}{}
958
955
}
959
956
960
- sourceMap := make (map [string ]interface {})
961
- sourceMap ["branch" ] = pages .GetSource ().GetBranch ()
962
- sourceMap ["path" ] = pages .GetSource ().GetPath ()
963
-
964
957
pagesMap := make (map [string ]interface {})
965
- pagesMap ["source" ] = []interface {}{sourceMap }
966
- pagesMap ["build_type" ] = pages .GetBuildType ()
958
+ buildType := pages .GetBuildType ()
959
+ pagesMap ["build_type" ] = buildType
960
+
961
+ if buildType == "legacy" {
962
+ sourceMap := make (map [string ]interface {})
963
+ sourceMap ["branch" ] = pages .GetSource ().GetBranch ()
964
+ sourceMap ["path" ] = pages .GetSource ().GetPath ()
965
+ pagesMap ["source" ] = []interface {}{sourceMap }
966
+ } else {
967
+ pagesMap ["source" ] = nil
968
+ }
969
+
967
970
pagesMap ["url" ] = pages .GetURL ()
968
971
pagesMap ["status" ] = pages .GetStatus ()
969
972
pagesMap ["cname" ] = pages .GetCNAME ()
@@ -1038,7 +1041,8 @@ func flattenSecurityAndAnalysis(securityAndAnalysis *github.SecurityAndAnalysis)
1038
1041
// resourceGithubParseFullName will return "myorg", "myrepo", true when full_name is "myorg/myrepo".
1039
1042
func resourceGithubParseFullName (resourceDataLike interface {
1040
1043
GetOk (string ) (interface {}, bool )
1041
- }) (string , string , bool ) {
1044
+ },
1045
+ ) (string , string , bool ) {
1042
1046
x , ok := resourceDataLike .GetOk ("full_name" )
1043
1047
if ! ok {
1044
1048
return "" , "" , false
@@ -1062,3 +1066,13 @@ func customDiffFunction(_ context.Context, diff *schema.ResourceDiff, v interfac
1062
1066
}
1063
1067
return nil
1064
1068
}
1069
+
1070
+ func updateVulnerabilityAlerts (d * schema.ResourceData , client * github.Client , ctx context.Context , owner , repoName string ) error {
1071
+ updateVulnerabilityAlerts := client .Repositories .DisableVulnerabilityAlerts
1072
+ if vulnerabilityAlerts , ok := d .GetOk ("vulnerability_alerts" ); ok && vulnerabilityAlerts .(bool ) {
1073
+ updateVulnerabilityAlerts = client .Repositories .EnableVulnerabilityAlerts
1074
+ }
1075
+
1076
+ _ , err := updateVulnerabilityAlerts (ctx , owner , repoName )
1077
+ return err
1078
+ }
0 commit comments