@@ -36,7 +36,9 @@ export class BitbucketApp {
36
36
}
37
37
const user = await this . findUser ( { span } , secretToken ) ;
38
38
if ( ! user ) {
39
- res . statusCode = 503 ;
39
+ // If the webhook installer is no longer found in Gitpod's DB
40
+ // we should send a UNAUTHORIZED signal.
41
+ res . statusCode = 401 ;
40
42
res . send ( ) ;
41
43
return ;
42
44
}
@@ -45,13 +47,13 @@ export class BitbucketApp {
45
47
await this . handlePushHook ( { span } , data , user ) ;
46
48
}
47
49
} else {
48
- console . log ( `Ignoring unsupported bitbucket event: ${ req . header ( 'X-Event-Key' ) } ` ) ;
50
+ console . warn ( `Ignoring unsupported bitbucket event: ${ req . header ( 'X-Event-Key' ) } ` ) ;
49
51
}
50
- res . send ( 'OK' ) ;
51
52
} catch ( err ) {
52
- console . error ( `Couldn't handle request.` , req . headers , req . body ) ;
53
- console . error ( err ) ;
54
- res . sendStatus ( 500 ) ;
53
+ console . error ( `Couldn't handle request.` , err , { headers : req . headers , reqBody : req . body } ) ;
54
+ } finally {
55
+ // we always respond with OK, when we received a valid event.
56
+ res . sendStatus ( 200 ) ;
55
57
}
56
58
} ) ;
57
59
}
@@ -89,7 +91,7 @@ export class BitbucketApp {
89
91
span . setTag ( 'contextURL' , contextURL ) ;
90
92
const config = await this . prebuildManager . fetchConfig ( { span } , user , contextURL ) ;
91
93
if ( ! this . prebuildManager . shouldPrebuild ( config ) ) {
92
- console . log ( 'No config. No prebuild.' ) ;
94
+ console . log ( 'Bitbucket push event: No config. No prebuild.' ) ;
93
95
return undefined ;
94
96
}
95
97
@@ -159,7 +161,7 @@ export class BitbucketApp {
159
161
function toData ( body : BitbucketPushHook ) : ParsedRequestData | undefined {
160
162
const branchName = body . push . changes [ 0 ] ?. new ?. name ;
161
163
const commitHash = body . push . changes [ 0 ] ?. new ?. target ?. hash ;
162
- if ( ! branchName || ! commitHash ) {
164
+ if ( ! branchName || ! commitHash ) {
163
165
return undefined ;
164
166
}
165
167
const result = {
@@ -169,7 +171,7 @@ function toData(body: BitbucketPushHook): ParsedRequestData | undefined {
169
171
gitCloneUrl : body . repository . links . html . href + '.git'
170
172
}
171
173
if ( ! result . commitHash || ! result . repoUrl ) {
172
- console . error ( 'unexpected request body.' , body ) ;
174
+ console . error ( 'Bitbucket push event: unexpected request body.' , body ) ;
173
175
throw new Error ( 'Unexpected request body.' ) ;
174
176
}
175
177
return result ;
0 commit comments