Skip to content

Commit 7de8d48

Browse files
committed
Update patch to prevent commit signoff is enforced error
1 parent 93bdfa1 commit 7de8d48

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
Prevent 422 Commit signoff is enforced by the organization and cannot be disabled.
22

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".
97

108
For more information: https://github.com/integrations/terraform-provider-github/issues/2077
119

1210
diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go
13-
index f28cc4c6..aa6184c0 100644
11+
index f28cc4c6..6762e628 100644
1412
--- a/github/resource_github_repository.go
1513
+++ 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())
1917

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+
+ }
2630
+ }
2731
+
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

Comments
 (0)