Skip to content

Commit 81a9234

Browse files
committed
Add error handling to ignore 422 response
In the case of `vulnerability_alerts = false` and the message indicates control from parent Org/Enterprise Signed-off-by: Timo Sand <[email protected]>
1 parent 4cd8d1c commit 81a9234

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

github/resource_github_repository.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,11 +1243,17 @@ func resourceGithubParseFullName(resourceDataLike interface {
12431243
}
12441244

12451245
func updateVulnerabilityAlerts(d *schema.ResourceData, client *github.Client, ctx context.Context, owner, repoName string) error {
1246-
updateVulnerabilityAlerts := client.Repositories.DisableVulnerabilityAlerts
1247-
if vulnerabilityAlerts, ok := d.GetOk("vulnerability_alerts"); ok && vulnerabilityAlerts.(bool) {
1248-
updateVulnerabilityAlerts = client.Repositories.EnableVulnerabilityAlerts
1246+
updateVulnerabilityAlertsSDK := client.Repositories.DisableVulnerabilityAlerts
1247+
vulnerabilityAlerts, ok := d.GetOk("vulnerability_alerts")
1248+
if ok && vulnerabilityAlerts.(bool) {
1249+
updateVulnerabilityAlertsSDK = client.Repositories.EnableVulnerabilityAlerts
12491250
}
12501251

1251-
_, err := updateVulnerabilityAlerts(ctx, owner, repoName)
1252+
resp, err := updateVulnerabilityAlertsSDK(ctx, owner, repoName)
1253+
if err != nil {
1254+
if resp.StatusCode == http.StatusUnprocessableEntity && strings.Contains(err.Error(), "An enforced security configuration prevented modifying") && !ok {
1255+
return nil // An Organization or Enterprise policy is preventing the change
1256+
}
1257+
}
12521258
return err
12531259
}

0 commit comments

Comments
 (0)