Skip to content

Conversation

@nickfloyd
Copy link
Contributor

Resolves #737


Before the change?

  • When users archive a GitHub repository, the provider attempts to delete managed resources (like issue labels -as in the case above) during terraform destroy or resource removal, but fails with a 403 error because archived repositories are read-only.

After the change?

  • Now errors are handled properly for operations on archived repos

Pull request checklist

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

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@nickfloyd nickfloyd self-assigned this Oct 28, 2025
@nickfloyd nickfloyd added Type: Bug Something isn't working as documented Type: Feature New feature or request labels Oct 28, 2025
@nickfloyd nickfloyd requested a review from Copilot October 28, 2025 21:34
@nickfloyd
Copy link
Contributor Author

cc: @gallowaystorm

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds handling for archived repositories in Terraform deletion operations to prevent API errors. When repositories are archived, GitHub makes them read-only, causing deletion operations to fail with 403 errors. The changes gracefully handle these errors by detecting archived repository status and logging informational messages instead of returning errors.

Key changes:

  • Added utility functions to detect and handle archived repository errors
  • Updated resource deletion methods for repository files and issue labels to gracefully skip deletion on archived repositories
  • Added comprehensive test coverage for archived repository scenarios
  • Updated documentation to inform users about the new behavior

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
github/repository_utils.go Adds utility functions to detect archived repository errors and handle deletion gracefully
github/resource_github_repository_file.go Updates file deletion to use new archived repository handler
github/resource_github_issue_label.go Updates label deletion to use new archived repository handler
github/resource_github_issue_labels.go Updates bulk label deletion with inline archived repository error handling
github/resource_github_repository_file_test.go Adds test for file deletion on archived repositories
github/resource_github_issue_label_test.go Adds test for label deletion on archived repositories
github/resource_github_issue_labels_test.go Adds test for bulk label deletion on archived repositories
website/docs/r/repository_file.html.markdown Documents new archived repository deletion behavior
website/docs/r/issue_label.html.markdown Documents new archived repository deletion behavior
website/docs/r/issue_labels.html.markdown Documents new archived repository deletion behavior
Comments suppressed due to low confidence (1)

github/resource_github_issue_labels.go:202

  • Setting the resource ID after a delete operation is incorrect. The delete function should remove the resource from state, not set an ID. Line 200 should be removed, and line 202 should use := instead of = since err is not declared earlier in the function scope.
	d.SetId(repository)

	err := d.Set("label", make([]map[string]interface{}, 0))

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nickfloyd nickfloyd moved this from Backlog to In Review in Terraform Provider Oct 28, 2025
@nickfloyd nickfloyd changed the title Adds utility to handle the various needs of error management when dealing with archived repos. Handle error management on resources when dealing with archived repos. Oct 29, 2025
@nickfloyd nickfloyd merged commit 0f3f802 into main Oct 29, 2025
3 checks passed
@nickfloyd nickfloyd deleted the 737/handle-archived-repos branch October 29, 2025 18:37
@github-project-automation github-project-automation bot moved this from In Review to Done in Terraform Provider Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working as documented Type: Feature New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

Add ignoring feature for archived repositories

4 participants