forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_tracking.go
196 lines (168 loc) · 5.89 KB
/
error_tracking.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// Copyright 2022, Ryan Glab <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"net/http"
)
// ErrorTrackingService handles communication with the error tracking
// methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/error_tracking.html
type ErrorTrackingService struct {
client *Client
}
// ErrorTrackingClientKey represents an error tracking client key.
//
// GitLab docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#error-tracking-client-keys
type ErrorTrackingClientKey struct {
ID int `json:"id"`
Active bool `json:"active"`
PublicKey string `json:"public_key"`
SentryDsn string `json:"sentry_dsn"`
}
func (p ErrorTrackingClientKey) String() string {
return Stringify(p)
}
// ErrorTrackingSettings represents error tracking settings for a GitLab project.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/error_tracking.html
type ErrorTrackingSettings struct {
Active bool `json:"active"`
ProjectName string `json:"project_name"`
SentryExternalURL string `json:"sentry_external_url"`
APIURL string `json:"api_url"`
Integrated bool `json:"integrated"`
}
func (p ErrorTrackingSettings) String() string {
return Stringify(p)
}
// GetErrorTrackingSettings gets error tracking settings.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#get-error-tracking-settings
func (s *ErrorTrackingService) GetErrorTrackingSettings(pid interface{}, options ...RequestOptionFunc) (*ErrorTrackingSettings, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/error_tracking/settings", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
ets := new(ErrorTrackingSettings)
resp, err := s.client.Do(req, ets)
if err != nil {
return nil, resp, err
}
return ets, resp, err
}
// EnableDisableErrorTrackingOptions represents the available
// EnableDisableErrorTracking() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#enable-or-disable-the-error-tracking-project-settings
type EnableDisableErrorTrackingOptions struct {
Active *bool `url:"active,omitempty" json:"active,omitempty"`
Integrated *bool `url:"integrated,omitempty" json:"integrated,omitempty"`
}
// EnableDisableErrorTracking allows you to enable or disable the error tracking
// settings for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#enable-or-disable-the-error-tracking-project-settings
func (s *ErrorTrackingService) EnableDisableErrorTracking(pid interface{}, opt *EnableDisableErrorTrackingOptions, options ...RequestOptionFunc) (*ErrorTrackingSettings, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/error_tracking/settings", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPatch, u, opt, options)
if err != nil {
return nil, nil, err
}
ets := new(ErrorTrackingSettings)
resp, err := s.client.Do(req, &ets)
if err != nil {
return nil, resp, err
}
return ets, resp, err
}
// ListClientKeysOptions represents the available ListClientKeys() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#list-project-client-keys
type ListClientKeysOptions ListOptions
// ListClientKeys lists error tracking project client keys.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#list-project-client-keys
func (s *ErrorTrackingService) ListClientKeys(pid interface{}, opt *ListClientKeysOptions, options ...RequestOptionFunc) ([]*ErrorTrackingClientKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/error_tracking/client_keys", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var cks []*ErrorTrackingClientKey
resp, err := s.client.Do(req, &cks)
if err != nil {
return nil, resp, err
}
return cks, resp, err
}
// CreateClientKey creates a new client key for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#create-a-client-key
func (s *ErrorTrackingService) CreateClientKey(pid interface{}, options ...RequestOptionFunc) (*ErrorTrackingClientKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/error_tracking/client_keys", PathEscape(project))
req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return nil, nil, err
}
ck := new(ErrorTrackingClientKey)
resp, err := s.client.Do(req, ck)
if err != nil {
return nil, resp, err
}
return ck, resp, err
}
// DeleteClientKey removes a client key from the project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/error_tracking.html#delete-a-client-key
func (s *ErrorTrackingService) DeleteClientKey(pid interface{}, keyID int, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/error_tracking/client_keys/%d", PathEscape(project), keyID)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}