forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
external_status_checks.go
90 lines (77 loc) · 2.77 KB
/
external_status_checks.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
package gitlab
import (
"fmt"
"net/http"
"time"
)
// ExternalStatusChecksService handles communication with the external
// status check related methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/status_checks.html
type ExternalStatusChecksService struct {
client *Client
}
type MergeStatusCheck struct {
ID int `json:"id"`
Name string `json:"name"`
ExternalURL string `json:"external_url"`
Status string `json:"status"`
}
type ProjectStatusCheck struct {
ID int `json:"id"`
Name string `json:"name"`
ProjectID int `json:"project_id"`
ExternalURL string `json:"external_url"`
ProtectedBranches []StatusCheckProtectedBranch `json:"protected_branches"`
}
type StatusCheckProtectedBranch struct {
ID int `json:"id"`
ProjectID int `json:"project_id"`
Name string `json:"name"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
CodeOwnerApprovalRequired bool `json:"code_owner_approval_required"`
}
// ListMergeStatusChecks lists the external status checks that apply to it
// and their status for a single merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#list-status-checks-for-a-merge-request
func (s *ExternalStatusChecksService) ListMergeStatusChecks(pid interface{}, mr int, opt *ListOptions, options ...RequestOptionFunc) ([]*MergeStatusCheck, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d/status_checks", PathEscape(project), mr)
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var mscs []*MergeStatusCheck
resp, err := s.client.Do(req, &mscs)
if err != nil {
return nil, resp, err
}
return mscs, resp, err
}
// ListProjectStatusChecks lists the project external status checks.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/status_checks.html#get-project-external-status-checks
func (s *ExternalStatusChecksService) ListProjectStatusChecks(pid interface{}, opt *ListOptions, options ...RequestOptionFunc) ([]*ProjectStatusCheck, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/external_status_checks", PathEscape(project))
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil {
return nil, nil, err
}
var pscs []*ProjectStatusCheck
resp, err := s.client.Do(req, &pscs)
if err != nil {
return nil, resp, err
}
return pscs, resp, err
}