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

Method GetSessionLogs

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

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