1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14 type PreReceiveHook struct {
15 ID *int64 `json:"id,omitempty"`
16 Name *string `json:"name,omitempty"`
17 Enforcement *string `json:"enforcement,omitempty"`
18 ConfigURL *string `json:"configuration_url,omitempty"`
19 }
20
21 func (p PreReceiveHook) String() string {
22 return Stringify(p)
23 }
24
25
26
27
28 func (s *RepositoriesService) ListPreReceiveHooks(ctx context.Context, owner, repo string, opts *ListOptions) ([]*PreReceiveHook, *Response, error) {
29 u := fmt.Sprintf("repos/%v/%v/pre-receive-hooks", owner, repo)
30 u, err := addOptions(u, opts)
31 if err != nil {
32 return nil, nil, err
33 }
34
35 req, err := s.client.NewRequest("GET", u, nil)
36 if err != nil {
37 return nil, nil, err
38 }
39
40
41 req.Header.Set("Accept", mediaTypePreReceiveHooksPreview)
42
43 var hooks []*PreReceiveHook
44 resp, err := s.client.Do(ctx, req, &hooks)
45 if err != nil {
46 return nil, resp, err
47 }
48
49 return hooks, resp, nil
50 }
51
52
53
54
55 func (s *RepositoriesService) GetPreReceiveHook(ctx context.Context, owner, repo string, id int64) (*PreReceiveHook, *Response, error) {
56 u := fmt.Sprintf("repos/%v/%v/pre-receive-hooks/%d", owner, repo, id)
57 req, err := s.client.NewRequest("GET", u, nil)
58 if err != nil {
59 return nil, nil, err
60 }
61
62
63 req.Header.Set("Accept", mediaTypePreReceiveHooksPreview)
64
65 h := new(PreReceiveHook)
66 resp, err := s.client.Do(ctx, req, h)
67 if err != nil {
68 return nil, resp, err
69 }
70
71 return h, resp, nil
72 }
73
74
75
76
77 func (s *RepositoriesService) UpdatePreReceiveHook(ctx context.Context, owner, repo string, id int64, hook *PreReceiveHook) (*PreReceiveHook, *Response, error) {
78 u := fmt.Sprintf("repos/%v/%v/pre-receive-hooks/%d", owner, repo, id)
79 req, err := s.client.NewRequest("PATCH", u, hook)
80 if err != nil {
81 return nil, nil, err
82 }
83
84
85 req.Header.Set("Accept", mediaTypePreReceiveHooksPreview)
86
87 h := new(PreReceiveHook)
88 resp, err := s.client.Do(ctx, req, h)
89 if err != nil {
90 return nil, resp, err
91 }
92
93 return h, resp, nil
94 }
95
96
97
98
99 func (s *RepositoriesService) DeletePreReceiveHook(ctx context.Context, owner, repo string, id int64) (*Response, error) {
100 u := fmt.Sprintf("repos/%v/%v/pre-receive-hooks/%d", owner, repo, id)
101 req, err := s.client.NewRequest("DELETE", u, nil)
102 if err != nil {
103 return nil, err
104 }
105
106
107 req.Header.Set("Accept", mediaTypePreReceiveHooksPreview)
108
109 return s.client.Do(ctx, req, nil)
110 }
111
View as plain text