WatchGit opens a bidirectional WebSocket to the agent's git watch endpoint and returns a stream for sending subscribe/refresh messages and receiving change notifications.
(ctx context.Context, logger slog.Logger, chatID uuid.UUID)
| 555 | // endpoint and returns a stream for sending subscribe/refresh messages |
| 556 | // and receiving change notifications. |
| 557 | func (c *agentConn) WatchGit(ctx context.Context, logger slog.Logger, chatID uuid.UUID) (*wsjson.Stream[codersdk.WorkspaceAgentGitServerMessage, codersdk.WorkspaceAgentGitClientMessage], error) { |
| 558 | ctx, span := tracing.StartSpan(ctx) |
| 559 | defer span.End() |
| 560 | |
| 561 | host := net.JoinHostPort(c.agentAddress().String(), strconv.Itoa(AgentHTTPAPIServerPort)) |
| 562 | |
| 563 | dialOpts := &websocket.DialOptions{ |
| 564 | HTTPClient: c.apiClient(), |
| 565 | CompressionMode: websocket.CompressionNoContextTakeover, |
| 566 | } |
| 567 | c.headersMu.RLock() |
| 568 | if len(c.extraHeaders) > 0 { |
| 569 | dialOpts.HTTPHeader = c.extraHeaders.Clone() |
| 570 | } |
| 571 | c.headersMu.RUnlock() |
| 572 | |
| 573 | url := fmt.Sprintf("http://%s%s", host, "/api/v0/git/watch") |
| 574 | if chatID != uuid.Nil { |
| 575 | url += "?chat_id=" + chatID.String() |
| 576 | } |
| 577 | |
| 578 | conn, res, err := websocket.Dial(ctx, url, dialOpts) |
| 579 | if err != nil { |
| 580 | if res == nil { |
| 581 | return nil, err |
| 582 | } |
| 583 | return nil, codersdk.ReadBodyAsError(res) |
| 584 | } |
| 585 | if res != nil && res.Body != nil { |
| 586 | defer res.Body.Close() |
| 587 | } |
| 588 | |
| 589 | conn.SetReadLimit(1 << 22) // 4MiB |
| 590 | |
| 591 | return wsjson.NewStream[ |
| 592 | codersdk.WorkspaceAgentGitServerMessage, |
| 593 | codersdk.WorkspaceAgentGitClientMessage, |
| 594 | ](conn, websocket.MessageText, websocket.MessageText, logger), nil |
| 595 | } |
| 596 | |
| 597 | // ConnectDesktopVNC opens a WebSocket to the agent's desktop endpoint and |
| 598 | // returns a net.Conn carrying raw RFB (VNC) binary data. |
nothing calls this directly
no test coverage detected