@@ -30,12 +30,30 @@ type Hook struct {
30
30
Created time.Time `json:"created_at"`
31
31
}
32
32
33
+ // ListOrgHooks list all the hooks of one organization
34
+ func (c * Client ) ListOrgHooks (org string ) ([]* Hook , error ) {
35
+ hooks := make ([]* Hook , 0 , 10 )
36
+ return hooks , c .getParsedResponse ("GET" , fmt .Sprintf ("/orgs/%s/hooks" , org ), nil , nil , & hooks )
37
+ }
38
+
33
39
// ListRepoHooks list all the hooks of one repository
34
40
func (c * Client ) ListRepoHooks (user , repo string ) ([]* Hook , error ) {
35
41
hooks := make ([]* Hook , 0 , 10 )
36
42
return hooks , c .getParsedResponse ("GET" , fmt .Sprintf ("/repos/%s/%s/hooks" , user , repo ), nil , nil , & hooks )
37
43
}
38
44
45
+ // GetOrgHook get a hook of an organization
46
+ func (c * Client ) GetOrgHook (org string , id int64 ) (* Hook , error ) {
47
+ h := new (Hook )
48
+ return h , c .getParsedResponse ("GET" , fmt .Sprintf ("/orgs/%s/hooks/%d" , org , id ), nil , nil , h )
49
+ }
50
+
51
+ // GetRepoHook get a hook of a repository
52
+ func (c * Client ) GetRepoHook (user , repo string , id int64 ) (* Hook , error ) {
53
+ h := new (Hook )
54
+ return h , c .getParsedResponse ("GET" , fmt .Sprintf ("/repos/%s/%s/hooks/%d" , user , repo , id ), nil , nil , h )
55
+ }
56
+
39
57
// CreateHookOption options when create a hook
40
58
type CreateHookOption struct {
41
59
Type string `json:"type" binding:"Required"`
@@ -44,7 +62,17 @@ type CreateHookOption struct {
44
62
Active bool `json:"active"`
45
63
}
46
64
47
- // CreateRepoHook create one hook with options
65
+ // CreateOrgHook create one hook for an organization, with options
66
+ func (c * Client ) CreateOrgHook (org string , opt CreateHookOption ) (* Hook , error ) {
67
+ body , err := json .Marshal (& opt )
68
+ if err != nil {
69
+ return nil , err
70
+ }
71
+ h := new (Hook )
72
+ return h , c .getParsedResponse ("POST" , fmt .Sprintf ("/orgs/%s/hooks" , org ), jsonHeader , bytes .NewReader (body ), h )
73
+ }
74
+
75
+ // CreateRepoHook create one hook for a repository, with options
48
76
func (c * Client ) CreateRepoHook (user , repo string , opt CreateHookOption ) (* Hook , error ) {
49
77
body , err := json .Marshal (& opt )
50
78
if err != nil {
@@ -61,7 +89,17 @@ type EditHookOption struct {
61
89
Active * bool `json:"active"`
62
90
}
63
91
64
- // EditRepoHook modify one hook with hook id and options
92
+ // EditOrgHook modify one hook of an organization, with hook id and options
93
+ func (c * Client ) EditOrgHook (org string , id int64 , opt EditHookOption ) error {
94
+ body , err := json .Marshal (& opt )
95
+ if err != nil {
96
+ return err
97
+ }
98
+ _ , err = c .getResponse ("PATCH" , fmt .Sprintf ("/orgs/%s/hooks/%d" , org , id ), jsonHeader , bytes .NewReader (body ))
99
+ return err
100
+ }
101
+
102
+ // EditRepoHook modify one hook of a repository, with hook id and options
65
103
func (c * Client ) EditRepoHook (user , repo string , id int64 , opt EditHookOption ) error {
66
104
body , err := json .Marshal (& opt )
67
105
if err != nil {
@@ -71,7 +109,14 @@ func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) e
71
109
return err
72
110
}
73
111
74
- // DeleteRepoHook delete one hook with hook id
112
+ // DeleteOrgHook delete one hook from an organization, with hook id
113
+ func (c * Client ) DeleteOrgHook (org string , id int64 ) error {
114
+ _ , err := c .getResponse ("DELETE" , fmt .Sprintf ("/org/%s/hooks/%d" , org , id ), nil , nil )
115
+ return err
116
+ }
117
+
118
+
119
+ // DeleteRepoHook delete one hook from a repository, with hook id
75
120
func (c * Client ) DeleteRepoHook (user , repo string , id int64 ) error {
76
121
_ , err := c .getResponse ("DELETE" , fmt .Sprintf ("/repos/%s/%s/hooks/%d" , user , repo , id ), nil , nil )
77
122
return err
0 commit comments