MCPcopy
hub / github.com/cli/cli / GetSession

Method GetSession

pkg/cmd/agent-task/capi/sessions.go:297–333  ·  view source on GitHub ↗

GetSession retrieves a specific agent session by ID.

(ctx context.Context, id string)

Source from the content-addressed store, hash-verified

295
296// GetSession retrieves a specific agent session by ID.
297func (c *CAPIClient) GetSession(ctx context.Context, id string) (*Session, error) {
298 if id == "" {
299 return nil, fmt.Errorf("missing session ID")
300 }
301
302 url := fmt.Sprintf("%s/agents/sessions/%s", c.capiBaseURL, url.PathEscape(id))
303
304 req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
305 if err != nil {
306 return nil, err
307 }
308
309 res, err := c.httpClient.Do(req)
310 if err != nil {
311 return nil, err
312 }
313
314 defer res.Body.Close()
315 if res.StatusCode != http.StatusOK {
316 if res.StatusCode == http.StatusNotFound {
317 return nil, ErrSessionNotFound
318 }
319 return nil, fmt.Errorf("failed to get session: %s", res.Status)
320 }
321
322 var rawSession session
323 if err := json.NewDecoder(res.Body).Decode(&rawSession); err != nil {
324 return nil, fmt.Errorf("failed to decode session response: %w", err)
325 }
326
327 sessions, err := c.hydrateSessionPullRequestsAndUsers([]session{rawSession})
328 if err != nil {
329 return nil, fmt.Errorf("failed to fetch session resources: %w", err)
330 }
331
332 return sessions[0], nil
333}
334
335// GetSessionLogs retrieves logs of an agent session identified by ID.
336func (c *CAPIClient) GetSessionLogs(ctx context.Context, id string) ([]byte, error) {

Callers 2

TestGetSessionRequiresIDFunction · 0.95
TestGetSessionFunction · 0.95

Calls 4

ErrorfMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by 2

TestGetSessionRequiresIDFunction · 0.76
TestGetSessionFunction · 0.76