From 6d5439a00a01a9add95e66df7a5a74fe99def473 Mon Sep 17 00:00:00 2001 From: Tobias Trabelsi Date: Wed, 5 Oct 2022 21:36:06 +0200 Subject: [PATCH] fixed minor bug in resourceForkDelete --- examples/main.tf | 24 ++++++++++++++++++++++++ examples/provider.tf | 2 +- gitea/resource_gitea_fork.go | 19 ++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/examples/main.tf b/examples/main.tf index bf41f7e..2568532 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -71,3 +71,27 @@ resource "gitea_git_hook" "org_repo_pre_receive" { repo = gitea_repository.org_repo.name content = file("${path.module}/pre-receive.sh") } + +resource "gitea_org" "org1" { + name = "org1" +} + +resource "gitea_org" "org2" { + name = "org2" +} + +resource "gitea_repository" "repo1_in_org1" { + username = gitea_org.org1.name + name = "repo1-in-org1" +} + +resource "gitea_fork" "user_fork_of_repo1_in_org1" { + owner = gitea_org.org1.name + repo = gitea_repository.repo1_in_org1.name +} + +resource "gitea_fork" "org2_fork_of_repo1_in_org1" { + owner = gitea_org.org1.name + repo = gitea_repository.repo1_in_org1.name + organization = gitea_org.org2.name +} \ No newline at end of file diff --git a/examples/provider.tf b/examples/provider.tf index ec315cc..9f5f45f 100644 --- a/examples/provider.tf +++ b/examples/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { gitea = { source = "terraform.local/lerentis/gitea" - version = "0.8.0" + version = "0.9.0" } } } diff --git a/gitea/resource_gitea_fork.go b/gitea/resource_gitea_fork.go index d9a5497..775586b 100644 --- a/gitea/resource_gitea_fork.go +++ b/gitea/resource_gitea_fork.go @@ -62,7 +62,24 @@ func resourceForkRead(d *schema.ResourceData, meta interface{}) (err error) { func resourceForkDelete(d *schema.ResourceData, meta interface{}) (err error) { client := meta.(*gitea.Client) - client.DeleteRepo(d.Get(forkOrganization).(string), d.Get(forkRepo).(string)) + id, err := strconv.ParseInt(d.Id(), 10, 64) + + if err != nil { + return err + } + + repo, _, err := client.GetRepoByID(id) + var resp *gitea.Response + + resp, err = client.DeleteRepo(repo.Owner.UserName, repo.Name) + + if err != nil { + if resp.StatusCode == 404 { + return + } else { + return err + } + } return }