From 6d0bd5906a09cdbbf1b1a72b7b23c13db0295351 Mon Sep 17 00:00:00 2001 From: Tobias Trabelsi Date: Wed, 5 Oct 2022 21:22:30 +0200 Subject: [PATCH] pre release version bump make fmt clarified some limitations for fork resource --- docs/index.md | 2 +- docs/resources/fork.md | 34 +++++++++++++++++++++-- examples/provider/provider.tf | 2 +- examples/resources/gitea_fork/resource.tf | 8 +++--- gitea/resource_gitea_fork.go | 15 ++++++---- 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/docs/index.md b/docs/index.md index 53c4509..a6219b6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,7 @@ terraform { required_providers { gitea = { source = "Lerentis/gitea" - version = "0.8.0" + version = "0.9.0" } } } diff --git a/docs/resources/fork.md b/docs/resources/fork.md index e96181f..6733ea7 100644 --- a/docs/resources/fork.md +++ b/docs/resources/fork.md @@ -3,14 +3,44 @@ page_title: "gitea_fork Resource - terraform-provider-gitea" subcategory: "" description: |- - gitea_fork manages repository fork + gitea_fork manages repository fork to the current user or an organisation + Forking a repository to a dedicated user is currently unsupported + Creating a fork using this resource without an organisation will create the fork in the executors name --- # gitea_fork (Resource) -`gitea_fork` manages repository fork +`gitea_fork` manages repository fork to the current user or an organisation +Forking a repository to a dedicated user is currently unsupported +Creating a fork using this resource without an organisation will create the fork in the executors name +## Example Usage +```terraform +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 +} +``` ## Schema diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 2f9e7ac..997533b 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { gitea = { source = "Lerentis/gitea" - version = "0.8.0" + version = "0.9.0" } } } diff --git a/examples/resources/gitea_fork/resource.tf b/examples/resources/gitea_fork/resource.tf index 4129a01..f680d5e 100644 --- a/examples/resources/gitea_fork/resource.tf +++ b/examples/resources/gitea_fork/resource.tf @@ -8,16 +8,16 @@ resource "gitea_org" "org2" { resource "gitea_repository" "repo1_in_org1" { username = gitea_org.org1.name - name = "repo1-in-org1" + 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 + 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 + owner = gitea_org.org1.name + repo = gitea_repository.repo1_in_org1.name organization = gitea_org.org2.name } diff --git a/gitea/resource_gitea_fork.go b/gitea/resource_gitea_fork.go index 91b5f96..d9a5497 100644 --- a/gitea/resource_gitea_fork.go +++ b/gitea/resource_gitea_fork.go @@ -3,14 +3,15 @@ package gitea import ( "fmt" "strconv" + "code.gitea.io/sdk/gitea" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( - forkOwner string = "owner" - forkRepo string = "repo" - forkOrganization string = "organization" + forkOwner string = "owner" + forkRepo string = "repo" + forkOrganization string = "organization" ) func resourceForkCreate(d *schema.ResourceData, meta interface{}) (err error) { @@ -24,8 +25,8 @@ func resourceForkCreate(d *schema.ResourceData, meta interface{}) (err error) { } repo, _, err := client.CreateFork(d.Get(forkOwner).(string), - d.Get(forkRepo).(string), - opts) + d.Get(forkRepo).(string), + opts) if err == nil { err = setForkResourceData(repo, d) } @@ -102,6 +103,8 @@ func resourceGiteaFork() *schema.Resource { Description: "The organization that owns the forked repo", }, }, - Description: "`gitea_fork` manages repository fork", + Description: "`gitea_fork` manages repository fork to the current user or an organisation\n" + + "Forking a repository to a dedicated user is currently unsupported\n" + + "Creating a fork using this resource without an organisation will create the fork in the executors name", } }