@Summary Get workspace build by user, workspace name, and build number @ID get-workspace-build-by-user-workspace-name-and-build-number @Security CoderSessionToken @Produce json @Tags Builds @Param user path string true "User ID, name, or me" @Param workspacename path string true "Workspace name" @Pa
(rw http.ResponseWriter, r *http.Request)
| 232 | // @Success 200 {object} codersdk.WorkspaceBuild |
| 233 | // @Router /api/v2/users/{user}/workspace/{workspacename}/builds/{buildnumber} [get] |
| 234 | func (api *API) workspaceBuildByBuildNumber(rw http.ResponseWriter, r *http.Request) { |
| 235 | ctx := r.Context() |
| 236 | mems := httpmw.OrganizationMembersParam(r) |
| 237 | workspaceName := chi.URLParam(r, "workspacename") |
| 238 | buildNumber, err := strconv.ParseInt(chi.URLParam(r, "buildnumber"), 10, 32) |
| 239 | if err != nil { |
| 240 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 241 | Message: "Failed to parse build number as integer.", |
| 242 | Detail: err.Error(), |
| 243 | }) |
| 244 | return |
| 245 | } |
| 246 | |
| 247 | workspace, err := api.Database.GetWorkspaceByOwnerIDAndName(ctx, database.GetWorkspaceByOwnerIDAndNameParams{ |
| 248 | OwnerID: mems.UserID(), |
| 249 | Name: workspaceName, |
| 250 | }) |
| 251 | if httpapi.Is404Error(err) { |
| 252 | httpapi.ResourceNotFound(rw) |
| 253 | return |
| 254 | } |
| 255 | if err != nil { |
| 256 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 257 | Message: "Internal error fetching workspace by name.", |
| 258 | Detail: err.Error(), |
| 259 | }) |
| 260 | return |
| 261 | } |
| 262 | |
| 263 | workspaceBuild, err := api.Database.GetWorkspaceBuildByWorkspaceIDAndBuildNumber(ctx, database.GetWorkspaceBuildByWorkspaceIDAndBuildNumberParams{ |
| 264 | WorkspaceID: workspace.ID, |
| 265 | BuildNumber: int32(buildNumber), |
| 266 | }) |
| 267 | if httpapi.Is404Error(err) { |
| 268 | httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{ |
| 269 | Message: fmt.Sprintf("Workspace %q Build %d does not exist.", workspaceName, buildNumber), |
| 270 | }) |
| 271 | return |
| 272 | } |
| 273 | if err != nil { |
| 274 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 275 | Message: "Internal error fetching workspace build.", |
| 276 | Detail: err.Error(), |
| 277 | }) |
| 278 | return |
| 279 | } |
| 280 | |
| 281 | data, err := api.workspaceBuildsData(ctx, []database.WorkspaceBuild{workspaceBuild}) |
| 282 | if err != nil { |
| 283 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 284 | Message: "Internal error getting workspace build data.", |
| 285 | Detail: err.Error(), |
| 286 | }) |
| 287 | return |
| 288 | } |
| 289 | |
| 290 | apiBuild, err := api.convertWorkspaceBuild( |
| 291 | workspaceBuild, |
nothing calls this directly
no test coverage detected