Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ linters:
- AddProjectItemOptions
- AuthorizationRequest
- CodeScanningAlertState
- CodespaceCreateForUserOptions
- ConfigApplyOptions
- ConfigSettings
- CreateCodespaceOptions
- CreateOrUpdateIssueTypesOptions
- CreateOrgInvitationOptions
- CreateUpdateEnvironment
Expand All @@ -229,7 +227,6 @@ linters:
- PagesUpdate
- PagesUpdateWithoutCNAME
- ProtectionRequest
- PublishCodespaceOptions
- PullRequestBranchUpdateOptions
- PullRequestReviewRequest
- PullRequestReviewsEnforcementUpdate
Expand All @@ -246,7 +243,6 @@ linters:
- TeamAddTeamMembershipOptions
- TeamAddTeamRepoOptions
- TeamProjectOptions
- UpdateCodespaceOptions
- UpdateDefaultSetupConfigurationOptions
- UpdateProjectItemOptions
- UserSuspendOptions
Expand All @@ -256,18 +252,15 @@ linters:
body-allowed-wrong-names:
- AddProjectItemOptions
- CheckSuitePreferenceOptions
- CodespaceCreateForUserOptions
- ConfigApplyOptions
- CreateCheckRunOptions
- CreateCheckSuiteOptions
- CreateCodespaceOptions
- CreateOrUpdateIssueTypesOptions
- CreateOrgInvitationOptions
- InstallationTokenListRepoOptions
- InstallationTokenOptions
- LockIssueOptions
- MaintenanceOptions
- PublishCodespaceOptions
- PullRequestBranchUpdateOptions
- RepositoryAddCollaboratorOptions
- RepositoryContentFileOptions
Expand All @@ -278,7 +271,6 @@ linters:
- TeamAddTeamRepoOptions
- TeamProjectOptions
- UpdateCheckRunOptions
- UpdateCodespaceOptions
- UpdateDefaultSetupConfigurationOptions
- UpdateProjectItemOptions
- UserSuspendOptions
Expand Down
34 changes: 18 additions & 16 deletions github/codespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func (s *CodespacesService) List(ctx context.Context, opts *ListCodespacesOption
return codespaces, resp, nil
}

