From d9c5e4347fa3ff6eb466592e71235a5961b3d1e4 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Thu, 22 Apr 2021 13:52:01 -0700 Subject: [PATCH 1/3] Initial commit of setting vulnerability_alerts --- github/resource_github_repository.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 71aeafd013..f2924e0366 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -549,7 +549,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er } } - if !d.IsNewResource() && d.HasChange("vulnerability_alerts") { + if d.HasChange("vulnerability_alerts") { updateVulnerabilityAlerts := client.Repositories.DisableVulnerabilityAlerts if vulnerabilityAlerts, ok := d.GetOk("vulnerability_alerts"); ok && vulnerabilityAlerts.(bool) { updateVulnerabilityAlerts = client.Repositories.EnableVulnerabilityAlerts @@ -564,7 +564,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er if d.HasChange("visibility") { o, n := d.GetChange("visibility") repoReq.Visibility = github.String(n.(string)) - log.Printf("[DEBUG] <<<<<<<<<<<<< Updating repository visibility from %s to %s", o, n) + log.Printf("[DEBUG] Updating repository visibility from %s to %s", o, n) _, _, err = client.Repositories.Edit(ctx, owner, repoName, repoReq) if err != nil { if !strings.Contains(err.Error(), "422 Visibility is already private") { @@ -572,13 +572,13 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er } } } else { - log.Printf("[DEBUG] <<<<<<<<<< no visibility update required. visibility: %s", d.Get("visibility")) + log.Printf("[DEBUG] No visibility update required. visibility: %s", d.Get("visibility")) } if d.HasChange("private") { o, n := d.GetChange("private") repoReq.Private = github.Bool(n.(bool)) - log.Printf("[DEBUG] <<<<<<<<<<<<< Updating repository privacy from %v to %v", o, n) + log.Printf("[DEBUG] Updating repository privacy from %v to %v", o, n) _, _, err = client.Repositories.Edit(ctx, owner, repoName, repoReq) if err != nil { if !strings.Contains(err.Error(), "422 Privacy is already set") { From 23e455740615b8f506c219fd3e483003b7138361 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Sun, 25 Apr 2021 01:19:59 -0700 Subject: [PATCH 2/3] Remove vulnerability alerts handling from create and keep on update --- github/resource_github_repository.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index f2924e0366..fd06d9e6d4 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -369,24 +369,6 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er } } - var alerts bool - if a, ok := d.GetOk("vulnerability_alerts"); ok { - alerts = a.(bool) - } - - var createVulnerabilityAlerts func(context.Context, string, string) (*github.Response, error) - if isPrivate && alerts { - createVulnerabilityAlerts = client.Repositories.EnableVulnerabilityAlerts - } else if !isPrivate && !alerts { - createVulnerabilityAlerts = client.Repositories.DisableVulnerabilityAlerts - } - if createVulnerabilityAlerts != nil { - _, err := createVulnerabilityAlerts(ctx, owner, repoName) - if err != nil { - return err - } - } - pages := expandPages(d.Get("pages").([]interface{})) if pages != nil { _, _, err := client.Repositories.EnablePages(ctx, owner, repoName, pages) From b6b95b9a38cc5e95e8125d14beee385228c8940b Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Thu, 22 Jul 2021 13:35:26 -0700 Subject: [PATCH 3/3] Add note for unsuccessful enterprise vulnerability alert setting --- website/docs/r/repository.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index 68c5f86255..60dccfb4f8 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -99,7 +99,7 @@ initial repository creation and create the target branch inside of the repositor * `template` - (Optional) Use a template repository to create this resource. See [Template Repositories](#template-repositories) below for details. -* `vulnerability_alerts` (Optional) - 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.) See [GitHub Documentation](https://help.github.com/en/github/managing-security-vulnerabilities/about-security-alerts-for-vulnerable-dependencies) for details. +* `vulnerability_alerts` (Optional) - 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.) See [GitHub Documentation](https://help.github.com/en/github/managing-security-vulnerabilities/about-security-alerts-for-vulnerable-dependencies) for details. Note that vulnerability alerts have not been successfully tested on any GitHub Enterprise instance and may be unavailable in those settings. ### GitHub Pages Configuration