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 Creator *User `json:"creator,omitempty"`
35 CreatedAt *time.Time `json:"created_at,omitempty"`
36 UpdatedAt *time.Time `json:"updated_at,omitempty"`
37 }
38
39 func (r RepoStatus) String() string {
40 return Stringify(r)
41 }
42
43
44
45
46
47 func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref string, opts *ListOptions) ([]*RepoStatus, *Response, error) {
48 u := fmt.Sprintf("repos/%v/%v/commits/%v/statuses", owner, repo, refURLEscape(ref))
49 u, err := addOptions(u, opts)
50 if err != nil {
51 return nil, nil, err
52 }
53
54 req, err := s.client.NewRequest("GET", u, nil)
55 if err != nil {
56 return nil, nil, err
57 }
58
59 var statuses []*RepoStatus
60 resp, err := s.client.Do(ctx, req, &statuses)
61 if err != nil {
62 return nil, resp, err
63 }
64
65 return statuses, resp, nil
66 }
67
68
69
70
71
72 func (s *RepositoriesService) CreateStatus(ctx context.Context, owner, repo, ref string, status *RepoStatus) (*RepoStatus, *Response, error) {
73 u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, refURLEscape(ref))
74 req, err := s.client.NewRequest("POST", u, status)
75 if err != nil {
76 return nil, nil, err
77 }
78
79 repoStatus := new(RepoStatus)
80 resp, err := s.client.Do(ctx, req, repoStatus)
81 if err != nil {
82 return nil, resp, err
83 }
84
85 return repoStatus, resp, nil
86 }
87
88
89 type CombinedStatus struct {
90
91
92 State *string `json:"state,omitempty"`
93
94 Name *string `json:"name,omitempty"`
95 SHA *string `json:"sha,omitempty"`
96 TotalCount *int `json:"total_count,omitempty"`
97 Statuses []*RepoStatus `json:"statuses,omitempty"`
98
99 CommitURL *string `json:"commit_url,omitempty"`
100 RepositoryURL *string `json:"repository_url,omitempty"`
101 }
102
103 func (s CombinedStatus) String() string {
104 return Stringify(s)
105 }
106
107
108
109
110
111 func (s *RepositoriesService) GetCombinedStatus(ctx context.Context, owner, repo, ref string, opts *ListOptions) (*CombinedStatus, *Response, error) {
112 u := fmt.Sprintf("repos/%v/%v/commits/%v/status", owner, repo, refURLEscape(ref))
113 u, err := addOptions(u, opts)
114 if err != nil {
115 return nil, nil, err
116 }
117
118 req, err := s.client.NewRequest("GET", u, nil)
119 if err != nil {
120 return nil, nil, err
121 }
122
123 status := new(CombinedStatus)
124 resp, err := s.client.Do(ctx, req, status)
125 if err != nil {
126 return nil, resp, err
127 }
128
129 return status, resp, nil
130 }
131
View as plain text