@@ -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
414415func 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".
10391045func 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+ }
0 commit comments