feat: Add agent tasks API support#4225
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4225 +/- ##
==========================================
+ Coverage 97.75% 97.76% +0.01%
==========================================
Files 189 190 +1
Lines 19035 19133 +98
==========================================
+ Hits 18608 18706 +98
Misses 231 231
Partials 196 196 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @danyalahmed1995!
Just a couple tweaks/questions, then we should be ready for a second LGTM+Approval from any other contributor to this repo before merging.
cc: @stevehipwell - @alexandear - @zyfy29 - @Not-Dhananjay-Mishra - @munlicode
Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
|
@gmlewis Thanks, sounds good. I’ll address the review comments and push an update shortly. |
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @danyalahmed1995!
LGTM.
cc: @stevehipwell - @alexandear - @zyfy29 - @Not-Dhananjay-Mishra - @munlicode
stevehipwell
left a comment
There was a problem hiding this comment.
Thanks for the PR @danyalahmed1995, I've added a couple of comments.
| type AgentTasksService service | ||
|
|
||
| // AgentTask represents a Copilot cloud agent task. | ||
| type AgentTask struct { |
There was a problem hiding this comment.
This struct doesn't look correct to me as a number of these fields are required so shouldn't be pointers.
There was a problem hiding this comment.
Thanks, I’ll review the documented required vs nullable fields and adjust the struct so required fields are non-pointers while keeping nullable/optional fields as pointers.
| return s.list(ctx, "agents/tasks", opts) | ||
| } | ||
|
|
||
| func (s *AgentTasksService) list(ctx context.Context, u string, opts *AgentTaskListOptions) (*AgentTaskList, *Response, error) { |
There was a problem hiding this comment.
Why is this separate to List?
There was a problem hiding this comment.
This was split out only to make the addOptions error path testable after Codecov flagged it. I agree it adds some unnecessary indirection, so I can fold it back into List and drop that extra helper if that’s preferred.
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10")) |
There was a problem hiding this comment.
Could we get "2026-03-10" made into a constant?
There was a problem hiding this comment.
Yes, makes sense. I’ll move the preview API version into a package-level constant and use it across the Agent Tasks methods.
|
|
||
| // ListByRepo lists tasks for a repository. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#list-tasks-for-repository |
There was a problem hiding this comment.
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#list-tasks-for-repository | |
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#list-tasks-for-repository |
Because below you have:
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#start-a-task | ||
| // | ||
| //meta:operation POST /agents/repos/{owner}/{repo}/tasks | ||
| func (s *AgentTasksService) Create(ctx context.Context, owner, repo string, opts *CreateAgentTaskOptions) (*AgentTask, *Response, error) { | ||
| u := fmt.Sprintf("agents/repos/%v/%v/tasks", owner, repo) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "POST", u, opts, WithVersion("2026-03-10")) |
There was a problem hiding this comment.
The versions in the comment and the code do not match.
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#get-a-task-by-repo | ||
| // | ||
| //meta:operation GET /agents/repos/{owner}/{repo}/tasks/{task_id} | ||
| func (s *AgentTasksService) GetByRepoAndID(ctx context.Context, owner, repo, taskID string) (*AgentTask, *Response, error) { | ||
| u := fmt.Sprintf("agents/repos/%v/%v/tasks/%v", owner, repo, taskID) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10")) |
There was a problem hiding this comment.
The versions in the comment and the code do not match.
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#list-tasks | ||
| // | ||
| //meta:operation GET /agents/tasks | ||
| func (s *AgentTasksService) List(ctx context.Context, opts *AgentTaskListOptions) (*AgentTaskList, *Response, error) { | ||
| return s.list(ctx, "agents/tasks", opts) | ||
| } | ||
|
|
||
| func (s *AgentTasksService) list(ctx context.Context, u string, opts *AgentTaskListOptions) (*AgentTaskList, *Response, error) { | ||
| u, err := addOptions(u, opts) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10")) |
There was a problem hiding this comment.
The versions in the comment and the code do not match.
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#get-a-task-by-id | ||
| // | ||
| //meta:operation GET /agents/tasks/{task_id} | ||
| func (s *AgentTasksService) Get(ctx context.Context, taskID string) (*AgentTask, *Response, error) { | ||
| u := fmt.Sprintf("agents/tasks/%v", taskID) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10")) |
There was a problem hiding this comment.
The versions in the comment and the code do not match.
Summary
Adds typed client support for GitHub's Agent Tasks REST API.
This implements the documented public-preview Agent Tasks endpoints:
GET /agents/repos/{owner}/{repo}/tasksPOST /agents/repos/{owner}/{repo}/tasksGET /agents/repos/{owner}/{repo}/tasks/{task_id}GET /agents/tasksGET /agents/tasks/{task_id}Closes #4213.
Changes
AgentTasksServiceand registered it onClient.Notes
The Agent Tasks API is currently in public preview, so this PR keeps the implementation scoped to the fields and endpoints currently documented by GitHub.
Validation
Ran the repository validation flow from
CONTRIBUTING.md:script/fmt.shscript/test.sh ./...script/lint.shscript/generate.shgit diff --checkscript/test.shwith the default race configuration could not run on this Windows machine becausecgo/gccwas not available. I reran the full test script with the non-race fallback across all modules, and it passed.