From 049ccaf5fcb284af186c539709cb0a975487e235 Mon Sep 17 00:00:00 2001 From: felixlut Date: Fri, 22 Sep 2023 16:57:36 +0200 Subject: [PATCH 1/2] remove repository topic if they cannot be found in GitHub anymore --- github/resource_github_repository_topics.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/github/resource_github_repository_topics.go b/github/resource_github_repository_topics.go index e481042830..40958b021b 100644 --- a/github/resource_github_repository_topics.go +++ b/github/resource_github_repository_topics.go @@ -2,8 +2,11 @@ package github import ( "context" + "log" + "net/http" "regexp" + "github.com/google/go-github/v55/github" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) @@ -68,6 +71,17 @@ func resourceGithubRepositoryTopicsRead(d *schema.ResourceData, meta interface{} topics, _, err := client.Repositories.ListAllTopics(ctx, owner, repoName) if err != nil { + if ghErr, ok := err.(*github.ErrorResponse); ok { + if ghErr.Response.StatusCode == http.StatusNotModified { + return nil + } + if ghErr.Response.StatusCode == http.StatusNotFound { + log.Printf("[INFO] Removing topics from repository %s/%s from state because it no longer exists in GitHub", + owner, repoName) + d.SetId("") + return nil + } + } return err } From 9b64652007e13f76a6cf7d97b097f9d06a2c0b4c Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Wed, 10 Jan 2024 15:44:23 -0800 Subject: [PATCH 2/2] Fix build error by bumping package version in offending file --- github/resource_github_repository_topics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/resource_github_repository_topics.go b/github/resource_github_repository_topics.go index 40958b021b..2d84370be6 100644 --- a/github/resource_github_repository_topics.go +++ b/github/resource_github_repository_topics.go @@ -6,7 +6,7 @@ import ( "net/http" "regexp" - "github.com/google/go-github/v55/github" + "github.com/google/go-github/v57/github" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" )