Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9d729e8

Browse files
committedDec 5, 2024··
fix: Fixed repository resource churn
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
1 parent 1c11053 commit 9d729e8

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed
 

‎github/resource_github_repository.go

+31-17
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,15 +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)
826-
if err != nil {
827-
return err
828-
}
825+
err = updateVulnerabilityAlerts(d, client, ctx, owner, repoName)
829826
}
830827

831828
if d.HasChange("visibility") {
@@ -957,13 +954,19 @@ func flattenPages(pages *github.Pages) []interface{} {
957954
return []interface{}{}
958955
}
959956

960-
sourceMap := make(map[string]interface{})
961-
sourceMap["branch"] = pages.GetSource().GetBranch()
962-
sourceMap["path"] = pages.GetSource().GetPath()
963-
964957
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+
967970
pagesMap["url"] = pages.GetURL()
968971
pagesMap["status"] = pages.GetStatus()
969972
pagesMap["cname"] = pages.GetCNAME()
@@ -1038,7 +1041,8 @@ func flattenSecurityAndAnalysis(securityAndAnalysis *github.SecurityAndAnalysis)
10381041
// resourceGithubParseFullName will return "myorg", "myrepo", true when full_name is "myorg/myrepo".
10391042
func resourceGithubParseFullName(resourceDataLike interface {
10401043
GetOk(string) (interface{}, bool)
1041-
}) (string, string, bool) {
1044+
},
1045+
) (string, string, bool) {
10421046
x, ok := resourceDataLike.GetOk("full_name")
10431047
if !ok {
10441048
return "", "", false
@@ -1062,3 +1066,13 @@ func customDiffFunction(_ context.Context, diff *schema.ResourceDiff, v interfac
10621066
}
10631067
return nil
10641068
}
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

Comments
 (0)
Please sign in to comment.