Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions github/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ type Config struct {
}

type Owner struct {
name string
id int64
v3client *github.Client
v4client *githubv4.Client
StopContext context.Context
IsOrganization bool
name string
id int64
v3client *github.Client
v4client *githubv4.Client
StopContext context.Context
IsOrganization bool
IsWebCommitSignoffRequired bool
}

// GHECDataResidencyMatch is a regex to match a GitHub Enterprise Cloud data residency URL:
Expand Down Expand Up @@ -130,6 +131,7 @@ func (c *Config) ConfigureOwner(owner *Owner) (*Owner, error) {
if remoteOrg != nil {
owner.id = remoteOrg.GetID()
owner.IsOrganization = true
owner.IsWebCommitSignoffRequired = remoteOrg.GetWebCommitSignoffRequired()
}
}
}
Expand Down
22 changes: 8 additions & 14 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,18 +867,11 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta any) error {
owner := meta.(*Owner).name
ctx := context.WithValue(context.Background(), ctxId, d.Id())

// When the organization has "Require sign off on web-based commits" enabled,
// the API doesn't allow you to send `web_commit_signoff_required` in order to
// update the repository with this field or it will throw a 422 error.
// As a workaround, we check if the organization requires it, and if so,
// we remove the field from the request.
if d.HasChange("web_commit_signoff_required") && meta.(*Owner).IsOrganization {
organization, _, err := client.Organizations.Get(ctx, owner)
if err == nil {
if organization != nil && organization.GetWebCommitSignoffRequired() {
repoReq.WebCommitSignoffRequired = nil
}
}
// When the organization has "Require contributors to sign off on web-based commits" enabled,
// the API doesn't allow you to send `web_commit_signoff_required` or it returns a 422 error.
// As a workaround, check if the organization requires it, and if so, remove it from the request.
if meta.(*Owner).IsOrganization && meta.(*Owner).IsWebCommitSignoffRequired {
Comment thread
steveteuber marked this conversation as resolved.
repoReq.WebCommitSignoffRequired = nil
}

repo, _, err := client.Repositories.Edit(ctx, owner, repoName, repoReq)
Expand Down Expand Up @@ -982,8 +975,9 @@ func resourceGithubRepositoryDelete(d *schema.ResourceData, meta any) error {
return err
}
repoReq := resourceGithubRepositoryObject(d)
// Always remove `web_commit_signoff_required` when archiving, to avoid 422 error
repoReq.WebCommitSignoffRequired = nil
if meta.(*Owner).IsOrganization && meta.(*Owner).IsWebCommitSignoffRequired {
Comment thread
steveteuber marked this conversation as resolved.
repoReq.WebCommitSignoffRequired = nil
}
log.Printf("[DEBUG] Archiving repository on delete: %s/%s", owner, repoName)
_, _, err := client.Repositories.Edit(ctx, owner, repoName, repoReq)
return err
Expand Down