1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14 type Subscription struct {
15 Subscribed *bool `json:"subscribed,omitempty"`
16 Ignored *bool `json:"ignored,omitempty"`
17 Reason *string `json:"reason,omitempty"`
18 CreatedAt *Timestamp `json:"created_at,omitempty"`
19 URL *string `json:"url,omitempty"`
20
21
22 RepositoryURL *string `json:"repository_url,omitempty"`
23
24
25 ThreadURL *string `json:"thread_url,omitempty"`
26 }
27
28
29
30
31 func (s *ActivityService) ListWatchers(ctx context.Context, owner, repo string, opts *ListOptions) ([]*User, *Response, error) {
32 u := fmt.Sprintf("repos/%s/%s/subscribers", owner, repo)
33 u, err := addOptions(u, opts)
34 if err != nil {
35 return nil, nil, err
36 }
37
38 req, err := s.client.NewRequest("GET", u, nil)
39 if err != nil {
40 return nil, nil, err
41 }
42
43 var watchers []*User
44 resp, err := s.client.Do(ctx, req, &watchers)
45 if err != nil {
46 return nil, resp, err
47 }
48
49 return watchers, resp, nil
50 }
51
52
53
54
55
56
57 func (s *ActivityService) ListWatched(ctx context.Context, user string, opts *ListOptions) ([]*Repository, *Response, error) {
58 var u string
59 if user != "" {
60 u = fmt.Sprintf("users/%v/subscriptions", user)
61 } else {
62 u = "user/subscriptions"
63 }
64 u, err := addOptions(u, opts)
65 if err != nil {
66 return nil, nil, err
67 }
68
69 req, err := s.client.NewRequest("GET", u, nil)
70 if err != nil {
71 return nil, nil, err
72 }
73
74 var watched []*Repository
75 resp, err := s.client.Do(ctx, req, &watched)
76 if err != nil {
77 return nil, resp, err
78 }
79
80 return watched, resp, nil
81 }
82
83
84
85
86
87
88 func (s *ActivityService) GetRepositorySubscription(ctx context.Context, owner, repo string) (*Subscription, *Response, error) {
89 u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
90
91 req, err := s.client.NewRequest("GET", u, nil)
92 if err != nil {
93 return nil, nil, err
94 }
95
96 sub := new(Subscription)
97 resp, err := s.client.Do(ctx, req, sub)
98 if err != nil {
99
100 _, err = parseBoolResponse(err)
101 return nil, resp, err
102 }
103
104 return sub, resp, nil
105 }
106
107
108
109
110
111
112
113
114
115 func (s *ActivityService) SetRepositorySubscription(ctx context.Context, owner, repo string, subscription *Subscription) (*Subscription, *Response, error) {
116 u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
117
118 req, err := s.client.NewRequest("PUT", u, subscription)
119 if err != nil {
120 return nil, nil, err
121 }
122
123 sub := new(Subscription)
124 resp, err := s.client.Do(ctx, req, sub)
125 if err != nil {
126 return nil, resp, err
127 }
128
129 return sub, resp, nil
130 }
131
132
133
134
135
136
137
138
139 func (s *ActivityService) DeleteRepositorySubscription(ctx context.Context, owner, repo string) (*Response, error) {
140 u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
141 req, err := s.client.NewRequest("DELETE", u, nil)
142 if err != nil {
143 return nil, err
144 }
145
146 return s.client.Do(ctx, req, nil)
147 }
148
View as plain text