@@ -15,6 +15,8 @@ import {
1515 DeleteConfigurationRequest ,
1616 DeleteConfigurationResponse ,
1717 GetConfigurationRequest ,
18+ GetConfigurationWebhookActivityStatusRequest ,
19+ GetConfigurationWebhookActivityStatusResponse ,
1820 ListConfigurationsRequest ,
1921 ListConfigurationsResponse ,
2022 PrebuildSettings ,
@@ -30,6 +32,8 @@ import { SortOrder } from "@gitpod/public-api/lib/gitpod/v1/sorting_pb";
3032import { Project } from "@gitpod/gitpod-protocol" ;
3133import { DeepPartial } from "@gitpod/gitpod-protocol/lib/util/deep-partial" ;
3234import { ContextService } from "../workspace/context-service" ;
35+ import { PrebuildManager } from "../prebuilds/prebuild-manager" ;
36+ import { Timestamp } from "@bufbuild/protobuf" ;
3337
3438function buildUpdateObject < T extends Record < string , any > > ( obj : T ) : Partial < T > {
3539 const update : Partial < T > = { } ;
@@ -58,6 +62,8 @@ export class ConfigurationServiceAPI implements ServiceImpl<typeof Configuration
5862 private readonly userService : UserService ,
5963 @inject ( ContextService )
6064 private readonly contextService : ContextService ,
65+ @inject ( PrebuildManager )
66+ private readonly prebuildManager : PrebuildManager ,
6167 ) { }
6268
6369 async createConfiguration (
@@ -238,4 +244,27 @@ export class ConfigurationServiceAPI implements ServiceImpl<typeof Configuration
238244
239245 return new DeleteConfigurationResponse ( ) ;
240246 }
247+
248+ async getConfigurationWebhookActivityStatus ( req : GetConfigurationWebhookActivityStatusRequest , _ : HandlerContext ) {
249+ if ( ! req . configurationId ) {
250+ throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "configuration_id is required" ) ;
251+ }
252+
253+ const configuration = await this . projectService . getProject ( ctxUserId ( ) , req . configurationId ) ;
254+ if ( ! configuration ) {
255+ throw new ApplicationError ( ErrorCodes . NOT_FOUND , "configuration not found" ) ;
256+ }
257+ const user = await this . userService . findUserById ( ctxUserId ( ) , ctxUserId ( ) ) ;
258+ const event = await this . prebuildManager . getRecentWebhookEvent ( { } , user , configuration ) ;
259+
260+ const resp = new GetConfigurationWebhookActivityStatusResponse ( {
261+ isWebhookActive : event !== undefined ,
262+ latestWebhookEvent : {
263+ commit : event ?. commit ,
264+ creationTime : event ?. creationTime ? Timestamp . fromDate ( new Date ( event . creationTime ) ) : undefined ,
265+ } ,
266+ } ) ;
267+
268+ return resp ;
269+ }
241270}
0 commit comments