-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: Add support for Codespaces organizations APIs #3892
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1c366b1
add support for codespaces org
Not-Dhananjay-Mishra ca8e60b
update copyright year to 2025
Not-Dhananjay-Mishra b2372c6
fix test
Not-Dhananjay-Mishra 6f151cc
inc coverage
Not-Dhananjay-Mishra 232367b
feedback
Not-Dhananjay-Mishra 381db67
use omitzero with SelectedUsernames
Not-Dhananjay-Mishra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| // CodespacesOrgAccessControlRequest represent request for SetOrgAccessControl. | ||
| type CodespacesOrgAccessControlRequest struct { | ||
| // Visibility represent which users can access codespaces in the organization. | ||
| // Can be one of: disabled, selected_members, all_members, all_members_and_outside_collaborators. | ||
| Visibility string `json:"visibility"` | ||
| // SelectedUsernames represent the usernames of the organization members who should have access to codespaces in the organization. | ||
| // Required when visibility is selected_members. | ||
| SelectedUsernames []string `json:"selected_usernames,omitempty"` | ||
| } | ||
|
|
||
| // ListInOrg lists the codespaces associated to a specified organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/codespaces/organizations#list-codespaces-for-the-organization | ||
| // | ||
| //meta:operation GET /orgs/{org}/codespaces | ||
| func (s *CodespacesService) ListInOrg(ctx context.Context, org string, opts *ListOptions) (*ListCodespaces, *Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/codespaces", org) | ||
| 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 codespaces *ListCodespaces | ||
| resp, err := s.client.Do(ctx, req, &codespaces) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return codespaces, resp, nil | ||
| } | ||
|
|
||
| // SetOrgAccessControl sets which users can access codespaces in an organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/codespaces/organizations#manage-access-control-for-organization-codespaces | ||
| // | ||
| //meta:operation PUT /orgs/{org}/codespaces/access | ||
| func (s *CodespacesService) SetOrgAccessControl(ctx context.Context, org string, request CodespacesOrgAccessControlRequest) (*Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/codespaces/access", org) | ||
| req, err := s.client.NewRequest("PUT", u, request) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| resp, err := s.client.Do(ctx, req, nil) | ||
| if err != nil { | ||
| return resp, err | ||
| } | ||
|
|
||
| return resp, nil | ||
| } | ||
|
|
||
| // AddUsersToOrgAccess adds users to Codespaces access for an organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/codespaces/organizations#add-users-to-codespaces-access-for-an-organization | ||
| // | ||
| //meta:operation POST /orgs/{org}/codespaces/access/selected_users | ||
| func (s *CodespacesService) AddUsersToOrgAccess(ctx context.Context, org string, usernames []string) (*Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/codespaces/access/selected_users", org) | ||
| req, err := s.client.NewRequest("POST", u, map[string][]string{"selected_usernames": usernames}) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| resp, err := s.client.Do(ctx, req, nil) | ||
| if err != nil { | ||
| return resp, err | ||
| } | ||
|
|
||
| return resp, nil | ||
| } | ||
|
|
||
| // RemoveUsersFromOrgAccess removes users from Codespaces access for an organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/codespaces/organizations#remove-users-from-codespaces-access-for-an-organization | ||
| // | ||
| //meta:operation DELETE /orgs/{org}/codespaces/access/selected_users | ||
| func (s *CodespacesService) RemoveUsersFromOrgAccess(ctx context.Context, org string, usernames []string) (*Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/codespaces/access/selected_users", org) | ||
| req, err := s.client.NewRequest("DELETE", u, map[string][]string{"selected_usernames": usernames}) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| resp, err := s.client.Do(ctx, req, nil) | ||
| if err != nil { | ||
| return resp, err | ||
| } | ||
|
|
||
| return resp, nil | ||
| } | ||
|
|
||
| // ListUserCodespacesInOrg lists the codespaces that a member of an organization has for repositories in that organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/codespaces/organizations#list-codespaces-for-a-user-in-organization | ||
| // | ||
| //meta:operation GET /orgs/{org}/members/{username}/codespaces | ||
| func (s *CodespacesService) ListUserCodespacesInOrg(ctx context.Context, org, username string, opts *ListOptions) (*ListCodespaces, *Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/members/%v/codespaces", org, username) | ||
| 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 codespaces *ListCodespaces | ||
| resp, err := s.client.Do(ctx, req, &codespaces) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return codespaces, resp, nil | ||
| } | ||
|
|
||
| // DeleteUserCodespaceInOrg deletes a user's codespace from the organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/codespaces/organizations#delete-a-codespace-from-the-organization | ||
| // | ||
| //meta:operation DELETE /orgs/{org}/members/{username}/codespaces/{codespace_name} | ||
| func (s *CodespacesService) DeleteUserCodespaceInOrg(ctx context.Context, org, username, codespaceName string) (*Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/members/%v/codespaces/%v", org, username, codespaceName) | ||
| req, err := s.client.NewRequest("DELETE", u, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| resp, err := s.client.Do(ctx, req, nil) | ||
| if err != nil { | ||
| return resp, err | ||
| } | ||
|
|
||
| return resp, nil | ||
| } | ||
|
|
||
| // StopUserCodespaceInOrg stops a codespace for an organization user. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/codespaces/organizations#stop-a-codespace-for-an-organization-user | ||
| // | ||
| //meta:operation POST /orgs/{org}/members/{username}/codespaces/{codespace_name}/stop | ||
| func (s *CodespacesService) StopUserCodespaceInOrg(ctx context.Context, org, username, codespaceName string) (*Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/members/%v/codespaces/%v/stop", org, username, codespaceName) | ||
| req, err := s.client.NewRequest("POST", u, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| resp, err := s.client.Do(ctx, req, nil) | ||
| if err != nil { | ||
| return resp, err | ||
| } | ||
|
|
||
| return resp, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.