Skip to content

Commit

Permalink
Handle repo rename edge case for team repository deletions (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
k24dizzle authored Sep 2, 2021
1 parent 443daae commit 4902101
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion github/resource_github_team_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ func resourceGithubTeamRepositoryDelete(d *schema.ResourceData, meta interface{}

log.Printf("[DEBUG] Deleting team repository association: %s (%s/%s)",
teamIdString, orgName, repoName)
_, err = client.Teams.RemoveTeamRepoByID(ctx, orgId, teamId, orgName, repoName)
resp, err := client.Teams.RemoveTeamRepoByID(ctx, orgId, teamId, orgName, repoName)

if resp.Response.StatusCode == 404 {
log.Printf("[DEBUG] Failed to find team %s to delete for repo: %s.", teamIdString, repoName)
repo, _, err := client.Repositories.Get(ctx, orgName, repoName)
if err != nil {
return err
}
newRepoName := repo.GetName()
if newRepoName != repoName {
log.Printf("[DEBUG] Repo name has changed %s -> %s. "+
"Try deleting team repository again.",
repoName, newRepoName)
_, err := client.Teams.RemoveTeamRepoByID(ctx, orgId, teamId, orgName, newRepoName)
return err
}
}

return err
}

0 comments on commit 4902101

Please sign in to comment.