MCPcopy Create free account
hub / github.com/cli/cli / GetSession

Method GetSession

pkg/cmd/agent-task/capi/sessions.go:294–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

292
293// GetSession retrieves a specific agent session by ID.
294func (c *CAPIClient) GetSession(ctx context.Context, id string) (*Session, error) {
295 if id == "" {
296 return nil, fmt.Errorf("missing session ID")
297 }
298
299 u, err := safeurl.JoinPathWithHostPrefix(c.capiBaseURL, "agents", "sessions", id)
300 if err != nil {
301 return nil, err
302 }
303
304 req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), 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 6

JoinPathWithHostPrefixFunction · 0.92
ErrorfMethod · 0.65
StringMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by 2

TestGetSessionRequiresIDFunction · 0.76
TestGetSessionFunction · 0.76