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

Method GetSessionLogs

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

GetSessionLogs retrieves logs of an agent session identified by ID.

(ctx context.Context, id string)

Source from the content-addressed store, hash-verified

337
338// GetSessionLogs retrieves logs of an agent session identified by ID.
339func (c *CAPIClient) GetSessionLogs(ctx context.Context, id string) ([]byte, error) {
340 if id == "" {
341 return nil, fmt.Errorf("missing session ID")
342 }
343
344 u, err := safeurl.JoinPathWithHostPrefix(c.capiBaseURL, "agents", "sessions", id, "logs")
345 if err != nil {
346 return nil, err
347 }
348
349 req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), http.NoBody)
350 if err != nil {
351 return nil, err
352 }
353
354 res, err := c.httpClient.Do(req)
355 if err != nil {
356 return nil, err
357 }
358
359 defer res.Body.Close()
360 if res.StatusCode != http.StatusOK {
361 if res.StatusCode == http.StatusNotFound {
362 return nil, ErrSessionNotFound
363 }
364 return nil, fmt.Errorf("failed to get session: %s", res.Status)
365 }
366
367 return io.ReadAll(res.Body)
368}
369
370// ListSessionsByResourceID retrieves sessions associated with the given resource type and ID.
371func (c *CAPIClient) ListSessionsByResourceID(ctx context.Context, resourceType string, resourceID int64, limit int) ([]*Session, error) {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected