Skip to content

Commit f8042ad

Browse files
fix: address latest agent tasks review comments
1 parent ceabbf4 commit f8042ad

4 files changed

Lines changed: 63 additions & 97 deletions

File tree

github/agent_tasks.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"time"
1313
)
1414

15+
const agentTasksAPIVersion = "2026-03-10"
16+
1517
// AgentTasksService handles communication with the agent tasks
1618
// methods of the GitHub API.
1719
//
@@ -20,40 +22,40 @@ type AgentTasksService service
2022

2123
// AgentTask represents a Copilot cloud agent task.
2224
type AgentTask struct {
23-
ID *string `json:"id,omitempty"`
25+
ID string `json:"id"`
2426
URL *string `json:"url,omitempty"`
2527
HTMLURL *string `json:"html_url,omitempty"`
2628
Name *string `json:"name,omitempty"`
2729
Creator *User `json:"creator,omitempty"`
2830
CreatorType *string `json:"creator_type,omitempty"`
2931
Owner *User `json:"owner,omitempty"`
3032
Repository *Repository `json:"repository,omitempty"`
31-
State *string `json:"state,omitempty"`
33+
State string `json:"state"`
3234
SessionCount *int `json:"session_count,omitempty"`
3335
Artifacts []*AgentTaskArtifact `json:"artifacts,omitempty"`
3436
ArchivedAt *Timestamp `json:"archived_at,omitempty"`
35-
CreatedAt *Timestamp `json:"created_at,omitempty"`
37+
CreatedAt Timestamp `json:"created_at"`
3638
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
3739
Sessions []*AgentTaskSession `json:"sessions,omitempty"`
3840
}
3941

4042
// AgentTaskArtifact represents an artifact produced by an agent task.
4143
type AgentTaskArtifact struct {
42-
Provider *string `json:"provider,omitempty"`
43-
Type *string `json:"type,omitempty"`
44-
Data json.RawMessage `json:"data,omitempty"`
44+
Provider string `json:"provider"`
45+
Type string `json:"type"`
46+
Data json.RawMessage `json:"data"`
4547
}
4648

