forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodespaces_machines.go
More file actions
74 lines (63 loc) · 2.47 KB
/
codespaces_machines.go
File metadata and controls
74 lines (63 loc) · 2.47 KB
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
// Copyright 2025 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"fmt"
)
// CodespacesMachines represent a list of machines.
type CodespacesMachines struct {
TotalCount int64 `json:"total_count"`
Machines []*CodespacesMachine `json:"machines"`
}
// ListRepoMachineTypesOptions represent options for ListMachineTypesForRepository.
type ListRepoMachineTypesOptions struct {
// Ref represent the branch or commit to check for prebuild availability and devcontainer restrictions.
Ref *string `url:"ref,omitempty"`
// Location represent the location to check for available machines. Assigned by IP if not provided.
Location *string `url:"location,omitempty"`
// ClientIP represent the IP for location auto-detection when proxying a request
ClientIP *string `url:"client_ip,omitempty"`
}
// ListRepositoryMachineTypes lists the machine types available for a given repository based on its configuration.
//
// GitHub API docs: https://docs.github.com/rest/codespaces/machines#list-available-machine-types-for-a-repository
//
//meta:operation GET /repos/{owner}/{repo}/codespaces/machines
func (s *CodespacesService) ListRepositoryMachineTypes(ctx context.Context, owner, repo string, opts *ListRepoMachineTypesOptions) (*CodespacesMachines, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/codespaces/machines", owner, repo)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var machines *CodespacesMachines
resp, err := s.client.Do(ctx, req, &machines)
if err != nil {
return nil, resp, err
}
return machines, resp, nil
}
// ListCodespaceMachineTypes lists the machine types a codespace can transition to use.
//
// GitHub API docs: https://docs.github.com/rest/codespaces/machines#list-machine-types-for-a-codespace
//
//meta:operation GET /user/codespaces/{codespace_name}/machines
func (s *CodespacesService) ListCodespaceMachineTypes(ctx context.Context, codespaceName string) (*CodespacesMachines, *Response, error) {
u := fmt.Sprintf("user/codespaces/%v/machines", codespaceName)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var machines *CodespacesMachines
resp, err := s.client.Do(ctx, req, &machines)
if err != nil {
return nil, resp, err
}
return machines, resp, nil
}