1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 "time"
23 )
24
25
26
27
28
29 type EventsService struct {
30 client *Client
31 }
32
33
34
35
36
37 type ContributionEvent struct {
38 ID int `json:"id"`
39 Title string `json:"title"`
40 ProjectID int `json:"project_id"`
41 ActionName string `json:"action_name"`
42 TargetID int `json:"target_id"`
43 TargetIID int `json:"target_iid"`
44 TargetType string `json:"target_type"`
45 AuthorID int `json:"author_id"`
46 TargetTitle string `json:"target_title"`
47 CreatedAt *time.Time `json:"created_at"`
48 PushData struct {
49 CommitCount int `json:"commit_count"`
50 Action string `json:"action"`
51 RefType string `json:"ref_type"`
52 CommitFrom string `json:"commit_from"`
53 CommitTo string `json:"commit_to"`
54 Ref string `json:"ref"`
55 CommitTitle string `json:"commit_title"`
56 } `json:"push_data"`
57 Note *Note `json:"note"`
58 Author struct {
59 Name string `json:"name"`
60 Username string `json:"username"`
61 ID int `json:"id"`
62 State string `json:"state"`
63 AvatarURL string `json:"avatar_url"`
64 WebURL string `json:"web_url"`
65 } `json:"author"`
66 AuthorUsername string `json:"author_username"`
67 }
68
69
70
71
72
73 type ListContributionEventsOptions struct {
74 ListOptions
75 Action *EventTypeValue `url:"action,omitempty" json:"action,omitempty"`
76 TargetType *EventTargetTypeValue `url:"target_type,omitempty" json:"target_type,omitempty"`
77 Before *ISOTime `url:"before,omitempty" json:"before,omitempty"`
78 After *ISOTime `url:"after,omitempty" json:"after,omitempty"`
79 Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
80 }
81
82
83
84
85
86
87 func (s *UsersService) ListUserContributionEvents(uid interface{}, opt *ListContributionEventsOptions, options ...RequestOptionFunc) ([]*ContributionEvent, *Response, error) {
88 user, err := parseID(uid)
89 if err != nil {
90 return nil, nil, err
91 }
92 u := fmt.Sprintf("users/%s/events", user)
93
94 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
95 if err != nil {
96 return nil, nil, err
97 }
98
99 var cs []*ContributionEvent
100 resp, err := s.client.Do(req, &cs)
101 if err != nil {
102 return nil, resp, err
103 }
104
105 return cs, resp, nil
106 }
107
108
109
110
111 func (s *EventsService) ListCurrentUserContributionEvents(opt *ListContributionEventsOptions, options ...RequestOptionFunc) ([]*ContributionEvent, *Response, error) {
112 req, err := s.client.NewRequest(http.MethodGet, "events", opt, options)
113 if err != nil {
114 return nil, nil, err
115 }
116
117 var cs []*ContributionEvent
118 resp, err := s.client.Do(req, &cs)
119 if err != nil {
120 return nil, resp, err
121 }
122
123 return cs, resp, nil
124 }
125
126
127
128
129
130 type ProjectEvent struct {
131 ID int `json:"id"`
132 Title string `json:"title"`
133 ProjectID int `json:"project_id"`
134 ActionName string `json:"action_name"`
135 TargetID int `json:"target_id"`
136 TargetIID int `json:"target_iid"`
137 TargetType string `json:"target_type"`
138 AuthorID int `json:"author_id"`
139 TargetTitle string `json:"target_title"`
140 CreatedAt string `json:"created_at"`
141 Author struct {
142 Name string `json:"name"`
143 Username string `json:"username"`
144 ID int `json:"id"`
145 State string `json:"state"`
146 AvatarURL string `json:"avatar_url"`
147 WebURL string `json:"web_url"`
148 } `json:"author"`
149 AuthorUsername string `json:"author_username"`
150 Data struct {
151 Before string `json:"before"`
152 After string `json:"after"`
153 Ref string `json:"ref"`
154 UserID int `json:"user_id"`
155 UserName string `json:"user_name"`
156 Repository *Repository `json:"repository"`
157 Commits []*Commit `json:"commits"`
158 TotalCommitsCount int `json:"total_commits_count"`
159 } `json:"data"`
160 Note struct {
161 ID int `json:"id"`
162 Body string `json:"body"`
163 Attachment string `json:"attachment"`
164 Author struct {
165 ID int `json:"id"`
166 Username string `json:"username"`
167 Email string `json:"email"`
168 Name string `json:"name"`
169 State string `json:"state"`
170 AvatarURL string `json:"avatar_url"`
171 WebURL string `json:"web_url"`
172 } `json:"author"`
173 CreatedAt *time.Time `json:"created_at"`
174 System bool `json:"system"`
175 NoteableID int `json:"noteable_id"`
176 NoteableType string `json:"noteable_type"`
177 NoteableIID int `json:"noteable_iid"`
178 } `json:"note"`
179 PushData struct {
180 CommitCount int `json:"commit_count"`
181 Action string `json:"action"`
182 RefType string `json:"ref_type"`
183 CommitFrom string `json:"commit_from"`
184 CommitTo string `json:"commit_to"`
185 Ref string `json:"ref"`
186 CommitTitle string `json:"commit_title"`
187 } `json:"push_data"`
188 }
189
190 func (s ProjectEvent) String() string {
191 return Stringify(s)
192 }
193
194
195
196
197
198
199 type ListProjectVisibleEventsOptions struct {
200 ListOptions
201 Action *EventTypeValue `url:"action,omitempty" json:"action,omitempty"`
202 TargetType *EventTargetTypeValue `url:"target_type,omitempty" json:"target_type,omitempty"`
203 Before *ISOTime `url:"before,omitempty" json:"before,omitempty"`
204 After *ISOTime `url:"after,omitempty" json:"after,omitempty"`
205 Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
206 }
207
208
209
210
211
212 func (s *EventsService) ListProjectVisibleEvents(pid interface{}, opt *ListProjectVisibleEventsOptions, options ...RequestOptionFunc) ([]*ProjectEvent, *Response, error) {
213 project, err := parseID(pid)
214 if err != nil {
215 return nil, nil, err
216 }
217 u := fmt.Sprintf("projects/%s/events", PathEscape(project))
218
219 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
220 if err != nil {
221 return nil, nil, err
222 }
223
224 var p []*ProjectEvent
225 resp, err := s.client.Do(req, &p)
226 if err != nil {
227 return nil, resp, err
228 }
229
230 return p, resp, nil
231 }
232
View as plain text