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