#26 document codeberg not allowing pull mirrors

fixed permission failure in gite_repository
main v0.12.3
Tobias Trabelsi 1 year ago
parent f87515a453
commit 0a85957c50

@ -1,9 +1,11 @@
TEST?=./gitea TEST?=./gitea
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor) GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
ARCH?=$$(uname -m)
KERNEL?=$$(uname -s | tr '[:upper:]' '[:lower:]')
GOFMT ?= gofmt -s GOFMT ?= gofmt -s
VERSION = 0.12.2 VERSION = 0.12.3
test: fmt-check test: fmt-check
go test -i $(TEST) || exit 1 go test -i $(TEST) || exit 1
@ -34,8 +36,8 @@ build:
go build -ldflags="-X 'main.Version=${VERSION}'" -o terraform-provider-gitea_${VERSION} go build -ldflags="-X 'main.Version=${VERSION}'" -o terraform-provider-gitea_${VERSION}
install: build install: build
@echo installing to @echo installing to
@echo ~/.terraform.d/plugins/terraform.local/lerentis/gitea/${VERSION}/linux_amd64/terraform-provider-gitea_${VERSION} @echo ~/.terraform.d/plugins/terraform.local/lerentis/gitea/${VERSION}/${KERNEL}_${ARCH}/terraform-provider-gitea_${VERSION}
@mkdir -p ~/.terraform.d/plugins/terraform.local/lerentis/gitea/${VERSION}/linux_amd64 @mkdir -p ~/.terraform.d/plugins/terraform.local/lerentis/gitea/${VERSION}/${KERNEL}_${ARCH}
@mv terraform-provider-gitea_${VERSION} ~/.terraform.d/plugins/terraform.local/lerentis/gitea/${VERSION}/linux_amd64/terraform-provider-gitea_${VERSION} @mv terraform-provider-gitea_${VERSION} ~/.terraform.d/plugins/terraform.local/lerentis/gitea/${VERSION}/${KERNEL}_${ARCH}/terraform-provider-gitea_${VERSION}
doc: doc:
tfplugindocs tfplugindocs

@ -17,7 +17,7 @@ terraform {
required_providers { required_providers {
gitea = { gitea = {
source = "Lerentis/gitea" source = "Lerentis/gitea"
version = "0.12.2" version = "0.12.3"
} }
} }
} }

@ -17,7 +17,7 @@ terraform {
required_providers { required_providers {
gitea = { gitea = {
source = "Lerentis/gitea" source = "Lerentis/gitea"
version = "0.12.2" version = "0.12.3"
} }
} }
} }

@ -7,6 +7,7 @@ description: |-
Per default this repository will be initializiled with the provided configuration (gitignore, License etc.). Per default this repository will be initializiled with the provided configuration (gitignore, License etc.).
If the username property is set to a organisation name, the provider will try to look if this organisation exists and create the repository under the organisation scope. If the username property is set to a organisation name, the provider will try to look if this organisation exists and create the repository under the organisation scope.
Repository migrations have some properties that are not available to regular repositories. These are all prefixed with migration_. Repository migrations have some properties that are not available to regular repositories. These are all prefixed with migration_.
Codeberg.org does currently not allow mirrors to be created. See FAQ Section of CodeBerg for more information: https://docs.codeberg.org/getting-started/faq/#why-am-i-not-allowed-to-set-up-an-automatic-mirror
--- ---
# gitea_repository (Resource) # gitea_repository (Resource)
@ -17,6 +18,7 @@ Per default this repository will be initializiled with the provided configuratio
If the `username` property is set to a organisation name, the provider will try to look if this organisation exists and create the repository under the organisation scope. If the `username` property is set to a organisation name, the provider will try to look if this organisation exists and create the repository under the organisation scope.
Repository migrations have some properties that are not available to regular repositories. These are all prefixed with `migration_`. Repository migrations have some properties that are not available to regular repositories. These are all prefixed with `migration_`.
Codeberg.org does currently not allow mirrors to be created. See FAQ Section of CodeBerg for more information: https://docs.codeberg.org/getting-started/faq/#why-am-i-not-allowed-to-set-up-an-automatic-mirror
## Example Usage ## Example Usage

@ -2,7 +2,7 @@ terraform {
required_providers { required_providers {
gitea = { gitea = {
source = "terraform.local/lerentis/gitea" source = "terraform.local/lerentis/gitea"
version = "0.12.2" version = "0.12.3"
} }
} }
} }

