MCPcopy Index your code
hub / github.com/coder/coder / WatchGit

Method WatchGit

codersdk/workspacesdk/agentconn.go:557–595  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

555// endpoint and returns a stream for sending subscribe/refresh messages
556// and receiving change notifications.
557func (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.

Callers

nothing calls this directly

Calls 9

agentAddressMethod · 0.95
apiClientMethod · 0.95
StartSpanFunction · 0.92
ReadBodyAsErrorFunction · 0.92
NewStreamFunction · 0.92
DialMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45
CloneMethod · 0.45

Tested by

no test coverage detected