-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: Add Copilot custom agents enterprise endpoints #4525
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
Open
Tens1des
wants to merge
2
commits into
google:master
Choose a base branch
from
Tens1des:feat/copilot-custom-agents
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,152 @@ | ||
| // Copyright 2026 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" | ||
| ) | ||
|
|
||
| // CopilotCustomAgent represents a custom agent defined in an enterprise source repository. | ||
| type CopilotCustomAgent struct { | ||
| Name *string `json:"name,omitempty"` | ||
| FilePath *string `json:"file_path,omitempty"` | ||
| URL *string `json:"url,omitempty"` | ||
| } | ||
|
|
||
| // EnterpriseCustomAgents represents the list of custom agents for an enterprise. | ||
| type EnterpriseCustomAgents struct { | ||
| CustomAgents []*CopilotCustomAgent `json:"custom_agents"` | ||
| } | ||
|
|
||
| // CopilotCustomAgentsSourceOrganization represents the organization configured as | ||
| // the custom agents source for an enterprise. | ||
| type CopilotCustomAgentsSourceOrganization struct { | ||
| ID *int64 `json:"id,omitempty"` | ||
| Login *string `json:"login,omitempty"` | ||
| AvatarURL *string `json:"avatar_url,omitempty"` | ||
| } | ||
|
|
||
| // CopilotCustomAgentsSourceRepository represents the repository that stores custom agent definitions. | ||
| type CopilotCustomAgentsSourceRepository struct { | ||
| ID *int64 `json:"id,omitempty"` | ||
| Name *string `json:"name,omitempty"` | ||
| FullName *string `json:"full_name,omitempty"` | ||
| } | ||
|
|
||
| // CopilotCustomAgentsSourceRuleset represents the ruleset created to protect agent definition files. | ||
| type CopilotCustomAgentsSourceRuleset struct { | ||
| ID *int64 `json:"id,omitempty"` | ||
| Name *string `json:"name,omitempty"` | ||
| Enforcement *string `json:"enforcement,omitempty"` | ||
| } | ||
|
|
||
| // CopilotCustomAgentsSource represents the source organization and repository for | ||
| // enterprise custom agents (and optionally a protecting ruleset). | ||
| type CopilotCustomAgentsSource struct { | ||
| Organization *CopilotCustomAgentsSourceOrganization `json:"organization"` | ||
| Repository *CopilotCustomAgentsSourceRepository `json:"repository"` | ||
| Ruleset *CopilotCustomAgentsSourceRuleset `json:"ruleset,omitempty"` | ||
| } | ||
|
|
||
| // SetCopilotCustomAgentsSourceRequest is the request body for setting the custom agents source. | ||
| type SetCopilotCustomAgentsSourceRequest struct { | ||
| // OrganizationID is the ID of the organization to use as the custom agents source. | ||
| OrganizationID int64 `json:"organization_id"` | ||
| // CreateRuleset controls whether to create a ruleset to protect agent definition files. | ||
| // Defaults to true when omitted. | ||
| CreateRuleset *bool `json:"create_ruleset,omitempty"` | ||
| } | ||
|
|
||
| // ListEnterpriseCustomAgents gets the list of custom agents defined for an enterprise. | ||
| // | ||
| // If no source repository has been configured, CustomAgents may be nil. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-custom-agents?apiVersion=2022-11-28#get-custom-agents-for-an-enterprise | ||
| // | ||
| //meta:operation GET /enterprises/{enterprise}/copilot/custom-agents | ||
| func (s *CopilotService) ListEnterpriseCustomAgents(ctx context.Context, enterprise string, opts *ListOptions) (*EnterpriseCustomAgents, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/copilot/custom-agents", enterprise) | ||
| 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 agents *EnterpriseCustomAgents | ||
| resp, err := s.client.Do(req, &agents) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return agents, resp, nil | ||
| } | ||
|
|
||
| // GetEnterpriseCustomAgentsSource gets the organization and repository configured as | ||
| // the source for custom agent definitions in an enterprise. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-custom-agents?apiVersion=2022-11-28#get-the-source-organization-for-custom-agents-in-an-enterprise | ||
| // | ||
| //meta:operation GET /enterprises/{enterprise}/copilot/custom-agents/source | ||
| func (s *CopilotService) GetEnterpriseCustomAgentsSource(ctx context.Context, enterprise string) (*CopilotCustomAgentsSource, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/copilot/custom-agents/source", enterprise) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var source *CopilotCustomAgentsSource | ||
| resp, err := s.client.Do(req, &source) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return source, resp, nil | ||
| } | ||
|
|
||
| // SetEnterpriseCustomAgentsSource sets an organization as the source for custom agent | ||
| // definitions in an enterprise. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-custom-agents?apiVersion=2022-11-28#set-the-source-organization-for-custom-agents-in-an-enterprise | ||
| // | ||
| //meta:operation PUT /enterprises/{enterprise}/copilot/custom-agents/source | ||
| func (s *CopilotService) SetEnterpriseCustomAgentsSource(ctx context.Context, enterprise string, body SetCopilotCustomAgentsSourceRequest) (*CopilotCustomAgentsSource, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/copilot/custom-agents/source", enterprise) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "PUT", u, body) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var source *CopilotCustomAgentsSource | ||
| resp, err := s.client.Do(req, &source) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return source, resp, nil | ||
| } | ||
|
|
||
| // DeleteEnterpriseCustomAgentsSource removes the custom agents source configuration for an enterprise. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-custom-agents?apiVersion=2022-11-28#delete-the-custom-agents-source-for-an-enterprise | ||
| // | ||
| //meta:operation DELETE /enterprises/{enterprise}/copilot/custom-agents/source | ||
| func (s *CopilotService) DeleteEnterpriseCustomAgentsSource(ctx context.Context, enterprise string) (*Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/copilot/custom-agents/source", enterprise) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "DELETE", u, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return s.client.Do(req, 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.
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.