Compare commits

..

4 Commits

Author SHA1 Message Date
8e2fc7264b
shorten feedback loop
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-08-13 22:45:54 +02:00
aa7856ea7b
#12 stick with IDs for consistency
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
2022-08-13 22:37:46 +02:00
8b25a1519e
#12 fix terraform import for organisations
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-13 22:15:19 +02:00
cfa43451d8
#12 init
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-13 18:43:03 +02:00
8 changed files with 55 additions and 16 deletions

View File

@ -15,13 +15,24 @@ steps:
- push
- pull_request
- tag
- name: build-dev
image: golang:1.18.3-alpine3.16
commands:
- "apk add --update --no-cache make"
- "make build"
when:
event:
- push
resources:
limits:
cpu: 1000
memory: 1024MiB
- name: build
image: goreleaser/goreleaser
commands:
- goreleaser build --snapshot
when:
event:
- push
- pull_request
resources:
limits:

View File

@ -3,7 +3,7 @@ GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
GOFMT ?= gofmt -s
VERSION = 0.7.1
VERSION = 0.7.2
test: fmt-check
go test -i $(TEST) || exit 1

View File

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

View File

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

View File

@ -18,7 +18,8 @@ resource "gitea_repository" "mirror" {
}
resource "gitea_org" "test_org" {
name = "test-org"
name = "test-org"
description = "test description"
}
resource "gitea_repository" "org_repo" {

View File

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

View File

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

View File

@ -2,6 +2,7 @@ package gitea
import (
"fmt"
"strconv"
"code.gitea.io/sdk/gitea"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@ -17,21 +18,47 @@ const (
RepoAdminChangeTeamAccess string = "repo_admin_change_team_access"
)
// might come in handy if we want to stick to numeric IDs
func searchOrgByClientId(c *gitea.Client, id int64) (res *gitea.Organization, err error) {
page := 1
for {
orgs, _, err := c.AdminListOrgs(gitea.AdminListOrgsOptions{
ListOptions: gitea.ListOptions{
Page: page,
PageSize: 50,
},
})
if err != nil {
return nil, err
}
if len(orgs) == 0 {
return nil, fmt.Errorf("Organisation with ID %d could not be found", id)
}
for _, org := range orgs {
if org.ID == id {
return org, nil
}
}
page += 1
}
}
func resourceOrgRead(d *schema.ResourceData, meta interface{}) (err error) {
client := meta.(*gitea.Client)
var org *gitea.Organization
var resp *gitea.Response
org, resp, err = client.GetOrg(d.Get(orgName).(string))
id, err := strconv.ParseInt(d.Id(), 10, 64)
org, err = searchOrgByClientId(client, id)
if err != nil {
if resp.StatusCode == 404 {
d.SetId("")
return nil
} else {
return err
}
return err
}
err = setOrgResourceData(org, d)
@ -133,7 +160,7 @@ func resourceGiteaOrg() *schema.Resource {
Update: resourceOrgUpdate,
Delete: resourceOrgDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
StateContext: schema.ImportStatePassthroughContext,
},
Schema: map[string]*schema.Schema{
"name": {