mirror of
https://git.uploadfilter24.eu/lerentis/terraform-provider-gitea.git
synced 2024-12-04 21:08:11 +00:00
added possibility to list all repos of an organisation
This commit is contained in:
parent
48f5c3ee3c
commit
483bda1033
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
|
||||
|
||||
VERSION = 0.14.1
|
||||
VERSION = 0.15.0
|
||||
|
||||
test: fmt-check
|
||||
go test -i $(TEST) || exit 1
|
||||
|
|
|
@ -17,7 +17,7 @@ terraform {
|
|||
required_providers {
|
||||
gitea = {
|
||||
source = "Lerentis/gitea"
|
||||
version = "0.14.1"
|
||||
version = "0.15.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ terraform {
|
|||
required_providers {
|
||||
gitea = {
|
||||
source = "Lerentis/gitea"
|
||||
version = "0.14.1"
|
||||
version = "0.15.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,5 +46,6 @@ resource "gitea_repository" "org_repo" {
|
|||
|
||||
- `avatar_url` (String)
|
||||
- `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
|
||||
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 {
|
||||
gitea = {
|
||||
source = "terraform.local/lerentis/gitea"
|
||||
version = "0.14.1"
|
||||
version = "0.15.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ terraform {
|
|||
required_providers {
|
||||
gitea = {
|
||||
source = "Lerentis/gitea"
|
||||
version = "0.14.1"
|
||||
version = "0.15.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ const (
|
|||
orgLocation string = "location"
|
||||
orgVisibility string = "visibility"
|
||||
RepoAdminChangeTeamAccess string = "repo_admin_change_team_access"
|
||||
orgRepos string = "org_repos"
|
||||
)
|
||||
|
||||
// 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) {
|
||||
client := meta.(*gitea.Client)
|
||||
|
||||
|
@ -62,7 +89,8 @@ func resourceOrgRead(d *schema.ResourceData, meta interface{}) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
err = setOrgResourceData(org, d)
|
||||
repos, _ := getAllOrgRepos(client, org.UserName)
|
||||
err = setOrgResourceData(org, d, &repos)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -85,7 +113,8 @@ func resourceOrgCreate(d *schema.ResourceData, meta interface{}) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
err = setOrgResourceData(org, d)
|
||||
repos, _ := getAllOrgRepos(client, org.UserName)
|
||||
err = setOrgResourceData(org, d, &repos)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -118,7 +147,8 @@ func resourceOrgUpdate(d *schema.ResourceData, meta interface{}) (err error) {
|
|||
|
||||
org, resp, err = client.GetOrg(d.Get(orgName).(string))
|
||||
|
||||
err = setOrgResourceData(org, d)
|
||||
repos, _ := getAllOrgRepos(client, org.UserName)
|
||||
err = setOrgResourceData(org, d, &repos)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -141,7 +171,7 @@ func resourceOrgDelete(d *schema.ResourceData, meta interface{}) (err error) {
|
|||
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.Set("name", org.UserName)
|
||||
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("location", org.Location)
|
||||
d.Set("visibility", org.Visibility)
|
||||
d.Set("repos", repos)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -211,6 +242,13 @@ func resourceGiteaOrg() *schema.Resource {
|
|||
Default: "public",
|
||||
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" +
|
||||
"Organisations are a way to group repositories and abstract permission management in a gitea instance.",
|
||||
|
|
Loading…
Reference in a new issue