// CreateCodespaceOptions represents options for the creation of a codespace in a repository.
type CreateCodespaceOptions struct {
// CreateCodespaceRequest represents a request to create a codespace in a repository.
type CreateCodespaceRequest struct {
Ref *string `json:"ref,omitempty"`
// Geo represents the geographic area for this codespace.
// If not specified, the value is assigned by IP.
Expand Down Expand Up @@ -212,11 +212,11 @@ type CodespacePullRequestOptions struct {
RepositoryID int64 `json:"repository_id"`
}

// CodespaceCreateForUserOptions represents options for creating a codespace for the authenticated user.
type CodespaceCreateForUserOptions struct {
PullRequest *CodespacePullRequestOptions `json:"pull_request"`
// CreateCodespaceForUserRequest represents a request to create a codespace for the authenticated user.
type CreateCodespaceForUserRequest struct {
PullRequest *CodespacePullRequestOptions `json:"pull_request,omitempty"`
// RepositoryID represents the repository ID for this codespace.
RepositoryID int64 `json:"repository_id"`
RepositoryID *int64 `json:"repository_id,omitempty"`
Ref *string `json:"ref,omitempty"`
Geo *string `json:"geo,omitempty"`
ClientIP *string `json:"client_ip,omitempty"`
Expand All @@ -230,10 +230,12 @@ type CodespaceCreateForUserOptions struct {
DisplayName *string `json:"display_name,omitempty"`
}

// UpdateCodespaceOptions represents options for updating a codespace.
type UpdateCodespaceOptions struct {
// UpdateCodespaceRequest represents a request to update a codespace.
type UpdateCodespaceRequest struct {
// Machine represents a valid machine to transition this codespace to.
Machine *string `json:"machine,omitempty"`
// DisplayName represents the display name for this codespace.
DisplayName *string `json:"display_name,omitempty"`
// RecentFolders represents the recently opened folders inside the codespace.
// It is currently used by the clients to determine the folder path to load the codespace in.
RecentFolders []string `json:"recent_folders,omitempty"`
Expand All @@ -251,8 +253,8 @@ type CodespaceExport struct {
HTMLURL *string `json:"html_url,omitempty"`
}

// PublishCodespaceOptions represents options for creating a repository from an unpublished codespace.
type PublishCodespaceOptions struct {
// PublishCodespaceRequest represents a request to create a repository from an unpublished codespace.
type PublishCodespaceRequest struct {
// Name represents the name of the new repository.
Name *string `json:"name,omitempty"`
// Private represents whether the new repository is private. Defaults to false.
Expand All @@ -273,7 +275,7 @@ type CodespacePermissions struct {
// GitHub API docs: https://docs.github.com/rest/codespaces/codespaces?apiVersion=2022-11-28#create-a-codespace-in-a-repository
//
//meta:operation POST /repos/{owner}/{repo}/codespaces
func (s *CodespacesService) CreateInRepo(ctx context.Context, owner, repo string, body *CreateCodespaceOptions) (*Codespace, *Response, error) {
func (s *CodespacesService) CreateInRepo(ctx context.Context, owner, repo string, body CreateCodespaceRequest) (*Codespace, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/codespaces", owner, repo)
req, err := s.client.NewRequest(ctx, "POST", u, body)
if err != nil {
Expand Down Expand Up @@ -444,7 +446,7 @@ func (s *CodespacesService) CheckPermissions(ctx context.Context, owner, repo, r
// GitHub API docs: https://docs.github.com/rest/codespaces/codespaces?apiVersion=2022-11-28#create-a-codespace-from-a-pull-request
//
//meta:operation POST /repos/{owner}/{repo}/pulls/{pull_number}/codespaces
func (s *CodespacesService) CreateFromPullRequest(ctx context.Context, owner, repo string, pullNumber int, body *CreateCodespaceOptions) (*Codespace, *Response, error) {
func (s *CodespacesService) CreateFromPullRequest(ctx context.Context, owner, repo string, pullNumber int, body CreateCodespaceRequest) (*Codespace, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%v/codespaces", owner, repo, pullNumber)
req, err := s.client.NewRequest(ctx, "POST", u, body)
if err != nil {
Expand All @@ -462,12 +464,12 @@ func (s *CodespacesService) CreateFromPullRequest(ctx context.Context, owner, re

// Create creates a new codespace, owned by the authenticated user.
//
// This method requires either RepositoryId OR a PullRequest but not both.
// This method requires either RepositoryID or PullRequest to be set, but not both.
//
// GitHub API docs: https://docs.github.com/rest/codespaces/codespaces?apiVersion=2022-11-28#create-a-codespace-for-the-authenticated-user
//
//meta:operation POST /user/codespaces
func (s *CodespacesService) Create(ctx context.Context, body *CodespaceCreateForUserOptions) (*Codespace, *Response, error) {
func (s *CodespacesService) Create(ctx context.Context, body CreateCodespaceForUserRequest) (*Codespace, *Response, error) {
u := "user/codespaces"
req, err := s.client.NewRequest(ctx, "POST", u, body)
if err != nil {
Expand Down Expand Up @@ -511,7 +513,7 @@ func (s *CodespacesService) Get(ctx context.Context, codespaceName string) (*Cod
// GitHub API docs: https://docs.github.com/rest/codespaces/codespaces?apiVersion=2022-11-28#update-a-codespace-for-the-authenticated-user
//
//meta:operation PATCH /user/codespaces/{codespace_name}
func (s *CodespacesService) Update(ctx context.Context, codespaceName string, body *UpdateCodespaceOptions) (*Codespace, *Response, error) {
func (s *CodespacesService) Update(ctx context.Context, codespaceName string, body UpdateCodespaceRequest) (*Codespace, *Response, error) {
u := fmt.Sprintf("user/codespaces/%v", codespaceName)
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
if err != nil {
Expand Down Expand Up @@ -574,7 +576,7 @@ func (s *CodespacesService) GetLatestCodespaceExport(ctx context.Context, codesp
// GitHub API docs: https://docs.github.com/rest/codespaces/codespaces?apiVersion=2022-11-28#create-a-repository-from-an-unpublished-codespace
//
//meta:operation POST /user/codespaces/{codespace_name}/publish
func (s *CodespacesService) Publish(ctx context.Context, codespaceName string, body *PublishCodespaceOptions) (*Codespace, *Response, error) {
func (s *CodespacesService) Publish(ctx context.Context, codespaceName string, body PublishCodespaceRequest) (*Codespace, *Response, error) {
u := fmt.Sprintf("user/codespaces/%v/publish", codespaceName)
req, err := s.client.NewRequest(ctx, "POST", u, body)
if err != nil {
Expand Down
51 changes: 35 additions & 16 deletions github/codespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestCodespacesService_CreateInRepo(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

input := &CreateCodespaceOptions{
input := CreateCodespaceRequest{
Ref: new("main"),
Geo: new("WestUs2"),
Machine: new("standardLinux"),
Expand Down Expand Up @@ -451,7 +451,7 @@ func TestCodespacesService_CreateFromPullRequest(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

input := &CreateCodespaceOptions{
input := CreateCodespaceRequest{
Machine: new("standardLinux"),
IdleTimeoutMinutes: new(60),
}
Expand Down Expand Up @@ -497,25 +497,25 @@ func TestCodespacesService_Create(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

opt := &CodespaceCreateForUserOptions{
input := CreateCodespaceForUserRequest{
Ref: new("main"),
Geo: new("WestUs2"),
Machine: new("standardLinux"),
IdleTimeoutMinutes: new(60),
RepositoryID: int64(111),
RepositoryID: new(int64(111)),
PullRequest: nil,
}

mux.HandleFunc("/user/codespaces", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testJSONBody(t, r, opt)
testJSONBody(t, r, input)
fmt.Fprint(w, `{"id":1,"repository":{"id":111}}`)
})

ctx := t.Context()
codespace, _, err := client.Codespaces.Create(
ctx,
opt,
input,
)
if err != nil {
t.Fatalf("Codespaces.Create returned error: %v", err)
Expand All @@ -536,7 +536,7 @@ func TestCodespacesService_Create(t *testing.T) {
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Codespaces.Create(
ctx,
opt,
input,
)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
Expand All @@ -545,6 +545,24 @@ func TestCodespacesService_Create(t *testing.T) {
})
}

func TestCreateCodespaceForUserRequest_Marshal(t *testing.T) {
t.Parallel()

repoInput := CreateCodespaceForUserRequest{
RepositoryID: new(int64(111)),
Ref: new("main"),
}
testJSONMarshal(t, repoInput, `{"repository_id":111,"ref":"main"}`)

pullRequestInput := CreateCodespaceForUserRequest{
PullRequest: &CodespacePullRequestOptions{
PullRequestNumber: 42,
RepositoryID: 111,
},
}
testJSONMarshal(t, pullRequestInput, `{"pull_request":{"pull_request_number":42,"repository_id":111}}`)
}

func TestCodespacesService_Get(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
Expand Down Expand Up @@ -585,8 +603,9 @@ func TestCodespacesService_Update(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

opt := &UpdateCodespaceOptions{
Machine: new("standardLinux"),
input := UpdateCodespaceRequest{
Machine: new("standardLinux"),
DisplayName: new("my codespace"),
RecentFolders: []string{
"folder1",
"folder2",
Expand All @@ -595,15 +614,15 @@ func TestCodespacesService_Update(t *testing.T) {

mux.HandleFunc("/user/codespaces/codespace_1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
testJSONBody(t, r, opt)
testJSONBody(t, r, input)
fmt.Fprint(w, `{"id":1,"repository":{"id":111}}`)
})

ctx := t.Context()
codespace, _, err := client.Codespaces.Update(
ctx,
"codespace_1",
opt,
input,
)
if err != nil {
t.Fatalf("Codespaces.Update returned error: %v", err)
Expand All @@ -625,7 +644,7 @@ func TestCodespacesService_Update(t *testing.T) {
got, resp, err := client.Codespaces.Update(
ctx,
"codespace_1",
opt,
input,
)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
Expand Down Expand Up @@ -720,22 +739,22 @@ func TestCodespacesService_Publish(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

opt := &PublishCodespaceOptions{
input := PublishCodespaceRequest{
Name: new("repo"),
Private: new(true),
}

mux.HandleFunc("/user/codespaces/codespace_1/publish", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testJSONBody(t, r, opt)
testJSONBody(t, r, input)
fmt.Fprint(w, `{"id":1,"repository":{"id":111}}`)
})

ctx := t.Context()
repo, _, err := client.Codespaces.Publish(
ctx,
"codespace_1",
opt,
input,
)
if err != nil {
t.Fatalf("Codespaces.Publish returned error: %v", err)
Expand All @@ -756,7 +775,7 @@ func TestCodespacesService_Publish(t *testing.T) {
got, resp, err := client.Codespaces.Publish(
ctx,
"codespace_1",
opt,
input,
)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
Expand Down
Loading
Loading