Skip to content

Commit 0106ddb

Browse files
committed
fix(github_repository_autolink_reference): Remove from state for non-existing repository
fix: Fix variable name
1 parent d63ad78 commit 0106ddb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

github/resource_github_repository_autolink_reference.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ func resourceGithubRepositoryAutolinkReferenceRead(d *schema.ResourceData, meta
130130
ctx = context.WithValue(ctx, ctxEtag, d.Get("etag").(string))
131131
}
132132

133+
_, _, repo_err := client.Repositories.Get(ctx, owner, repoName)
134+
if repo_err != nil {
135+
if ghErr, ok := repo_err.(*github.ErrorResponse); ok {
136+
if ghErr.Response.StatusCode == http.StatusNotModified {
137+
return nil
138+
}
139+
if ghErr.Response.StatusCode == http.StatusNotFound {
140+
log.Printf("[INFO] Removing autolink reference from state because repository %s/%s no longer exists in GitHub",
141+
owner, repoName)
142+
d.SetId("")
143+
return nil
144+
}
145+
}
146+
return repo_err
147+
}
148+
133149
autolinkRef, _, err := client.Repositories.GetAutolink(ctx, owner, repoName, autolinkRefID)
134150
if err != nil {
135151
if ghErr, ok := err.(*github.ErrorResponse); ok {

0 commit comments

Comments
 (0)