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

Method GetSession

pkg/cmd/agent-task/capi/sessions.go:297–336  ·  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 u, err := safeurl.JoinPathWithHostPrefix(c.capiBaseURL, "agents", "sessions", id)
303 if err != nil {
304 return nil, err
305 }
306
307 req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), http.NoBody)
308 if err != nil {
309 return nil, err
310 }
311
312 res, err := c.httpClient.Do(req)
313 if err != nil {
314 return nil, err
315 }
316
317 defer res.Body.Close()
318 if res.StatusCode != http.StatusOK {
319 if res.StatusCode == http.StatusNotFound {
320 return nil, ErrSessionNotFound
321 }
322 return nil, fmt.Errorf("failed to get session: %s", res.Status)
323 }
324
325 var rawSession session
326 if err := json.NewDecoder(res.Body).Decode(&rawSession); err != nil {
327 return nil, fmt.Errorf("failed to decode session response: %w", err)
328 }
329
330 sessions, err := c.hydrateSessionPullRequestsAndUsers([]session{rawSession})
331 if err != nil {
332 return nil, fmt.Errorf("failed to fetch session resources: %w", err)
333 }
334
335 return sessions[0], nil
336}
337
338// GetSessionLogs retrieves logs of an agent session identified by ID.
339func (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