1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14 type RepoStatus struct {
15 ID *int64 `json:"id,omitempty"`
16 NodeID *string `json:"node_id,omitempty"`
17 URL *string `json:"url,omitempty"`
18
19
20
21 State *string `json:"state,omitempty"`
22
23
24
25 TargetURL *string `json:"target_url,omitempty"`
26
27
28 Description *string `json:"description,omitempty"`
29
30
31 Context *string `json:"context,omitempty"`
32
33
34 AvatarURL *string `json:"avatar_url,omitempty"`
35
36 Creator *User `json:"creator,omitempty"`
37 CreatedAt *Timestamp `json:"created_at,omitempty"`
38 UpdatedAt *Timestamp `json:"updated_at,omitempty"`
39 }
40
41 func (r RepoStatus) String() string {
42 return Stringify(r)
43 }
44
45
46
47
48
49 func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref string, opts *ListOptions) ([]*RepoStatus, *Response, error) {
50 u := fmt.Sprintf("repos/%v/%v/commits/%v/statuses", owner, repo, refURLEscape(ref))
51 u, err := addOptions(u, opts)
52 if err != nil {
53 return nil, nil, err
54 }
55
56 req, err := s.client.NewRequest("GET", u, nil)
57 if err != nil {
58 return nil, nil, err
59 }
60
61 var statuses []*RepoStatus
62 resp, err := s.client.Do(ctx, req, &statuses)
63 if err != nil {
64 return nil, resp, err
65 }
66
67 return statuses, resp, nil
68 }
69
70
71
72
73
74 func (s *RepositoriesService) CreateStatus(ctx context.Context, owner, repo, ref string, status *RepoStatus) (*RepoStatus, *Response, error) {
75 u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, refURLEscape(ref))
76 req, err := s.client.NewRequest("POST", u, status)
77 if err != nil {
78 return nil, nil, err
79 }
80
81 repoStatus := new(RepoStatus)
82 resp, err := s.client.Do(ctx, req, repoStatus)
83 if err != nil {
84 return nil, resp, err
85 }
86
87 return repoStatus, resp, nil
88 }
89
90
91 type CombinedStatus struct {
92
93
94 State *string `json:"state,omitempty"`
95
96 Name *string `json:"name,omitempty"`
97 SHA *string `json:"sha,omitempty"`
98 TotalCount *int `json:"total_count,omitempty"`
99 Statuses []*RepoStatus `json:"statuses,omitempty"`
100
101 CommitURL *string `json:"commit_url,omitempty"`
102 RepositoryURL *string `json:"repository_url,omitempty"`
103 }
104
105 func (s CombinedStatus) String() string {
106 return Stringify(s)
107 }
108
109
110
111
112
113 func (s *RepositoriesService) GetCombinedStatus(ctx context.Context, owner, repo, ref string, opts *ListOptions) (*CombinedStatus, *Response, error) {
114 u := fmt.Sprintf("repos/%v/%v/commits/%v/status", owner, repo, refURLEscape(ref))
115 u, err := addOptions(u, opts)
116 if err != nil {
117 return nil, nil, err
118 }
119
120 req, err := s.client.NewRequest("GET", u, nil)
121 if err != nil {
122 return nil, nil, err
123 }
124
125 status := new(CombinedStatus)
126 resp, err := s.client.Do(ctx, req, status)
127 if err != nil {
128 return nil, resp, err
129 }
130
131 return status, resp, nil
132 }
133
View as plain text