EXPERIMENTAL: this endpoint is experimental and is subject to change. @Summary Watch chat workspace git state via WebSockets @ID watch-chat-workspace-git-state-via-websockets @Security CoderSessionToken @Tags Chats @Produce json @Param chat path string true "Chat ID" format(uuid) @Success 200 {obje
(rw http.ResponseWriter, r *http.Request)
| 2306 | // |
| 2307 | //nolint:revive // HTTP handler writes to ResponseWriter. |
| 2308 | func (api *API) watchChatGit(rw http.ResponseWriter, r *http.Request) { |
| 2309 | var ( |
| 2310 | ctx = r.Context() |
| 2311 | chat = httpmw.ChatParam(r) |
| 2312 | logger = api.Logger.Named("chat_git_watcher").With(slog.F("chat_id", chat.ID)) |
| 2313 | ) |
| 2314 | |
| 2315 | if _, ok := api.authorizeChatWorkspaceExec(rw, r, chat, codersdk.ChatGitWatchNoWorkspaceMessage); !ok { |
| 2316 | return |
| 2317 | } |
| 2318 | |
| 2319 | agents, err := api.Database.GetWorkspaceAgentsInLatestBuildByWorkspaceID(ctx, chat.WorkspaceID.UUID) |
| 2320 | if err != nil { |
| 2321 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 2322 | Message: "Internal error fetching workspace agents.", |
| 2323 | Detail: err.Error(), |
| 2324 | }) |
| 2325 | return |
| 2326 | } |
| 2327 | if len(agents) == 0 { |
| 2328 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 2329 | Message: codersdk.ChatGitWatchWorkspaceNoAgentsMessage, |
| 2330 | }) |
| 2331 | return |
| 2332 | } |
| 2333 | |
| 2334 | apiAgent, err := db2sdk.WorkspaceAgent( |
| 2335 | api.DERPMap(), |
| 2336 | *api.TailnetCoordinator.Load(), |
| 2337 | agents[0], |
| 2338 | nil, |
| 2339 | nil, |
| 2340 | nil, |
| 2341 | api.AgentInactiveDisconnectTimeout, |
| 2342 | api.DeploymentValues.AgentFallbackTroubleshootingURL.String(), |
| 2343 | ) |
| 2344 | if err != nil { |
| 2345 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 2346 | Message: "Internal error reading workspace agent.", |
| 2347 | Detail: err.Error(), |
| 2348 | }) |
| 2349 | return |
| 2350 | } |
| 2351 | if apiAgent.Status != codersdk.WorkspaceAgentConnected { |
| 2352 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 2353 | Message: codersdk.ChatGitWatchAgentStateMessage(apiAgent.Status), |
| 2354 | }) |
| 2355 | return |
| 2356 | } |
| 2357 | |
| 2358 | dialCtx, dialCancel := context.WithTimeout(ctx, 30*time.Second) |
| 2359 | defer dialCancel() |
| 2360 | |
| 2361 | agentConn, release, err := api.agentProvider.AgentConn(dialCtx, agents[0].ID) |
| 2362 | if err != nil { |
| 2363 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 2364 | Message: "Internal error dialing workspace agent.", |
| 2365 | Detail: err.Error(), |
nothing calls this directly
no test coverage detected