Skip to content

Commit

Permalink
Merge pull request #348 from terraform-providers/fix-repo-404
Browse files Browse the repository at this point in the history
Handle repo 404 gracefully
  • Loading branch information
paultyng authored Feb 5, 2020
2 parents 8b3aa4c + b42fa11 commit c6e9a02
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion github/resource_github_repository_collaborator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"net/http"
"strings"

"github.com/google/go-github/v28/github"
Expand Down Expand Up @@ -97,8 +98,19 @@ func resourceGithubRepositoryCollaboratorRead(d *schema.ResourceData, meta inter
// First, check if the user has been invited but has not yet accepted
invitation, err := findRepoInvitation(client, ctx, orgName, repoName, username)
if err != nil {
if ghErr, ok := err.(*github.ErrorResponse); ok {
if ghErr.Response.StatusCode == http.StatusNotFound {
// this short circuits the rest of the code because if the
// repo is 404, no reason to try to list existing collaborators
log.Printf("[WARN] Removing repository collaborator %s/%s %s from state because it no longer exists in GitHub",
orgName, repoName, username)
d.SetId("")
return nil
}
}
return err
} else if invitation != nil {
}
if invitation != nil {
username = *invitation.Invitee.Login
log.Printf("[DEBUG] Found invitation for %q", username)

Expand Down

0 comments on commit c6e9a02

Please sign in to comment.