-
Notifications
You must be signed in to change notification settings - Fork 928
feat: update build url to @username/workspace/builds/buildnumber #2234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d7451d0
318224c
e60aa38
4c22d12
d127aed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"errors" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/go-chi/chi/v5" | ||
"github.com/google/uuid" | ||
|
@@ -160,6 +161,82 @@ func (api *API) workspaceBuilds(rw http.ResponseWriter, r *http.Request) { | |
httpapi.Write(rw, http.StatusOK, apiBuilds) | ||
} | ||
|
||
func (api *API) workspaceBuildByBuildNumber(rw http.ResponseWriter, r *http.Request) { | ||
owner := httpmw.UserParam(r) | ||
workspaceName := chi.URLParam(r, "workspacename") | ||
buildNumber, err := strconv.ParseInt(chi.URLParam(r, "buildnumber"), 10, 32) | ||
if err != nil { | ||
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{ | ||
Message: "Failed to parse build number as integer.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
|
||
workspace, err := api.Database.GetWorkspaceByOwnerIDAndName(r.Context(), database.GetWorkspaceByOwnerIDAndNameParams{ | ||
OwnerID: owner.ID, | ||
Name: workspaceName, | ||
}) | ||
if errors.Is(err, sql.ErrNoRows) { | ||
httpapi.Write(rw, http.StatusNotFound, httpapi.Response{ | ||
Message: fmt.Sprintf("Workspace %q does not exist.", workspaceName), | ||
}) | ||
return | ||
} | ||
if err != nil { | ||
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{ | ||
Message: "Internal error fetching workspace by name.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
|
||
if !api.Authorize(rw, r, rbac.ActionRead, rbac.ResourceWorkspace. | ||
InOrg(workspace.OrganizationID).WithOwner(workspace.OwnerID.String()).WithID(workspace.ID.String())) { | ||
return | ||
} | ||
|
||
workspaceBuild, err := api.Database.GetWorkspaceBuildByWorkspaceIDAndBuildNumber(r.Context(), database.GetWorkspaceBuildByWorkspaceIDAndBuildNumberParams{ | ||
WorkspaceID: workspace.ID, | ||
BuildNumber: int32(buildNumber), | ||
}) | ||
if errors.Is(err, sql.ErrNoRows) { | ||
httpapi.Write(rw, http.StatusNotFound, httpapi.Response{ | ||
Message: fmt.Sprintf("Workspace %q Build %d does not exist.", workspaceName, buildNumber), | ||
}) | ||
return | ||
} | ||
if err != nil { | ||
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{ | ||
Message: "Internal error fetching workspace build.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
|
||
job, err := api.Database.GetProvisionerJobByID(r.Context(), workspaceBuild.JobID) | ||
if err != nil { | ||
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{ | ||
Message: "Internal error fetching provisioner job.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
|
||
users, err := api.Database.GetUsersByIDs(r.Context(), []uuid.UUID{workspace.OwnerID, workspaceBuild.InitiatorID}) | ||
if err != nil { | ||
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{ | ||
Message: "Internal error fetching user.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
Comment on lines
+226
to
+233
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remark (non-blocking): If we end up having the concept of "system" or "ghost" users with reserved UUIDs, we'll need to make sure that this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it worth making a pass through the repo to find such occurrences and commenting around them for future reference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not just yet. It's more of something to keep in mind if or when we do have "system" or "ghost" users. |
||
|
||
httpapi.Write(rw, http.StatusOK, | ||
convertWorkspaceBuild(findUser(workspace.OwnerID, users), findUser(workspaceBuild.InitiatorID, users), | ||
workspace, workspaceBuild, job)) | ||
} | ||
|
||
func (api *API) workspaceBuildByName(rw http.ResponseWriter, r *http.Request) { | ||
workspace := httpmw.WorkspaceParam(r) | ||
if !api.Authorize(rw, r, rbac.ActionRead, rbac.ResourceWorkspace. | ||
|
Uh oh!
There was an error while loading. Please reload this page.