@ -2,7 +2,7 @@ terraform {
required_providers { required_providers {
gitea = { gitea = {
source = "Lerentis/gitea" source = "Lerentis/gitea"
version = "0.12.2" version = "0.12.3"
} }
} }
} }

@ -1,11 +1,14 @@
package gitea package gitea
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"code.gitea.io/sdk/gitea" "code.gitea.io/sdk/gitea"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
) )
@ -108,14 +111,20 @@ func resourceRepoCreate(d *schema.ResourceData, meta interface{}) (err error) {
var repo *gitea.Repository var repo *gitea.Repository
var resp *gitea.Response var resp *gitea.Response
var orgRepo bool var orgRepo, hasAdmin bool
_, resp, err = client.GetOrg(d.Get(repoOwner).(string)) _, resp, err = client.GetOrg(d.Get(repoOwner).(string))
if resp.StatusCode == 404 { if resp.StatusCode == 404 {
_, err := searchUserByName(client, d.Get(repoOwner).(string)) _, err := searchUserByName(client, d.Get(repoOwner).(string))
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("Creation of repository cound not proceed as owner %s is not present in gitea", d.Get(repoOwner).(string))) if strings.Contains(err.Error(), "could not be found") {
return errors.New(fmt.Sprintf("Creation of repository cound not proceed as owner %s is not present in gitea", d.Get(repoOwner).(string)))
}
tflog.Warn(context.Background(), "Error query for users. Assuming missing permissions and proceding with user permissions")
hasAdmin = false
} else {
hasAdmin = true
} }
orgRepo = false orgRepo = false
} else { } else {
@ -180,7 +189,11 @@ func resourceRepoCreate(d *schema.ResourceData, meta interface{}) (err error) {
if orgRepo { if orgRepo {
repo, _, err = client.CreateOrgRepo(d.Get(repoOwner).(string), opts) repo, _, err = client.CreateOrgRepo(d.Get(repoOwner).(string), opts)
} else { } else {
repo, _, err = client.AdminCreateRepo(d.Get(repoOwner).(string), opts) if hasAdmin {
repo, _, err = client.AdminCreateRepo(d.Get(repoOwner).(string), opts)
} else {
repo, _, err = client.CreateRepo(opts)
}
} }
} }
@ -580,6 +593,8 @@ func resourceGiteaRepository() *schema.Resource {
"Per default this repository will be initializiled with the provided configuration (gitignore, License etc.).\n" + "Per default this repository will be initializiled with the provided configuration (gitignore, License etc.).\n" +
"If the `username` property is set to a organisation name, the provider will try to look if this organisation exists " + "If the `username` property is set to a organisation name, the provider will try to look if this organisation exists " +
"and create the repository under the organisation scope.\n\n" + "and create the repository under the organisation scope.\n\n" +
"Repository migrations have some properties that are not available to regular repositories. These are all prefixed with `migration_`.", "Repository migrations have some properties that are not available to regular repositories. These are all prefixed with `migration_`.\n" +
"Codeberg.org does currently not allow mirrors to be created. See FAQ Section of CodeBerg for more information: " +
"https://docs.codeberg.org/getting-started/faq/#why-am-i-not-allowed-to-set-up-an-automatic-mirror",
} }
} }

@ -5,6 +5,7 @@ go 1.18
require ( require (
code.gitea.io/sdk/gitea v0.15.1 code.gitea.io/sdk/gitea v0.15.1
github.com/hashicorp/terraform-plugin-docs v0.14.1 github.com/hashicorp/terraform-plugin-docs v0.14.1
github.com/hashicorp/terraform-plugin-log v0.8.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1 github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
) )
@ -35,7 +36,6 @@ require (
github.com/hashicorp/terraform-exec v0.18.1 // indirect github.com/hashicorp/terraform-exec v0.18.1 // indirect
github.com/hashicorp/terraform-json v0.16.0 // indirect github.com/hashicorp/terraform-json v0.16.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.14.3 // indirect github.com/hashicorp/terraform-plugin-go v0.14.3 // indirect
github.com/hashicorp/terraform-plugin-log v0.8.0 // indirect
github.com/hashicorp/terraform-registry-address v0.1.0 // indirect github.com/hashicorp/terraform-registry-address v0.1.0 // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect

Loading…
Cancel
Save