mirror of
https://git.uploadfilter24.eu/lerentis/terraform-provider-gitea.git
synced 2024-12-04 21:08:11 +00:00
Merge pull request #48 from Lerentis/feature/#47/list-all-org-repos
This commit is contained in:
commit
ed32470b17
8 changed files with 60 additions and 9 deletions
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ KERNEL?=$$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
GOFMT ?= gofmt -s
|
GOFMT ?= gofmt -s
|
||||||
|
|
||||||
VERSION = 0.14.1
|
VERSION = 0.15.0
|
||||||
|
|
||||||
test: fmt-check
|
test: fmt-check
|
||||||
go test -i $(TEST) || exit 1
|
go test -i $(TEST) || exit 1
|
||||||
|
|
|
@ -17,7 +17,7 @@ terraform {
|
||||||
required_providers {
|
required_providers {
|
||||||
gitea = {
|
gitea = {
|
||||||
source = "Lerentis/gitea"
|
source = "Lerentis/gitea"
|
||||||
version = "0.14.1"
|
version = "0.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ terraform {
|
||||||
required_providers {
|
required_providers {
|
||||||
gitea = {
|
gitea = {
|
||||||
source = "Lerentis/gitea"
|
source = "Lerentis/gitea"
|
||||||
version = "0.14.1"
|
version = "0.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,5 +46,6 @@ resource "gitea_repository" "org_repo" {
|
||||||
|
|
||||||
- `avatar_url` (String)
|
- `avatar_url` (String)
|
||||||
- `id` (String) The ID of this resource.
|
- `id` (String) The ID of this resource.
|
||||||
|
- `repos` (List of String) List of all Repositories that are part of this organisation
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -123,3 +123,15 @@ output "token" {
|
||||||
value = resource.gitea_token.test_token.token
|
value = resource.gitea_token.test_token.token
|
||||||
sensitive = true
|
sensitive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data "gitea_repo" "org_repos" {
|
||||||
|
name = each.key
|
||||||
|
username = gitea_org.org1.name
|
||||||
|
for_each = {
|
||||||
|
for repo in resource.gitea_org.org1.repos : repo => repo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output "repos" {
|
||||||
|
value = data.gitea_repo.org_repos["repo1-in-org1"].clone_url
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ terraform {
|
||||||
required_providers {
|
required_providers {
|
||||||
gitea = {
|
gitea = {
|
||||||
source = "terraform.local/lerentis/gitea"
|
source = "terraform.local/lerentis/gitea"
|
||||||
version = "0.14.1"
|
version = "0.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ terraform {
|
||||||
required_providers {
|
required_providers {
|
||||||
gitea = {
|
gitea = {
|
||||||
source = "Lerentis/gitea"
|
source = "Lerentis/gitea"
|
||||||
version = "0.14.1"
|
version = "0.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ const (
|
||||||
orgLocation string = "location"
|
orgLocation string = "location"
|
||||||
orgVisibility string = "visibility"
|
orgVisibility string = "visibility"
|
||||||
RepoAdminChangeTeamAccess string = "repo_admin_change_team_access"
|
RepoAdminChangeTeamAccess string = "repo_admin_change_team_access"
|
||||||
|
orgRepos string = "org_repos"
|
||||||
)
|
)
|
||||||
|
|
||||||
// might come in handy if we want to stick to numeric IDs
|
// might come in handy if we want to stick to numeric IDs
|
||||||
|
@ -48,6 +49,32 @@ func searchOrgByClientId(c *gitea.Client, id int64) (res *gitea.Organization, er
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAllOrgRepos(c *gitea.Client, orgName string) (repos []string, err error) {
|
||||||
|
page := 1
|
||||||
|
|
||||||
|
for {
|
||||||
|
repoBuffer, _, err := c.ListOrgRepos(orgName, gitea.ListOrgReposOptions{
|
||||||
|
ListOptions: gitea.ListOptions{
|
||||||
|
Page: page,
|
||||||
|
PageSize: 50,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(repoBuffer) == 0 {
|
||||||
|
return repos, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, repo := range repoBuffer {
|
||||||
|
repos = append(repos, repo.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
page += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func resourceOrgRead(d *schema.ResourceData, meta interface{}) (err error) {
|
func resourceOrgRead(d *schema.ResourceData, meta interface{}) (err error) {
|
||||||
client := meta.(*gitea.Client)
|
client := meta.(*gitea.Client)
|
||||||
|
|
||||||
|
@ -62,7 +89,8 @@ func resourceOrgRead(d *schema.ResourceData, meta interface{}) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = setOrgResourceData(org, d)
|
repos, _ := getAllOrgRepos(client, org.UserName)
|
||||||
|
err = setOrgResourceData(org, d, &repos)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -85,7 +113,8 @@ func resourceOrgCreate(d *schema.ResourceData, meta interface{}) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = setOrgResourceData(org, d)
|
repos, _ := getAllOrgRepos(client, org.UserName)
|
||||||
|
err = setOrgResourceData(org, d, &repos)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -118,7 +147,8 @@ func resourceOrgUpdate(d *schema.ResourceData, meta interface{}) (err error) {
|
||||||
|
|
||||||
org, resp, err = client.GetOrg(d.Get(orgName).(string))
|
org, resp, err = client.GetOrg(d.Get(orgName).(string))
|
||||||
|
|
||||||
err = setOrgResourceData(org, d)
|
repos, _ := getAllOrgRepos(client, org.UserName)
|
||||||
|
err = setOrgResourceData(org, d, &repos)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -141,7 +171,7 @@ func resourceOrgDelete(d *schema.ResourceData, meta interface{}) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func setOrgResourceData(org *gitea.Organization, d *schema.ResourceData) (err error) {
|
func setOrgResourceData(org *gitea.Organization, d *schema.ResourceData, repos *[]string) (err error) {
|
||||||
d.SetId(fmt.Sprintf("%d", org.ID))
|
d.SetId(fmt.Sprintf("%d", org.ID))
|
||||||
d.Set("name", org.UserName)
|
d.Set("name", org.UserName)
|
||||||
d.Set("full_name", org.FullName)
|
d.Set("full_name", org.FullName)
|
||||||
|
@ -150,6 +180,7 @@ func setOrgResourceData(org *gitea.Organization, d *schema.ResourceData) (err er
|
||||||
d.Set("website", org.Website)
|
d.Set("website", org.Website)
|
||||||
d.Set("location", org.Location)
|
d.Set("location", org.Location)
|
||||||
d.Set("visibility", org.Visibility)
|
d.Set("visibility", org.Visibility)
|
||||||
|
d.Set("repos", repos)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -211,6 +242,13 @@ func resourceGiteaOrg() *schema.Resource {
|
||||||
Default: "public",
|
Default: "public",
|
||||||
Description: "Flag is this organisation should be publicly visible or not.",
|
Description: "Flag is this organisation should be publicly visible or not.",
|
||||||
},
|
},
|
||||||
|
"repos": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Required: false,
|
||||||
|
Computed: true,
|
||||||
|
Description: "List of all Repositories that are part of this organisation",
|
||||||
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Description: "`gitea_org` manages a gitea organisation.\n\n" +
|
Description: "`gitea_org` manages a gitea organisation.\n\n" +
|
||||||
"Organisations are a way to group repositories and abstract permission management in a gitea instance.",
|
"Organisations are a way to group repositories and abstract permission management in a gitea instance.",
|
||||||
|
|
Loading…
Reference in a new issue