Repository navigation
Expand file tree
/
Copy pathdata_source_github_organization_repositories.go
More file actions
86 lines (74 loc) · 2.25 KB
/
Copy pathdata_source_github_organization_repositories.go
File metadata and controls
86 lines (74 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package github
import (
"context"
"github.com/google/go-github/v92/github"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceGithubOrganizationRepositories() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceGithubOrganizationRepositoriesRead,
Description: "Data source to list all organization repositories.",
Schema: map[string]*schema.Schema{
"repositories": {
Description: "Organization repositories.",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Description: "ID of the repository.",
Type: schema.TypeInt,
Computed: true,
},
"node_id": {
Description: "Node ID of the repository.",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Name of the repository.",
Type: schema.TypeString,
Computed: true,
},
"visibility": {
Description: "Visibility of the repository; one of `public`, `private`, or `internal`.",
Type: schema.TypeString,
Computed: true,
},
"archived": {
Description: "Whether the repository is archived.",
Type: schema.TypeBool,
Computed: true,
},
},
},
},
},
}
}
func dataSourceGithubOrganizationRepositoriesRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
meta, _ := m.(*Owner)
if ok, diags := checkOrganizationOK(meta); !ok {
return diags
}
repos := make([]map[string]any, 0)
for repo, err := range meta.v3client.Repositories.ListByOrgIter(ctx, meta.name, &github.RepositoryListByOrgOptions{ListOptions: github.ListOptions{PerPage: meta.maxPerPage}}) {
if err != nil {
return diag.FromErr(err)
}
r := map[string]any{
"id": repo.GetID(),
"node_id": repo.GetNodeID(),
"name": repo.GetName(),
"visibility": repo.GetVisibility(),
"archived": repo.GetArchived(),
}
repos = append(repos, r)
}
d.SetId(meta.name)
if err := d.Set("repositories", repos); err != nil {
return diag.Errorf("error setting repositories: %v", err)
}
return nil
}