-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: Add simple CRUD endpoints for GitHub Copilot Spaces #4379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6dbc3f4
c2207db
bfeaa03
377b890
960c32f
80a149b
95cab7f
b468faa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,152 @@ import ( | |
| // GitHub API docs: https://docs.github.com/rest/copilot?apiVersion=2022-11-28 | ||
| type CopilotService service | ||
|
|
||
| // CopilotSpace represents a Copilot Space. | ||
| type CopilotSpace struct { | ||
| ID int64 `json:"id"` | ||
| Number int `json:"number"` | ||
| Name string `json:"name"` | ||
| Description *string `json:"description,omitempty"` | ||
| GeneralInstructions *string `json:"general_instructions,omitempty"` | ||
| Owner User `json:"owner"` | ||
| Creator User `json:"creator"` | ||
| CreatedAt Timestamp `json:"created_at"` | ||
| UpdatedAt Timestamp `json:"updated_at"` | ||
| HTMLURL string `json:"html_url"` | ||
| APIURL string `json:"api_url"` | ||
| BaseRole string `json:"base_role"` | ||
| ResourcesAttributes []*CopilotSpaceResource `json:"resources_attributes,omitempty"` | ||
| } | ||
|
|
||
| // CopilotSpaceResource represents a resource attached to a Copilot Space. | ||
| type CopilotSpaceResource struct { | ||
| ID *int64 `json:"id,omitempty"` | ||
| ResourceType *string `json:"resource_type,omitempty"` | ||
| Metadata map[string]any `json:"metadata,omitempty"` | ||
| } | ||
|
|
||
| // CopilotSpaceRequest represents a request to create or update a Copilot Space. | ||
| type CopilotSpaceRequest struct { | ||
| Name *string `json:"name,omitempty"` | ||
| Description *string `json:"description,omitempty"` | ||
| GeneralInstructions *string `json:"general_instructions,omitempty"` | ||
| BaseRole *string `json:"base_role,omitempty"` | ||
| ResourcesAttributes []*CopilotSpaceResource `json:"resources_attributes,omitempty"` | ||
| } | ||
|
Comment on lines
+48
to
+55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't use this struct for both create and update. I propose introducing the following: // CreateOrganizationCopilotSpaceRequest represents a request to create a Copilot Space.
type CreateOrganizationCopilotSpaceRequest struct {
Name string `json:"name"`
Description *string `json:"description,omitempty"`
GeneralInstructions *string `json:"general_instructions,omitempty"`
BaseRole *string `json:"base_role,omitempty"`
ResourcesAttributes []*CopilotSpaceResource `json:"resources_attributes,omitempty"`
}
// UpdateOrganizationCopilotSpaceRequest represents a request to update a Copilot Space.
type UpdateOrganizationCopilotSpaceRequest struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
GeneralInstructions *string `json:"general_instructions,omitempty"`
BaseRole *string `json:"base_role,omitempty"`
ResourcesAttributes []*CopilotSpaceResource `json:"resources_attributes,omitempty"`
} |
||
|
|
||
| // CopilotSpacesList represents a list of Copilot Spaces. | ||
| type CopilotSpacesList struct { | ||
| Spaces []*CopilotSpace `json:"spaces"` | ||
| } | ||
|
|
||
| // ListOrganizationCopilotSpaces lists Copilot Spaces for an organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/copilot-spaces/copilot-spaces?apiVersion=2022-11-28#list-organization-copilot-spaces | ||
| // | ||
| //meta:operation GET /orgs/{org}/copilot-spaces | ||
| func (s *CopilotService) ListOrganizationCopilotSpaces(ctx context.Context, org string, opts *ListCursorOptions) (*CopilotSpacesList, *Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/copilot-spaces", org) | ||
| u, err := addOptions(u, opts) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var spaces *CopilotSpacesList | ||
| resp, err := s.client.Do(req, &spaces) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return spaces, resp, nil | ||
| } | ||
|
|
||
| // GetOrganizationCopilotSpace gets a Copilot Space for an organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/copilot-spaces/copilot-spaces?apiVersion=2022-11-28#get-an-organization-copilot-space | ||
| // | ||
| //meta:operation GET /orgs/{org}/copilot-spaces/{space_number} | ||
| func (s *CopilotService) GetOrganizationCopilotSpace(ctx context.Context, org string, spaceNumber int) (*CopilotSpace, *Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/copilot-spaces/%v", org, spaceNumber) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var space *CopilotSpace | ||
| resp, err := s.client.Do(req, &space) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return space, resp, nil | ||
| } | ||
|
|
||
| // CreateOrganizationCopilotSpace creates a Copilot Space for an organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/copilot-spaces/copilot-spaces?apiVersion=2022-11-28#create-an-organization-copilot-space | ||
| // | ||
| //meta:operation POST /orgs/{org}/copilot-spaces | ||
| func (s *CopilotService) CreateOrganizationCopilotSpace(ctx context.Context, org string, body CopilotSpaceRequest) (*CopilotSpace, *Response, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use separate body structs for Body parameters for these endpoints differ and we can't use the single
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair. I dug deeper onto separate parameters create and update accept and found that update 's update: forgot to send this message earlier, but the curl example shows a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| u := fmt.Sprintf("orgs/%v/copilot-spaces", org) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "POST", u, body) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var space *CopilotSpace | ||
| resp, err := s.client.Do(req, &space) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return space, resp, nil | ||
| } | ||
|
|
||
| // UpdateOrganizationCopilotSpace updates a Copilot Space for an organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/copilot-spaces/copilot-spaces?apiVersion=2022-11-28#set-an-organization-copilot-space | ||
| // | ||
| //meta:operation PUT /orgs/{org}/copilot-spaces/{space_number} | ||
| func (s *CopilotService) UpdateOrganizationCopilotSpace(ctx context.Context, org string, spaceNumber int, body CopilotSpaceRequest) (*CopilotSpace, *Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/copilot-spaces/%v", org, spaceNumber) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "PUT", u, body) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var space *CopilotSpace | ||
| resp, err := s.client.Do(req, &space) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return space, resp, nil | ||
| } | ||
|
|
||
| // DeleteOrganizationCopilotSpace deletes a Copilot Space for an organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/copilot-spaces/copilot-spaces?apiVersion=2022-11-28#delete-an-organization-copilot-space | ||
| // | ||
| //meta:operation DELETE /orgs/{org}/copilot-spaces/{space_number} | ||
| func (s *CopilotService) DeleteOrganizationCopilotSpace(ctx context.Context, org string, spaceNumber int) (*Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/copilot-spaces/%v", org, spaceNumber) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "DELETE", u, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return s.client.Do(req, nil) | ||
| } | ||
|
|
||
| // CopilotOrganizationDetails represents the details of an organization's Copilot for Business subscription. | ||
| type CopilotOrganizationDetails struct { | ||
| SeatBreakdown *CopilotSeatBreakdown `json:"seat_breakdown"` | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's introduce a separate struct that represents the
Metadata