/
data_source_github_organization_webhooks.go
76 lines (64 loc) · 1.47 KB
/
data_source_github_organization_webhooks.go
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
package github
import (
"context"
"github.com/google/go-github/v57/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceGithubOrganizationWebhooks() *schema.Resource {
return &schema.Resource{
Read: dataSourceGithubOrganizationWebhooksRead,
Schema: map[string]*schema.Schema{
"webhooks": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"url": {
Type: schema.TypeString,
Computed: true,
},
"active": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
},
}
}
func dataSourceGithubOrganizationWebhooksRead(d *schema.ResourceData, meta interface{}) error {
owner := meta.(*Owner).name
client := meta.(*Owner).v3client
ctx := context.Background()
options := &github.ListOptions{
PerPage: 100,
}
results := make([]map[string]interface{}, 0)
for {
hooks, resp, err := client.Organizations.ListHooks(ctx, owner, options)
if err != nil {
return err
}
results = append(results, flattenGitHubWebhooks(hooks)...)
if resp.NextPage == 0 {
break
}
options.Page = resp.NextPage
}
d.SetId(owner)
d.Set("webhooks", results)
return nil
}