Skip to content

Commit 3af824e

Browse files
filiptronicekSiddhant-K-codemustard-mh
authored
Implement ListOrganizationPrebuilds (#19326)
* Define `ListOrganizationPrebuilds` * Fix because of name changes * Add unimplemented `listOrganizationPrebuilds` * Crazy stuff right here * Address huiwen's comments * Fix more types * sad™ * trrr * WIP API changes * Add configuration id and search term filtering * Filtering * Offload prebuild listing to prebuild manager * unused thingy delete * Add filtering by status * `listPrebuilds` -> `listOrganizationPrebuilds` * Configuration filtering could be done with a branch ... what do you say? * Implement branch filtering * Update pagination rules * Fix pagination limit validation error * Migrate one more * Fix org id for prebuild listing * Update components/gitpod-db/src/typeorm/workspace-db-impl.ts Co-authored-by: Siddhant Khare <[email protected]> * Apply code suggestions * Align pagination with config service * Status filter validation * Align org id usage * Revert back to `listPrebuilds` * Update components/gitpod-db/src/typeorm/workspace-db-impl.ts Co-authored-by: Siddhant Khare <[email protected]> * Bring in search * Fix proj id instead of org id * Fix search query‽‽‽ * nit 💄 --------- Co-authored-by: Siddhant Khare <[email protected]> Co-authored-by: Huiwen Huang <[email protected]>
1 parent a14399d commit 3af824e

File tree

12 files changed

+481
-159
lines changed

12 files changed

+481
-159
lines changed

components/dashboard/src/service/json-rpc-prebuild-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,6 @@ export class JsonRpcPrebuildClient implements PromiseClient<typeof PrebuildServi
148148
async listOrganizationPrebuilds(
149149
request: PartialMessage<ListOrganizationPrebuildsRequest>,
150150
): Promise<ListOrganizationPrebuildsResponse> {
151-
return new ListOrganizationPrebuildsResponse({});
151+
throw new ApplicationError(ErrorCodes.UNIMPLEMENTED, "Not implemented (for jrpc)");
152152
}
153153
}

components/gitpod-db/src/typeorm/workspace-db-impl.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
import { TransactionalDBImpl } from "./transactional-db-impl";
5858
import { TypeORM } from "./typeorm";
5959
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
60+
import { DBProject } from "./entity/db-project";
6061

6162
type RawTo<T> = (instance: WorkspaceInstance, ws: Workspace) => T;
6263
interface OrderBy {
@@ -1036,6 +1037,67 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
10361037
return res;
10371038
}
10381039

1040+
/**
1041+
* Finds prebuilt workspaces by organization with optional filtering and pagination.
1042+
* @param organizationId The ID of the organization.
1043+
* @param offset Offset for pagination.
1044+
* @param limit Limit for pagination.
1045+
* @param filter Filters for the search.
1046+
* @returns A promise that resolves to an array of PrebuiltWorkspace objects.
1047+
*/
1048+
async findPrebuiltWorkspacesByOrganization(
1049+
organizationId: string,
1050+
offset = 0,
1051+
limit = 25,
1052+
filter?: {
1053+
configuration?: {
1054+
id: string;
1055+
branch?: string;
1056+
};
1057+
status: PrebuiltWorkspaceState;
1058+
searchTerm?: string;
1059+
},
1060+
): Promise<PrebuiltWorkspace[]> {
1061+
const repo = await this.getPrebuiltWorkspaceRepo();
1062+
const query = repo
1063+
.createQueryBuilder("pws")
1064+
.orderBy("pws.creationTime", "DESC")
1065+
.innerJoinAndMapOne(
1066+
"pws.workspace",
1067+
DBWorkspace,
1068+
"ws",
1069+
"pws.buildWorkspaceId = ws.id AND ws.organizationId = :organizationId",
1070+
{ organizationId },
1071+
)
1072+
.skip(offset)
1073+
.take(limit);
1074+
1075+
if (filter?.status) {
1076+
query.andWhere("pws.state = :state", { state: filter.status });
1077+
}
1078+
1079+
if (filter?.configuration?.id) {
1080+
query.andWhere("pws.projectId = :projectId", { projectId: filter.configuration.id });
1081+
if (filter.configuration.branch) {
1082+
query.andWhere("pws.branch = :branch", { branch: filter.configuration.branch });
1083+
}
1084+
}
1085+
1086+
const normalizedSearchTerm = filter?.searchTerm?.trim();
1087+
if (normalizedSearchTerm) {
1088+
query.innerJoinAndMapOne("pws.project", DBProject, "project", "pws.projectId = project.id");
1089+
query.andWhere(
1090+
new Brackets((qb) => {
1091+
qb.where("project.cloneUrl LIKE :searchTerm", {
1092+
searchTerm: `%${normalizedSearchTerm}%`,
1093+
}).orWhere("project.name LIKE :searchTerm", { searchTerm: `%${normalizedSearchTerm}%` });
1094+
}),
1095+
);
1096+
}
1097+
1098+
return query.getMany();
1099+
}
1100+
10391101
async findPrebuiltWorkspaceById(id: string): Promise<PrebuiltWorkspace | undefined> {
10401102
const repo = await this.getPrebuiltWorkspaceRepo();
10411103

components/gitpod-db/src/workspace-db.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
PrebuildInfo,
2121
AdminGetWorkspacesQuery,
2222
SnapshotState,
23+
PrebuiltWorkspaceState,
2324
} from "@gitpod/gitpod-protocol";
2425

2526
export type MaybeWorkspace = Workspace | undefined;
@@ -170,6 +171,19 @@ export interface WorkspaceDB {
170171
hardDeleteWorkspace(workspaceID: string): Promise<void>;
171172

172173
findPrebuiltWorkspacesByProject(projectId: string, branch?: string, limit?: number): Promise<PrebuiltWorkspace[]>;
174+
findPrebuiltWorkspacesByOrganization(
175+
organizationId: string,
176+
offset?: number,
177+
limit?: number,
178+
filter?: {
179+
configuration?: {
180+
id: string;
181+
branch?: string;
182+
};
183+
status?: PrebuiltWorkspaceState;
184+
searchTerm?: string;
185+
},
186+
): Promise<PrebuiltWorkspace[]>;
173187
findPrebuiltWorkspaceById(prebuildId: string): Promise<PrebuiltWorkspace | undefined>;
174188

175189
storePrebuildInfo(prebuildInfo: PrebuildInfo): Promise<void>;

components/public-api/gitpod/v1/prebuild.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ message WatchPrebuildResponse {
6666

6767
message ListOrganizationPrebuildsRequest {
6868
message Filter {
69+
message Configuration {
70+
string id = 1;
71+
string branch = 2;
72+
}
6973
PrebuildPhase.Phase status = 1;
70-
string configuration_id = 2;
74+
Configuration configuration = 2;
7175
// Filter the search down by searching for configuration names matching the
7276
// query
7377
string search_term = 3;

0 commit comments

Comments
 (0)