Repository navigation
Detect not-found via the error (errors.AsType) in github_team_repository delete - #3524
stevehipwell merged 2 commits into
Conversation
|
👋 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. |
stevehipwell
left a comment
There was a problem hiding this comment.
I've added a couple of inline comments, could you also look at the rest of the codebase for this pattern and make the relevant changes?
|
sorry for the force-push, I accidentally committed a local state file ( |
|
@rilical do you want to rebase again? |
…ory delete Detect the not-found case in resourceGithubTeamRepositoryDelete from the returned error via errors.AsType[*github.ErrorResponse] instead of reading resp.StatusCode off the raw response, and restructure to check the error first, matching the delete style in resource_github_issue_label.go. The repository-rename recovery and archived-repository handling are unchanged. A *github.ErrorResponse always carries a non-nil Response (go-github only builds one in CheckResponse), so drop the redundant Response != nil guard here and at the other sites that had picked up the same pattern: util_retry.go, provider.go, and resource_github_enterprise_organization.go. Normalize util_retry.go's not-found check from the literal 404 to http.StatusNotFound. Co-authored-by: Copilot App <[email protected]>
|
yep, done. rebased onto main now that #3518 landed, so it's down to just the single refactor commit. also refreshed the description to match. |
deiga
left a comment
There was a problem hiding this comment.
Looking at go-github it seems to me that a json.Unmarshal error can result in an github.ErrorResponse with a nil Response attribute. I don't think it makes sense to make the providers code more brittle by removing this nil checks
Per review, drop the Repositories.Get lookup and the rename-and-retry branch from resourceGithubTeamRepositoryDelete and simplify to the idempotent delete pattern used by resource_github_issue_label.go: a 404 from RemoveTeamRepoByID is treated as already-deleted (return nil), and any other error flows through handleArchivedRepoDelete as before. Co-authored-by: Copilot App <[email protected]>
|
@deiga thanks for taking a look. I went through go-github v88 (the version pinned in go.mod) and I don't think that path exists there:
Every |
|
@rilical ah, Sorry. I didn't see Steve's comment. Yes, then the nil checks are safe to remove. |
Unblocks the nightly `upgrade-provider` job and pulls in upstream v6.13.0. ## Why this was stuck Upstream v6.13.0 refactored the provider entry point in [#3440](integrations/terraform-provider-github#3440), replacing the parameterless `github.Provider()` with `github.NewProvider(version, commit)`, which returns the provider factory. The nightly [Upgrade provider](https://github.com/pulumi/pulumi-github/actions/workflows/upgrade-provider.yml) job rebases onto the new tag fine, then dies in codegen: ``` ./scripts/upstream.sh rebase -o refs/tags/v6.13.0: done error: upgrade-provider executed `make tfgen` which failed: exit status 2: ./resources.go:78:33: undefined: github.Provider make: *** [Makefile:323: bin/pulumi-tfgen-github] Error 1 ``` It has failed every night since v6.13.0 was released on 2026-07-08, so the bridge is still pinned to upstream v6.12.1 and none of the fixes below have shipped. ## Changes - `provider/resources.go`: use `github.NewProvider(version.Version, "")()`. `version` and `commit` only feed the upstream User-Agent and debug logging; the bridge appends its own Pulumi User-Agent, so the commit is left empty. This is the only hand-written change. - `upstream`: v6.12.1 → v6.13.0 (via `upstream.sh checkout` / `rebase -o refs/tags/v6.13.0` / `check_in`). - Regenerated schema, all five SDKs, and `docs/_index.md`. ## Notable upstream fixes pulled in - **`github_team_repository` delete now treats a 404 from GitHub as a successful delete** ([#3524](integrations/terraform-provider-github#3524)). Previously the 404 branch only recovered from repository *renames*: it re-read the repo and retried the delete only when `.GetName()` differed. A repository transferred to a **different organization** keeps its name, so the retry was skipped and the original 404 surfaced as a hard error. Any stack still holding that resource in state is then permanently wedged — every subsequent update fails on the same undeletable resource, and the only escape is `pulumi state delete`. - Fixes a nil-pointer panic in that same delete path when the API call fails at the transport layer ([#3518](integrations/terraform-provider-github#3518)). - `github_team_members` deletion is skipped when the parent team is already gone ([#3461](integrations/terraform-provider-github#3461)). ## Schema impact Additive — nothing removed or retyped (verified by diffing schema keys against `master`): - New provider config options: `cachePath`, `legacyClient` - New resource properties: `BranchDefault.repositoryId`, `BranchDefault.waitForRename`, `RepositoryCollaborators.ownerConfigured`, `RepositoryCustomProperty.repositoryId`, `TeamMembers.teamSlug` The bulk of the schema and `docs/_index.md` diff is upstream's migration to tfplugindocs ([#3380](integrations/terraform-provider-github#3380)) and its rewritten provider docs and examples ([#3440](integrations/terraform-provider-github#3440)) — restyled descriptions, and the overview example changing from `github_membership` to `getRepository` because upstream replaced `examples/provider/example_1.tf`/`example_2.tf` with a single `provider.tf`. ## Verification - `make tfgen` succeeds; example conversion 93.39% (1314/1407) - All five SDKs generated; Go SDK compiles - `dotnet build` not run locally (unrelated local NuGet source misconfiguration) — leaving that to CI - Acceptance tests not run locally 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Resolves #3523
Follow-up to #3518 (now merged), addressing @stevehipwell's review feedback.
What changed
resourceGithubTeamRepositoryDeletenow detects the not-found case from the returned error viaerrors.AsType[*github.ErrorResponse](err)instead of readingresp.StatusCodeoff the raw response, restructured to check the error first (matching the delete style inresource_github_issue_label.go).Response != nilguard on*github.ErrorResponseacross the codebase, since a*github.ErrorResponsealways carries a non-nilResponse(go-github only builds one inCheckResponse):util_retry.go,provider.go, andresource_github_enterprise_organization.go.util_retry.go's not-found check from the literal404tohttp.StatusNotFound.Behavior-preserving: the repo-rename retry and archived/404 handling are unchanged, and the nil-response panic regression test added in #3518 still covers this delete path.
Open question: a bare 404 on delete still returns the error rather than being idempotent (
return nil, likeresource_github_issue_label.go), and the rename retry is still there. Happy to simplify either if you'd like, I just didn't want to change destroy semantics unprompted.Verification
go build,go vet,gofmtclean.make test).TestAccGithubTeamRepositorypasses (create / read / import / update / destroy).Pull request checklist
Does this introduce a breaking change?
AI-assisted disclosure: developed with AI assistance (GitHub Copilot). Per the repository's AI Use Policy I have reviewed and understand the change, verified the
errors.AsType+*github.ErrorResponseinvariant against go-github v88's construction sites and the provider's usages, and tested it with the unit regression suite plus a live acceptance run ofTestAccGithubTeamRepository.