|
1 | 1 | Prevent 422 Commit signoff is enforced by the organization and cannot be disabled. |
2 | 2 |
|
3 | | -This patch fixes a bug in the GitHub API 2022-11-28 version where updating a repository |
4 | | -with web_commit_signoff_required=true throws a 422 error when the field is already true. |
5 | | - |
6 | | -It checks if the web_commit_signoff_required field has actually changed during a |
7 | | -repository update. If the field hasn't changed and is already true, it's removed from |
8 | | -the update request to avoid the API error. |
| 3 | +This patch fixes a bug in the GitHub API 2022-11-28 version when updating a repository |
| 4 | +within an organization that has "Require sign off on web-based commits" enabled. |
| 5 | +When trying to update the repository with `web_commit_signoff_required` field, the API |
| 6 | +returns a 422 error: "Commit signoff is enforced by the organization and cannot be disabled". |
9 | 7 |
|
10 | 8 | For more information: https://github.com/integrations/terraform-provider-github/issues/2077 |
11 | 9 |
|
12 | 10 | diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go |
13 | | -index f28cc4c6..aa6184c0 100644 |
| 11 | +index f28cc4c6..6762e628 100644 |
14 | 12 | --- a/github/resource_github_repository.go |
15 | 13 | +++ b/github/resource_github_repository.go |
16 | | -@@ -765,6 +765,14 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er |
17 | | - repoReq.DefaultBranch = github.String(d.Get("default_branch").(string)) |
18 | | - } |
| 14 | +@@ -769,6 +769,20 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er |
| 15 | + owner := meta.(*Owner).name |
| 16 | + ctx := context.WithValue(context.Background(), ctxId, d.Id()) |
19 | 17 |
|
20 | | -+ // There's a bug in the GitHub 2022-11-28 version, that throws a 422 error |
21 | | -+ // whenever the `web_commit_signoff_required` is set to true, even when it |
22 | | -+ // is already true. |
23 | | -+ if !d.HasChange("web_commit_signoff_required") && d.Get("web_commit_signoff_required").(bool) { |
24 | | -+ // remove the field from the request |
25 | | -+ repoReq.WebCommitSignoffRequired = nil |
| 18 | ++ // When the organization has "Require sign off on web-based commits" enabled, |
| 19 | ++ // the API doesn't allow you to send `web_commit_signoff_required` in order to |
| 20 | ++ // update the repository with this field or it will throw a 422 error. |
| 21 | ++ // As a workaround, we check if the organization requires it, and if so, |
| 22 | ++ // we remove the field from the request. |
| 23 | ++ if d.HasChange("web_commit_signoff_required") && meta.(*Owner).IsOrganization { |
| 24 | ++ organization, _, err := client.Organizations.Get(ctx, owner) |
| 25 | ++ if err == nil { |
| 26 | ++ if organization != nil && organization.GetWebCommitSignoffRequired() { |
| 27 | ++ repoReq.WebCommitSignoffRequired = nil |
| 28 | ++ } |
| 29 | ++ } |
26 | 30 | + } |
27 | 31 | + |
28 | | - repoName := d.Id() |
29 | | - owner := meta.(*Owner).name |
30 | | - ctx := context.WithValue(context.Background(), ctxId, d.Id()) |
| 32 | + repo, _, err := client.Repositories.Edit(ctx, owner, repoName, repoReq) |
| 33 | + if err != nil { |
| 34 | + return err |
0 commit comments