6
6
7
7
import { inject , injectable } from "inversify" ;
8
8
import * as grpc from "@grpc/grpc-js" ;
9
- import { WorkspaceDB } from "@gitpod/gitpod-db/lib" ;
9
+ import { RedisPublisher , WorkspaceDB } from "@gitpod/gitpod-db/lib" ;
10
10
import {
11
11
GitpodServer ,
12
12
PortProtocol ,
@@ -18,6 +18,7 @@ import {
18
18
WorkspaceContext ,
19
19
WorkspaceInstance ,
20
20
WorkspaceInstancePort ,
21
+ WorkspaceInstanceRepoStatus ,
21
22
WorkspaceSoftDeletion ,
22
23
} from "@gitpod/gitpod-protocol" ;
23
24
import { ErrorCodes , ApplicationError } from "@gitpod/gitpod-protocol/lib/messaging/error" ;
@@ -42,6 +43,8 @@ import { RegionService } from "./region-service";
42
43
import { ProjectsService } from "../projects/projects-service" ;
43
44
import { EnvVarService } from "../user/env-var-service" ;
44
45
import { WorkspaceManagerClientProvider } from "@gitpod/ws-manager/lib/client-provider" ;
46
+ import { SupportedWorkspaceClass } from "@gitpod/gitpod-protocol/lib/workspace-class" ;
47
+ import { Config } from "../config" ;
45
48
46
49
export interface StartWorkspaceOptions extends GitpodServer . StartWorkspaceOptions {
47
50
/**
@@ -53,13 +56,15 @@ export interface StartWorkspaceOptions extends GitpodServer.StartWorkspaceOption
53
56
@injectable ( )
54
57
export class WorkspaceService {
55
58
constructor (
59
+ @inject ( Config ) private readonly config : Config ,
56
60
@inject ( WorkspaceFactory ) private readonly factory : WorkspaceFactory ,
57
61
@inject ( WorkspaceStarter ) private readonly workspaceStarter : WorkspaceStarter ,
58
62
@inject ( WorkspaceManagerClientProvider ) private readonly clientProvider : WorkspaceManagerClientProvider ,
59
63
@inject ( WorkspaceDB ) private readonly db : WorkspaceDB ,
60
64
@inject ( EntitlementService ) private readonly entitlementService : EntitlementService ,
61
65
@inject ( EnvVarService ) private readonly envVarService : EnvVarService ,
62
66
@inject ( ProjectsService ) private readonly projectsService : ProjectsService ,
67
+ @inject ( RedisPublisher ) private readonly publisher : RedisPublisher ,
63
68
@inject ( Authorizer ) private readonly auth : Authorizer ,
64
69
) { }
65
70
@@ -539,6 +544,40 @@ export class WorkspaceService {
539
544
await this . auth . checkPermissionOnWorkspace ( userId , "access" , workspaceId ) ;
540
545
await this . db . updatePartial ( workspaceId , { description } ) ;
541
546
}
547
+
548
+ public async updateGitStatus (
549
+ userId : string ,
550
+ workspaceId : string ,
551
+ gitStatus : Required < WorkspaceInstanceRepoStatus > | undefined ,
552
+ ) {
553
+ await this . auth . checkPermissionOnWorkspace ( userId , "access" , workspaceId ) ;
554
+
555
+ let instance = await this . getCurrentInstance ( userId , workspaceId ) ;
556
+ if ( WorkspaceInstanceRepoStatus . equals ( instance . gitStatus , gitStatus ) ) {
557
+ return ;
558
+ }
559
+
560
+ const workspace = await this . getWorkspace ( userId , workspaceId ) ;
561
+ instance = await this . db . updateInstancePartial ( instance . id , { gitStatus } ) ;
562
+ await this . publisher . publishInstanceUpdate ( {
563
+ instanceID : instance . id ,
564
+ ownerID : workspace . ownerId ,
565
+ workspaceID : workspace . id ,
566
+ } ) ;
567
+ }
568
+
569
+ public async getSupportedWorkspaceClasses ( userId : string ) : Promise < SupportedWorkspaceClass [ ] > {
570
+ // No access check required, valid session/user is enough
571
+ const classes = this . config . workspaceClasses . map ( ( c ) => ( {
572
+ id : c . id ,
573
+ category : c . category ,
574
+ displayName : c . displayName ,
575
+ description : c . description ,
576
+ powerups : c . powerups ,
577
+ isDefault : c . isDefault ,
578
+ } ) ) ;
579
+ return classes ;
580
+ }
542
581
}
543
582
544
583
// TODO(gpl) Make private after FGA rollout
0 commit comments