1 package gitlab
2
3 import (
4 "fmt"
5 "net/http"
6 "time"
7 )
8
9
10
11
12
13 type ExternalStatusChecksService struct {
14 client *Client
15 }
16
17 type MergeStatusCheck struct {
18 ID int `json:"id"`
19 Name string `json:"name"`
20 ExternalURL string `json:"external_url"`
21 Status string `json:"status"`
22 }
23
24 type ProjectStatusCheck struct {
25 ID int `json:"id"`
26 Name string `json:"name"`
27 ProjectID int `json:"project_id"`
28 ExternalURL string `json:"external_url"`
29 ProtectedBranches []StatusCheckProtectedBranch `json:"protected_branches"`
30 }
31
32 type StatusCheckProtectedBranch struct {
33 ID int `json:"id"`
34 ProjectID int `json:"project_id"`
35 Name string `json:"name"`
36 CreatedAt *time.Time `json:"created_at"`
37 UpdatedAt *time.Time `json:"updated_at"`
38 CodeOwnerApprovalRequired bool `json:"code_owner_approval_required"`
39 }
40
41
42
43
44
45
46 func (s *ExternalStatusChecksService) ListMergeStatusChecks(pid interface{}, mr int, opt *ListOptions, options ...RequestOptionFunc) ([]*MergeStatusCheck, *Response, error) {
47 project, err := parseID(pid)
48 if err != nil {
49 return nil, nil, err
50 }
51 u := fmt.Sprintf("projects/%s/merge_requests/%d/status_checks", PathEscape(project), mr)
52
53 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
54 if err != nil {
55 return nil, nil, err
56 }
57
58 var mscs []*MergeStatusCheck
59 resp, err := s.client.Do(req, &mscs)
60 if err != nil {
61 return nil, resp, err
62 }
63
64 return mscs, resp, nil
65 }
66
67
68
69
70
71
72 type SetExternalStatusCheckStatusOptions struct {
73 SHA *string `url:"sha,omitempty" json:"sha,omitempty"`
74 ExternalStatusCheckID *int `url:"external_status_check_id,omitempty" json:"external_status_check_id,omitempty"`
75 Status *string `url:"status,omitempty" json:"status,omitempty"`
76 }
77
78
79
80
81
82 func (s *ExternalStatusChecksService) SetExternalStatusCheckStatus(pid interface{}, mergeRequest int, opt *SetExternalStatusCheckStatusOptions, options ...RequestOptionFunc) (*Response, error) {
83 project, err := parseID(pid)
84 if err != nil {
85 return nil, err
86 }
87 u := fmt.Sprintf("projects/%s/merge_requests/%d/status_check_responses", PathEscape(project), mergeRequest)
88
89 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
90 if err != nil {
91 return nil, err
92 }
93
94 return s.client.Do(req, nil)
95 }
96
97
98
99
100
101 func (s *ExternalStatusChecksService) ListProjectStatusChecks(pid interface{}, opt *ListOptions, options ...RequestOptionFunc) ([]*ProjectStatusCheck, *Response, error) {
102 project, err := parseID(pid)
103 if err != nil {
104 return nil, nil, err
105 }
106 u := fmt.Sprintf("projects/%s/external_status_checks", PathEscape(project))
107
108 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
109 if err != nil {
110 return nil, nil, err
111 }
112
113 var pscs []*ProjectStatusCheck
114 resp, err := s.client.Do(req, &pscs)
115 if err != nil {
116 return nil, resp, err
117 }
118
119 return pscs, resp, nil
120 }
121
122
123
124
125
126
127 type CreateExternalStatusCheckOptions struct {
128 Name *string `url:"name,omitempty" json:"name,omitempty"`
129 ExternalURL *string `url:"external_url,omitempty" json:"external_url,omitempty"`
130 ProtectedBranchIDs *[]int `url:"protected_branch_ids,omitempty" json:"protected_branch_ids,omitempty"`
131 }
132
133
134
135
136
137 func (s *ExternalStatusChecksService) CreateExternalStatusCheck(pid interface{}, opt *CreateExternalStatusCheckOptions, options ...RequestOptionFunc) (*Response, error) {
138 project, err := parseID(pid)
139 if err != nil {
140 return nil, err
141 }
142 u := fmt.Sprintf("projects/%s/external_status_checks", PathEscape(project))
143
144 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
145 if err != nil {
146 return nil, err
147 }
148
149 return s.client.Do(req, nil)
150 }
151
152
153
154
155
156 func (s *ExternalStatusChecksService) DeleteExternalStatusCheck(pid interface{}, check int, options ...RequestOptionFunc) (*Response, error) {
157 project, err := parseID(pid)
158 if err != nil {
159 return nil, err
160 }
161 u := fmt.Sprintf("projects/%s/external_status_checks/%d", PathEscape(project), check)
162
163 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
164 if err != nil {
165 return nil, err
166 }
167
168 return s.client.Do(req, nil)
169 }
170
171
172
173
174
175
176 type UpdateExternalStatusCheckOptions struct {
177 Name *string `url:"name,omitempty" json:"name,omitempty"`
178 ExternalURL *string `url:"external_url,omitempty" json:"external_url,omitempty"`
179 ProtectedBranchIDs *[]int `url:"protected_branch_ids,omitempty" json:"protected_branch_ids,omitempty"`
180 }
181
182
183
184
185
186 func (s *ExternalStatusChecksService) UpdateExternalStatusCheck(pid interface{}, check int, opt *UpdateExternalStatusCheckOptions, options ...RequestOptionFunc) (*Response, error) {
187 project, err := parseID(pid)
188 if err != nil {
189 return nil, err
190 }
191 u := fmt.Sprintf("projects/%s/external_status_checks/%d", PathEscape(project), check)
192
193 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
194 if err != nil {
195 return nil, err
196 }
197
198 return s.client.Do(req, nil)
199 }
200
View as plain text