4
4
* See License.enterprise.txt in the project root folder.
5
5
*/
6
6
7
- import { Probot , Application , Context } from 'probot' ;
8
- import { findPrivateKey } from 'probot/lib/ private-key' ;
7
+ import { Probot , Context } from 'probot' ;
8
+ import { getPrivateKey } from '@ probot/get- private-key' ;
9
9
import * as fs from 'fs-extra' ;
10
10
import { injectable , inject , decorate } from 'inversify' ;
11
11
import { Env } from '../../../src/env' ;
@@ -24,6 +24,7 @@ import { TraceContext } from '@gitpod/gitpod-protocol/lib/util/tracing';
24
24
import { TracedWorkspaceDB , DBWithTracing } from '@gitpod/gitpod-db/lib/traced-db' ;
25
25
import { PrebuildManager } from './prebuild-manager' ;
26
26
import { PrebuildStatusMaintainer } from './prebuilt-status-maintainer' ;
27
+ import { ApplicationFunctionOptions } from 'probot/lib/types' ;
27
28
28
29
/**
29
30
* GitHub app urls:
@@ -53,7 +54,7 @@ export class GithubApp extends Probot {
53
54
) {
54
55
super ( {
55
56
id : env . githubAppAppID ,
56
- cert : GithubApp . loadPrivateKey ( env . githubAppCertPath ) ,
57
+ privateKey : GithubApp . loadPrivateKey ( env . githubAppCertPath ) ,
57
58
secret : env . githubAppWebhookSecret
58
59
} ) ;
59
60
log . debug ( "Starting GitHub app integration" , {
@@ -65,7 +66,8 @@ export class GithubApp extends Probot {
65
66
this . load ( this . buildApp . bind ( this ) ) ;
66
67
}
67
68
68
- protected async buildApp ( app : Application ) {
69
+ protected async buildApp ( options : ApplicationFunctionOptions ) {
70
+ const app = options . app ;
69
71
this . statusMaintainer . start ( async id => ( await app . auth ( parseInt ( id ) ) ) as any as Octokit ) ;
70
72
// this.queueMaintainer.start();
71
73
@@ -105,14 +107,17 @@ export class GithubApp extends Probot {
105
107
} ) ;
106
108
107
109
app . on ( 'installation.created' , async ctx => {
108
- const authId : string = ctx . payload . installation . account . id ;
109
- const user = await this . userDB . findUserByIdentity ( { authProviderId : this . env . githubAppAuthProviderId , authId } ) ;
110
+ const accountId : string = `${ ctx . payload . installation . account . id } ` ;
111
+ const installationId = `${ ctx . payload . installation . id } ` ;
112
+ const senderId = `${ ctx . payload . sender . id } ` ;
113
+ const user = await this . userDB . findUserByIdentity ( { authProviderId : this . env . githubAppAuthProviderId , authId : accountId } ) ;
110
114
const userId = user ? user . id : undefined ;
111
- await this . appInstallationDB . recordNewInstallation ( "github" , 'platform' , ctx . payload . installation . id , userId , ctx . payload . sender . id ) ;
115
+ await this . appInstallationDB . recordNewInstallation ( "github" , 'platform' , installationId , userId , senderId ) ;
112
116
log . debug ( { userId } , "New installation recorded" , { userId, platformUserId : ctx . payload . sender . id } )
113
117
} ) ;
114
118
app . on ( 'installation.deleted' , async ctx => {
115
- await this . appInstallationDB . recordUninstallation ( "github" , 'platform' , ctx . payload . installation . id ) ;
119
+ const installationId = `${ ctx . payload . installation . id } ` ;
120
+ await this . appInstallationDB . recordUninstallation ( "github" , 'platform' , installationId ) ;
116
121
} ) ;
117
122
118
123
app . on ( 'push' , async ctx => {
@@ -412,14 +417,13 @@ export namespace GithubApp {
412
417
}
413
418
414
419
// loadPrivateKey is used in super call - must not be async
415
- if ( filename && fs . existsSync ( filename ) ) {
416
- const key = findPrivateKey ( filename ) ;
420
+ if ( fs . existsSync ( filename ) ) {
421
+ const key = getPrivateKey ( { filepath : filename } ) ;
417
422
if ( key ) {
418
423
return key . toString ( ) ;
419
424
}
420
425
}
421
426
}
422
-
423
427
}
424
428
425
429
class PrebuildListener {
0 commit comments