1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14
15
16
17 type CodespacesService service
18
19
20
21
22 type Codespace struct {
23 ID *int64 `json:"id,omitempty"`
24 Name *string `json:"name,omitempty"`
25 DisplayName *string `json:"display_name,omitempty"`
26 EnvironmentID *string `json:"environment_id,omitempty"`
27 Owner *User `json:"owner,omitempty"`
28 BillableOwner *User `json:"billable_owner,omitempty"`
29 Repository *Repository `json:"repository,omitempty"`
30 Machine *CodespacesMachine `json:"machine,omitempty"`
31 DevcontainerPath *string `json:"devcontainer_path,omitempty"`
32 Prebuild *bool `json:"prebuild,omitempty"`
33 CreatedAt *Timestamp `json:"created_at,omitempty"`
34 UpdatedAt *Timestamp `json:"updated_at,omitempty"`
35 LastUsedAt *Timestamp `json:"last_used_at,omitempty"`
36 State *string `json:"state,omitempty"`
37 URL *string `json:"url,omitempty"`
38 GitStatus *CodespacesGitStatus `json:"git_status,omitempty"`
39 Location *string `json:"location,omitempty"`
40 IdleTimeoutMinutes *int `json:"idle_timeout_minutes,omitempty"`
41 WebURL *string `json:"web_url,omitempty"`
42 MachinesURL *string `json:"machines_url,omitempty"`
43 StartURL *string `json:"start_url,omitempty"`
44 StopURL *string `json:"stop_url,omitempty"`
45 PullsURL *string `json:"pulls_url,omitempty"`
46 RecentFolders []string `json:"recent_folders,omitempty"`
47 RuntimeConstraints *CodespacesRuntimeConstraints `json:"runtime_constraints,omitempty"`
48 PendingOperation *bool `json:"pending_operation,omitempty"`
49 PendingOperationDisabledReason *string `json:"pending_operation_disabled_reason,omitempty"`
50 IdleTimeoutNotice *string `json:"idle_timeout_notice,omitempty"`
51 RetentionPeriodMinutes *int `json:"retention_period_minutes,omitempty"`
52 RetentionExpiresAt *Timestamp `json:"retention_expires_at,omitempty"`
53 LastKnownStopNotice *string `json:"last_known_stop_notice,omitempty"`
54 }
55
56
57 type CodespacesGitStatus struct {
58 Ahead *int `json:"ahead,omitempty"`
59 Behind *int `json:"behind,omitempty"`
60 HasUnpushedChanges *bool `json:"has_unpushed_changes,omitempty"`
61 HasUncommittedChanges *bool `json:"has_uncommitted_changes,omitempty"`
62 Ref *string `json:"ref,omitempty"`
63 }
64
65
66 type CodespacesMachine struct {
67 Name *string `json:"name,omitempty"`
68 DisplayName *string `json:"display_name,omitempty"`
69 OperatingSystem *string `json:"operating_system,omitempty"`
70 StorageInBytes *int64 `json:"storage_in_bytes,omitempty"`
71 MemoryInBytes *int64 `json:"memory_in_bytes,omitempty"`
72 CPUs *int `json:"cpus,omitempty"`
73 PrebuildAvailability *string `json:"prebuild_availability,omitempty"`
74 }
75
76
77 type CodespacesRuntimeConstraints struct {
78 AllowedPortPrivacySettings []string `json:"allowed_port_privacy_settings,omitempty"`
79 }
80
81
82 type ListCodespaces struct {
83 TotalCount *int `json:"total_count,omitempty"`
84 Codespaces []*Codespace `json:"codespaces"`
85 }
86
87
88
89
90
91
92
93
94 func (s *CodespacesService) ListInRepo(ctx context.Context, owner, repo string, opts *ListOptions) (*ListCodespaces, *Response, error) {
95 u := fmt.Sprintf("repos/%v/%v/codespaces", owner, repo)
96 u, err := addOptions(u, opts)
97 if err != nil {
98 return nil, nil, err
99 }
100
101 req, err := s.client.NewRequest("GET", u, nil)
102 if err != nil {
103 return nil, nil, err
104 }
105
106 var codespaces *ListCodespaces
107 resp, err := s.client.Do(ctx, req, &codespaces)
108 if err != nil {
109 return nil, resp, err
110 }
111
112 return codespaces, resp, nil
113 }
114
115
116 type ListCodespacesOptions struct {
117 ListOptions
118 RepositoryID int64 `url:"repository_id,omitempty"`
119 }
120
121
122
123
124
125
126
127
128 func (s *CodespacesService) List(ctx context.Context, opts *ListCodespacesOptions) (*ListCodespaces, *Response, error) {
129 u := "user/codespaces"
130 u, err := addOptions(u, opts)
131 if err != nil {
132 return nil, nil, err
133 }
134
135 req, err := s.client.NewRequest("GET", u, nil)
136 if err != nil {
137 return nil, nil, err
138 }
139
140 var codespaces *ListCodespaces
141 resp, err := s.client.Do(ctx, req, &codespaces)
142 if err != nil {
143 return nil, resp, err
144 }
145
146 return codespaces, resp, nil
147 }
148
149
150 type CreateCodespaceOptions struct {
151 Ref *string `json:"ref,omitempty"`
152
153
154
155
156 Geo *string `json:"geo,omitempty"`
157 ClientIP *string `json:"client_ip,omitempty"`
158 Machine *string `json:"machine,omitempty"`
159 DevcontainerPath *string `json:"devcontainer_path,omitempty"`
160 MultiRepoPermissionsOptOut *bool `json:"multi_repo_permissions_opt_out,omitempty"`
161 WorkingDirectory *string `json:"working_directory,omitempty"`
162 IdleTimeoutMinutes *int `json:"idle_timeout_minutes,omitempty"`
163 DisplayName *string `json:"display_name,omitempty"`
164
165
166 RetentionPeriodMinutes *int `json:"retention_period_minutes,omitempty"`
167 }
168
169
170
171
172
173
174
175
176 func (s *CodespacesService) CreateInRepo(ctx context.Context, owner, repo string, request *CreateCodespaceOptions) (*Codespace, *Response, error) {
177 u := fmt.Sprintf("repos/%v/%v/codespaces", owner, repo)
178
179 req, err := s.client.NewRequest("POST", u, request)
180 if err != nil {
181 return nil, nil, err
182 }
183
184 var codespace *Codespace
185 resp, err := s.client.Do(ctx, req, &codespace)
186 if err != nil {
187 return nil, resp, err
188 }
189
190 return codespace, resp, nil
191 }
192
193
194
195
196
197
198
199 func (s *CodespacesService) Start(ctx context.Context, codespaceName string) (*Codespace, *Response, error) {
200 u := fmt.Sprintf("user/codespaces/%v/start", codespaceName)
201
202 req, err := s.client.NewRequest("POST", u, nil)
203 if err != nil {
204 return nil, nil, err
205 }
206
207 var codespace *Codespace
208 resp, err := s.client.Do(ctx, req, &codespace)
209 if err != nil {
210 return nil, resp, err
211 }
212
213 return codespace, resp, nil
214 }
215
216
217
218
219
220
221
222 func (s *CodespacesService) Stop(ctx context.Context, codespaceName string) (*Codespace, *Response, error) {
223 u := fmt.Sprintf("user/codespaces/%v/stop", codespaceName)
224
225 req, err := s.client.NewRequest("POST", u, nil)
226 if err != nil {
227 return nil, nil, err
228 }
229
230 var codespace *Codespace
231 resp, err := s.client.Do(ctx, req, &codespace)
232 if err != nil {
233 return nil, resp, err
234 }
235
236 return codespace, resp, nil
237 }
238
239
240
241
242
243
244
245 func (s *CodespacesService) Delete(ctx context.Context, codespaceName string) (*Response, error) {
246 u := fmt.Sprintf("user/codespaces/%v", codespaceName)
247
248 req, err := s.client.NewRequest("DELETE", u, nil)
249 if err != nil {
250 return nil, err
251 }
252
253 return s.client.Do(ctx, req, nil)
254 }
255
View as plain text