fix(agent-task/capi): add WorkflowRunID field to Session

Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
Babak K. Shandiz 2025-09-18 16:11:17 +01:00
parent b6816ad89a
commit e5739cc545
No known key found for this signature in database
GPG key ID: 9472CAEFF56C742E
2 changed files with 109 additions and 0 deletions

View file

@ -43,6 +43,7 @@ type session struct {
EventURL string `json:"event_url"`
EventType string `json:"event_type"`
PremiumRequests float64 `json:"premium_requests"`
WorkflowRunID uint64 `json:"workflow_run_id,omitempty"`
Error *struct {
Code string `json:"code"`
Message string `json:"message"`
@ -87,6 +88,7 @@ type Session struct {
EventURL string
EventType string
PremiumRequests float64
WorkflowRunID uint64
Error *SessionError
PullRequest *api.PullRequest
@ -467,6 +469,7 @@ func fromAPISession(s session) *Session {
EventURL: s.EventURL,
EventType: s.EventType,
PremiumRequests: s.PremiumRequests,
WorkflowRunID: s.WorkflowRunID,
}
if s.Error != nil {
result.Error = &SessionError{

View file

@ -987,6 +987,112 @@ func TestListLatestSessionsForViewer(t *testing.T) {
},
},
},
{
name: "workflow run id is included",
limit: 10,
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
reg.Register(
httpmock.WithHost(
httpmock.QueryMatcher("GET", "agents/sessions", url.Values{
"page_number": {"1"},
"page_size": {"50"},
"sort": {"last_updated_at,desc"},
}),
"api.githubcopilot.com",
),
httpmock.StringResponse(heredoc.Docf(`
{
"sessions": [
{
"id": "sessA",
"name": "Build artifacts",
"user_id": 1,
"agent_id": 2,
"logs": "",
"state": "failed",
"owner_id": 10,
"repo_id": 1000,
"resource_type": "pull",
"resource_id": 3000,
"created_at": "%[1]s",
"workflow_run_id": 9999
}
]
}`,
sampleDateString,
)),
)
// GraphQL hydration
reg.Register(
httpmock.GraphQL(`query FetchPRsAndUsersForAgentTaskSessions\b`),
httpmock.GraphQLQuery(heredoc.Docf(`
{
"data": {
"nodes": [
{
"__typename": "PullRequest",
"id": "PR_node3000",
"fullDatabaseId": "3000",
"number": 100,
"title": "Improve docs",
"state": "OPEN",
"isDraft": true,
"url": "https://github.com/OWNER/REPO/pull/100",
"body": "",
"createdAt": "%[1]s",
"updatedAt": "%[1]s",
"repository": {"nameWithOwner": "OWNER/REPO"}
},
{
"__typename": "User",
"login": "octocat",
"name": "Octocat",
"databaseId": 1
}
]
}
}`,
sampleDateString,
), func(q string, vars map[string]interface{}) {
// Expected encoded node IDs for resource IDs 3000 and user octocat
assert.Equal(t, []interface{}{"PR_kwDNA-jNC7g", "U_kgAB"}, vars["ids"])
}),
)
},
wantOut: []*Session{
{
ID: "sessA",
Name: "Build artifacts",
UserID: 1,
AgentID: 2,
Logs: "",
State: "failed",
OwnerID: 10,
RepoID: 1000,
ResourceType: "pull",
ResourceID: 3000,
CreatedAt: sampleDate,
WorkflowRunID: 9999,
PullRequest: &api.PullRequest{
ID: "PR_node3000",
FullDatabaseID: "3000",
Number: 100,
Title: "Improve docs",
State: "OPEN",
IsDraft: true,
URL: "https://github.com/OWNER/REPO/pull/100",
Body: "",
CreatedAt: sampleDate,
UpdatedAt: sampleDate,
Repository: &api.PRRepository{
NameWithOwner: "OWNER/REPO",
},
},
User: &api.GitHubUser{Login: "octocat", Name: "Octocat", DatabaseID: 1},
},
},
},
{
name: "API error",
limit: 10,