4749
// AgentTaskSession represents a session associated with an agent task.
4850
type AgentTaskSession struct {
49-
ID *string `json:"id,omitempty"`
51+
ID string `json:"id"`
5052
Name *string `json:"name,omitempty"`
5153
User *User `json:"user,omitempty"`
5254
Owner *User `json:"owner,omitempty"`
5355
Repository *Repository `json:"repository,omitempty"`
5456
TaskID *string `json:"task_id,omitempty"`
55-
State *string `json:"state,omitempty"`
56-
CreatedAt *Timestamp `json:"created_at,omitempty"`
57+
State string `json:"state"`
58+
CreatedAt Timestamp `json:"created_at"`
5759
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
5860
CompletedAt *Timestamp `json:"completed_at,omitempty"`
5961
Prompt *string `json:"prompt,omitempty"`
@@ -112,7 +114,7 @@ type CreateAgentTaskOptions struct {
112114

113115
// ListByRepo lists tasks for a repository.
114116
//
115-
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#list-tasks-for-repository
117+
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#list-tasks-for-repository
116118
//
117119
//meta:operation GET /agents/repos/{owner}/{repo}/tasks
118120
func (s *AgentTasksService) ListByRepo(ctx context.Context, owner, repo string, opts *AgentTaskListByRepoOptions) (*AgentTaskList, *Response, error) {
@@ -122,7 +124,7 @@ func (s *AgentTasksService) ListByRepo(ctx context.Context, owner, repo string,
122124
return nil, nil, err
123125
}
124126

125-
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
127+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion(agentTasksAPIVersion))
126128
if err != nil {
127129
return nil, nil, err
128130
}
@@ -144,7 +146,7 @@ func (s *AgentTasksService) ListByRepo(ctx context.Context, owner, repo string,
144146
func (s *AgentTasksService) Create(ctx context.Context, owner, repo string, opts *CreateAgentTaskOptions) (*AgentTask, *Response, error) {
145147
u := fmt.Sprintf("agents/repos/%v/%v/tasks", owner, repo)
146148

147-
req, err := s.client.NewRequest(ctx, "POST", u, opts, WithVersion("2026-03-10"))
149+
req, err := s.client.NewRequest(ctx, "POST", u, opts, WithVersion(agentTasksAPIVersion))
148150
if err != nil {
149151
return nil, nil, err
150152
}
@@ -166,7 +168,7 @@ func (s *AgentTasksService) Create(ctx context.Context, owner, repo string, opts
166168
func (s *AgentTasksService) GetByRepoAndID(ctx context.Context, owner, repo, taskID string) (*AgentTask, *Response, error) {
167169
u := fmt.Sprintf("agents/repos/%v/%v/tasks/%v", owner, repo, taskID)
168170

169-
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
171+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion(agentTasksAPIVersion))
170172
if err != nil {
171173
return nil, nil, err
172174
}
@@ -186,16 +188,13 @@ func (s *AgentTasksService) GetByRepoAndID(ctx context.Context, owner, repo, tas
186188
//
187189
//meta:operation GET /agents/tasks
188190
func (s *AgentTasksService) List(ctx context.Context, opts *AgentTaskListOptions) (*AgentTaskList, *Response, error) {
189-
return s.list(ctx, "agents/tasks", opts)
190-
}
191-
192-
func (s *AgentTasksService) list(ctx context.Context, u string, opts *AgentTaskListOptions) (*AgentTaskList, *Response, error) {
191+
u := "agents/tasks"
193192
u, err := addOptions(u, opts)
194193
if err != nil {
195194
return nil, nil, err
196195
}
197196

198-
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
197+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion(agentTasksAPIVersion))
199198
if err != nil {
200199
return nil, nil, err
201200
}
@@ -217,7 +216,7 @@ func (s *AgentTasksService) list(ctx context.Context, u string, opts *AgentTaskL
217216
func (s *AgentTasksService) Get(ctx context.Context, taskID string) (*AgentTask, *Response, error) {
218217
u := fmt.Sprintf("agents/tasks/%v", taskID)
219218

220-
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
219+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion(agentTasksAPIVersion))
221220
if err != nil {
222221
return nil, nil, err
223222
}

github/agent_tasks_test.go

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,38 +72,38 @@ func agentTask(includeSessions bool) *AgentTask {
7272
updatedAt := &Timestamp{time.Date(2025, time.January, 1, 1, 0, 0, 0, time.UTC)}
7373

7474
task := &AgentTask{
75-
ID: Ptr(agentTaskID),
75+
ID: agentTaskID,
7676
URL: Ptr("https://api.github.com/agents/repos/octocat/hello-world/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890"),
7777
HTMLURL: Ptr("https://github.com/octocat/hello-world/copilot/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890"),
7878
Name: Ptr("Fix the login button on the homepage"),
7979
Creator: &User{ID: Ptr(int64(1))},
8080
CreatorType: Ptr("user"),
8181
Owner: &User{ID: Ptr(int64(2))},
8282
Repository: &Repository{ID: Ptr(int64(1296269))},
83-
State: Ptr("completed"),
83+
State: "completed",
8484
SessionCount: Ptr(1),
8585
Artifacts: []*AgentTaskArtifact{
8686
{
87-
Provider: Ptr("github"),
88-
Type: Ptr("pull"),
87+
Provider: "github",
88+
Type: "pull",
8989
Data: json.RawMessage(`{"id":42}`),
9090
},
9191
},
92-
CreatedAt: createdAt,
92+
CreatedAt: *createdAt,
9393
UpdatedAt: updatedAt,
9494
}
9595

9696
if includeSessions {
9797
task.Sessions = []*AgentTaskSession{
9898
{
99-
ID: Ptr(agentTaskSessionID),
99+
ID: agentTaskSessionID,
100100
Name: Ptr("Fix the login button on the homepage"),
101101
User: &User{ID: Ptr(int64(1))},
102102
Owner: &User{ID: Ptr(int64(2))},
103103
Repository: &Repository{ID: Ptr(int64(1296269))},
104104
TaskID: Ptr(agentTaskID),
105-
State: Ptr("completed"),
106-
CreatedAt: createdAt,
105+
State: "completed",
106+
CreatedAt: *createdAt,
107107
UpdatedAt: updatedAt,
108108
CompletedAt: updatedAt,
109109
Prompt: Ptr("Fix the login button on the homepage"),
@@ -314,15 +314,6 @@ func TestAgentTasksService_List(t *testing.T) {
314314
})
315315
}
316316

317-
func TestAgentTasksService_List_badOptions(t *testing.T) {
318-
t.Parallel()
319-
client, _, _ := setup(t)
320-
321-
ctx := t.Context()
322-
_, _, err := client.AgentTasks.list(ctx, "%", &AgentTaskListOptions{})
323-
testURLParseError(t, err)
324-
}
325-
326317
func TestAgentTasksService_Get(t *testing.T) {
327318
t.Parallel()
328319
client, mux, _ := setup(t)
@@ -359,17 +350,17 @@ func TestAgentTasksService_Get(t *testing.T) {
359350

360351
func TestAgentTask_Marshal(t *testing.T) {
361352
t.Parallel()
362-
testJSONMarshal(t, &AgentTask{}, "{}")
353+
testJSONMarshal(t, &AgentTask{}, `{"id":"","state":"","created_at":"0001-01-01T00:00:00Z"}`)
363354
testJSONMarshal(t, agentTask(true), agentTaskMarshalJSON(true), cmpJSONRawMessageComparator())
364355
}
365356

366357
func TestAgentTaskArtifact_Marshal(t *testing.T) {
367358
t.Parallel()
368-
testJSONMarshal(t, &AgentTaskArtifact{}, "{}")
359+
testJSONMarshal(t, &AgentTaskArtifact{Data: json.RawMessage("null")}, `{"provider":"","type":"","data":null}`)
369360

370361
u := &AgentTaskArtifact{
371-
Provider: Ptr("github"),
372-
Type: Ptr("pull"),
362+
Provider: "github",
363+
Type: "pull",
373364
Data: json.RawMessage(`{"id":42}`),
374365
}
375366
want := `{
@@ -383,7 +374,7 @@ func TestAgentTaskArtifact_Marshal(t *testing.T) {
383374

384375
func TestAgentTaskSession_Marshal(t *testing.T) {
385376
t.Parallel()
386-
testJSONMarshal(t, &AgentTaskSession{}, "{}")
377+
testJSONMarshal(t, &AgentTaskSession{}, `{"id":"","state":"","created_at":"0001-01-01T00:00:00Z"}`)
387378

388379
u := agentTask(true).Sessions[0]
389380
want := `{

github/github-accessors.go

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)