Skip to content

fix: send minimal payload when archiving repositories - #3621

Draft
krukowskid wants to merge 3 commits into
integrations:mainfrom
krukowskid:fix/archive-on-destroy-security-payload
Draft

fix: send minimal payload when archiving repositories#3621
krukowskid wants to merge 3 commits into
integrations:mainfrom
krukowskid:fix/archive-on-destroy-security-payload

Conversation

@krukowskid

Copy link
Copy Markdown

Resolves #3620


Before the change?

When archive_on_destroy was enabled, the delete path built a full repository update payload. Re-sending security_and_analysis caused GitHub to reject the request with HTTP 422 when an organization-enforced security configuration was applied, even though the repository was archived.

After the change?

The archive request contains only {archived:true}. The regression test verifies the exact PATCH payload while security settings are present in Terraform state, and the acceptance test now exercises the archive-on-destroy path.

Pull request checklist

  • Schema migrations have been created if needed (not needed)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (no documentation changes needed)

Does this introduce a breaking change?

  • Yes
  • No

Testing

  • go test ./... -timeout=30s -parallel=4 -skip '^TestAcc' -count=1
  • go build ./...

AI use

This focused change was implemented with GitHub Copilot assistance and reviewed and tested locally before submission.


Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

👋 Hi, and thank you for this contribution!

This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can.

You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions.


🤖 This is an automated message.

@github-actions github-actions Bot added the Type: Bug Something isn't working as documented label Aug 28, 2026
@dekokun

dekokun commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Not a maintainer — helping with review triage, so this is a comment rather than an approving review.

The change looks correct to me. Two things I verified that may save you time:

  • Removing the second acceptance step is right: with archived = true, delete takes the "already archived, nothing to do" early return, so the archive-on-destroy path was never exercised by that test. The update false -> true path is still covered around L184-202 of the same file.
  • Dropping d.Set("archived", true) is safe — it only fed resourceGithubRepositoryObject, and the state is discarded once delete returns.

One suggestion: the acceptance test runs the archive path at teardown but asserts nothing about the outcome. A CheckDestroy asserting GetArchived() == true would cover what #3620 actually reports.

I have not run the acceptance tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@krukowskid

Copy link
Copy Markdown
Author

Thanks for the suggestion. I added a CheckDestroy assertion that fetches the repository after Terraform destroy and verifies that it is archived. The unit test still verifies the exact minimal PATCH payload. Unit tests and the build pass locally.

@anoushaakhourytide

Copy link
Copy Markdown

Hi team. Can we please merge this fix ? Our internal products are dependent on this fix and are enterprise github is suffering due to this.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix addresses the reported failure and includes appropriate regression coverage.

Pull request overview

These provider review instructions are being used. This PR fixes repository archival failures by sending only the required archived field.

Changes:

  • Uses a minimal archive PATCH payload.
  • Adds exact-payload regression coverage.
  • Verifies archive-on-destroy through acceptance testing.
File summaries
File Description
github/resource_github_repository.go Sends the minimal archival payload.
github/resource_github_repository_test.go Adds regression and acceptance coverage.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@deiga

deiga commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Moving this to Draft as #3627 is now high prio

@deiga
deiga marked this pull request as draft September 11, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r/repository Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: 422 error on repository deletion with archive_on_destroy = true and security configuration enforced on all repos

5 participants