@@ -43,12 +43,24 @@ const ACCEPTED_COLOR_PROPS = Object.keys(COLOR_PROPS);
43
43
const REQUIRED_COLOR_PROPS = ACCEPTED_COLOR_PROPS . slice ( 0 , 4 ) ;
44
44
const INVALID_REVIEW_COMMENT = ( commentUrl ) =>
45
45
`Some themes are invalid. See the [Automated Theme Preview](${ commentUrl } ) comment above for more information.` ;
46
-
47
- // Retrieve octokit instance.
48
- const OCTOKIT = github . getOctokit ( getGithubToken ( ) ) ;
49
- const { OWNER , REPO } = getRepoInfo ( github . context ) ;
46
+ var OCTOKIT ;
47
+ var OWNER ;
48
+ var REPO ;
50
49
var PULL_REQUEST_ID ;
51
50
51
+ /**
52
+ * Incorrect JSON format error.
53
+ * @extends Error
54
+ * @param {string } message Error message.
55
+ * @returns {Error } IncorrectJsonFormatError.
56
+ */
57
+ class IncorrectJsonFormatError extends Error {
58
+ constructor ( message ) {
59
+ super ( message ) ;
60
+ this . name = "IncorrectJsonFormatError" ;
61
+ }
62
+ }
63
+
52
64
/**
53
65
* Retrieve PR number from the event payload.
54
66
*
@@ -274,7 +286,9 @@ const parseJSON = (json) => {
274
286
if ( typeof parsedJson === "object" ) {
275
287
return parsedJson ;
276
288
} else {
277
- throw new Error ( "PR diff is not a valid theme JSON object." ) ;
289
+ throw new IncorrectJsonFormatError (
290
+ "PR diff is not a valid theme JSON object." ,
291
+ ) ;
278
292
}
279
293
} catch ( error ) {
280
294
let parsedJson = json
@@ -289,7 +303,9 @@ const parseJSON = (json) => {
289
303
}
290
304
return Hjson . parse ( parsedJson . join ( "" ) ) ;
291
305
} else {
292
- throw error ;
306
+ throw new IncorrectJsonFormatError (
307
+ `Theme JSON file could not be parsed: ${ error . message } ` ,
308
+ ) ;
293
309
}
294
310
}
295
311
} ;
@@ -317,6 +333,11 @@ export const run = async () => {
317
333
\r${ THEME_CONTRIB_GUIDELINESS }
318
334
` ;
319
335
const ccc = new ColorContrastChecker ( ) ;
336
+ OCTOKIT = github . getOctokit ( getGithubToken ( ) ) ;
337
+ PULL_REQUEST_ID = getPrNumber ( ) ;
338
+ const { owner, repo } = getRepoInfo ( github . context ) ;
339
+ OWNER = owner ;
340
+ REPO = repo ;
320
341
const commenter = getCommenter ( ) ;
321
342
PULL_REQUEST_ID = getPrNumber ( ) ;
322
343
debug ( `Owner: ${ OWNER } ` ) ;
@@ -326,8 +347,8 @@ export const run = async () => {
326
347
// Retrieve the PR diff and preview-theme comment.
327
348
debug ( "Retrieve PR diff..." ) ;
328
349
const res = await OCTOKIT . pulls . get ( {
329
- OWNER ,
330
- REPO ,
350
+ owner : OWNER ,
351
+ repo : REPO ,
331
352
pull_number : PULL_REQUEST_ID ,
332
353
mediaType : {
333
354
format : "diff" ,
@@ -569,7 +590,9 @@ export const run = async () => {
569
590
OWNER ,
570
591
REPO ,
571
592
"REQUEST_CHANGES" ,
572
- error . message ,
593
+ "**Something went wrong in the theme preview action:** `" +
594
+ error . message +
595
+ "`" ,
573
596
) ;
574
597
await addRemoveLabel (
575
598
OCTOKIT ,
0 commit comments