@@ -15,7 +15,7 @@ import {
15
15
CommitContext ,
16
16
RefType ,
17
17
} from "@gitpod/gitpod-protocol" ;
18
- import { GitHubGraphQlEndpoint } from "./api" ;
18
+ import { GitHubGraphQlEndpoint , QueryResult } from "./api" ;
19
19
import { NotFoundError , UnauthorizedError } from "../errors" ;
20
20
import { log , LogContext , LogPayload } from "@gitpod/gitpod-protocol/lib/util/logging" ;
21
21
import { IContextParser , IssueContexts , AbstractContextParser } from "../workspace/context-parser" ;
@@ -24,6 +24,7 @@ import { GitHubTokenHelper } from "./github-token-helper";
24
24
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing" ;
25
25
import { RepoURL } from "../repohost" ;
26
26
import { containsScopes } from "../prebuilds/token-scopes-inclusion" ;
27
+ import { TrustedValue } from "@gitpod/gitpod-protocol/lib/util/scrubbing" ;
27
28
28
29
@injectable ( )
29
30
export class GithubContextParser extends AbstractContextParser implements IContextParser {
@@ -116,9 +117,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
116
117
const span = TraceContext . startSpan ( "GithubContextParser.handleDefaultContext" , ctx ) ;
117
118
118
119
try {
119
- const result : any = await this . githubQueryApi . runQuery (
120
- user ,
121
- `
120
+ const query = `
122
121
query {
123
122
repository(name: "${ repoName } ", owner: "${ owner } ") {
124
123
${ this . repoProperties ( ) }
@@ -130,11 +129,16 @@ export class GithubContextParser extends AbstractContextParser implements IConte
130
129
},
131
130
}
132
131
}
133
- ` ,
134
- ) ;
132
+ ` ;
133
+ const result : QueryResult < any > = await this . githubQueryApi . runQuery ( user , query ) ;
135
134
span . log ( { "request.finished" : "" } ) ;
136
135
136
+ if ( result . errors ) {
137
+ log . error ( "Errors executing query." , { query, errors : new TrustedValue ( result . errors ) } ) ;
138
+ }
139
+
137
140
if ( result . data . repository === null ) {
141
+ log . warn ( `Repository not found.` , { query } ) ;
138
142
throw await NotFoundError . create (
139
143
await this . tokenHelper . getCurrentToken ( user ) ,
140
144
user ,
@@ -184,9 +188,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
184
188
const path = decodeURIComponent ( segments . slice ( i ) . join ( "/" ) ) ;
185
189
// Sanitize path expression to prevent GraphQL injections (e.g. escape any `"` or `\n`).
186
190
const pathExpression = JSON . stringify ( `${ branchNameOrCommitHash } :${ path } ` ) ;
187
- const result : any = await this . githubQueryApi . runQuery (
188
- user ,
189
- `
191
+ const query = `
190
192
query {
191
193
repository(name: "${ repoName } ", owner: "${ owner } ") {
192
194
${ this . repoProperties ( ) }
@@ -213,12 +215,16 @@ export class GithubContextParser extends AbstractContextParser implements IConte
213
215
}
214
216
}
215
217
}
216
- ` ,
217
- ) ;
218
+ ` ;
219
+ const result : QueryResult < any > = await this . githubQueryApi . runQuery ( user , query ) ;
218
220
span . log ( { "request.finished" : "" } ) ;
221
+ if ( result . errors ) {
222
+ log . error ( "Errors executing query." , { query, errors : new TrustedValue ( result . errors ) } ) ;
223
+ }
219
224
220
225
const repo = result . data . repository ;
221
226
if ( repo === null ) {
227
+ log . warn ( `Repository not found.` , { query } ) ;
222
228
throw await NotFoundError . create (
223
229
await this . tokenHelper . getCurrentToken ( user ) ,
224
230
user ,
@@ -293,9 +299,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
293
299
}
294
300
295
301
try {
296
- const result : any = await this . githubQueryApi . runQuery (
297
- user ,
298
- `
302
+ const query = `
299
303
query {
300
304
repository(name: "${ repoName } ", owner: "${ owner } ") {
301
305
object(oid: "${ sha } ") {
@@ -313,11 +317,17 @@ export class GithubContextParser extends AbstractContextParser implements IConte
313
317
},
314
318
}
315
319
}
316
- ` ,
317
- ) ;
320
+ ` ;
321
+ const result : QueryResult < any > = await this . githubQueryApi . runQuery ( user , query ) ;
318
322
span . log ( { "request.finished" : "" } ) ;
319
323
324
+ if ( result . errors ) {
325
+ log . error ( "Errors executing query." , { query, errors : new TrustedValue ( result . errors ) } ) ;
326
+ }
327
+
320
328
if ( result . data . repository === null ) {
329
+ log . warn ( `Repository not found.` , { query } ) ;
330
+
321
331
throw await NotFoundError . create (
322
332
await this . tokenHelper . getCurrentToken ( user ) ,
323
333
user ,
@@ -362,9 +372,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
362
372
const span = TraceContext . startSpan ( "handlePullRequestContext" , ctx ) ;
363
373
364
374
try {
365
- const result : any = await this . githubQueryApi . runQuery (
366
- user ,
367
- `
375
+ const query = `
368
376
query {
369
377
repository(name: "${ repoName } ", owner: "${ owner } ") {
370
378
pullRequest(number: ${ pullRequestNr } ) {
@@ -402,11 +410,17 @@ export class GithubContextParser extends AbstractContextParser implements IConte
402
410
}
403
411
}
404
412
}
405
- ` ,
406
- ) ;
413
+ ` ;
414
+ const result : QueryResult < any > = await this . githubQueryApi . runQuery ( user , query ) ;
407
415
span . log ( { "request.finished" : "" } ) ;
408
416
417
+ if ( result . errors ) {
418
+ log . error ( "Errors executing query." , { query, errors : new TrustedValue ( result . errors ) } ) ;
419
+ }
420
+
409
421
if ( result . data . repository === null ) {
422
+ log . warn ( `Repository not found.` , { query } ) ;
423
+
410
424
throw await NotFoundError . create (
411
425
await this . tokenHelper . getCurrentToken ( user ) ,
412
426
user ,
@@ -464,9 +478,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
464
478
const span = TraceContext . startSpan ( "handleIssueContext" , ctx ) ;
465
479
466
480
try {
467
- const result : any = await this . githubQueryApi . runQuery (
468
- user ,
469
- `
481
+ const query = `
470
482
query {
471
483
repository(name: "${ repoName } ", owner: "${ owner } ") {
472
484
issue(number: ${ issueNr } ) {
@@ -481,11 +493,17 @@ export class GithubContextParser extends AbstractContextParser implements IConte
481
493
},
482
494
}
483
495
}
484
- ` ,
485
- ) ;
496
+ ` ;
497
+ const result : QueryResult < any > = await this . githubQueryApi . runQuery ( user , query ) ;
486
498
span . log ( { "request.finished" : "" } ) ;
487
499
500
+ if ( result . errors ) {
501
+ log . error ( "Errors executing query." , { query, errors : new TrustedValue ( result . errors ) } ) ;
502
+ }
503
+
488
504
if ( result . data . repository === null ) {
505
+ log . warn ( `Repository not found.` , { query } ) ;
506
+
489
507
throw await NotFoundError . create (
490
508
await this . tokenHelper . getCurrentToken ( user ) ,
491
509
user ,
0 commit comments