@@ -172,18 +172,18 @@ const upsertComment = async (
172
172
body ,
173
173
) => {
174
174
let resp ;
175
- if ( commentId ! == undefined ) {
176
- resp = await octokit . rest . issues . updateComment ( {
175
+ if ( commentId = == undefined ) {
176
+ resp = await octokit . rest . issues . createComment ( {
177
177
owner,
178
178
repo,
179
- comment_id : commentId ,
179
+ issue_number : issueNumber ,
180
180
body,
181
181
} ) ;
182
182
} else {
183
- resp = await octokit . rest . issues . createComment ( {
183
+ resp = await octokit . rest . issues . updateComment ( {
184
184
owner,
185
185
repo,
186
- issue_number : issueNumber ,
186
+ comment_id : commentId ,
187
187
body,
188
188
} ) ;
189
189
}
@@ -341,10 +341,10 @@ const parseJSON = (json) => {
341
341
. filter ( ( x ) => typeof x !== "string" || ! ! x . trim ( ) ) ; // Split json into array of strings and objects.
342
342
if ( splitJson [ 0 ] . replace ( / \s + / g, "" ) === "}," ) {
343
343
splitJson [ 0 ] = "}," ;
344
- if ( ! / \s * } \s * , ? \s * $ / . test ( splitJson [ 1 ] ) ) {
345
- splitJson . push ( splitJson . shift ( ) ) ;
346
- } else {
344
+ if ( / \s * } \s * , ? \s * $ / . test ( splitJson [ 1 ] ) ) {
347
345
splitJson . shift ( ) ;
346
+ } else {
347
+ splitJson . push ( splitJson . shift ( ) ) ;
348
348
}
349
349
parsedJson = splitJson . join ( "" ) ;
350
350
}
@@ -466,10 +466,7 @@ export const run = async () => {
466
466
// Check if the theme colors are valid.
467
467
debug ( "Theme preview body: Check if the theme colors are valid..." ) ;
468
468
let invalidColors = false ;
469
- if ( ! colors ) {
470
- warnings . push ( "Theme colors are missing" ) ;
471
- invalidColors = true ;
472
- } else {
469
+ if ( colors ) {
473
470
const missingKeys = REQUIRED_COLOR_PROPS . filter (
474
471
( x ) => ! Object . keys ( colors ) . includes ( x ) ,
475
472
) ;
@@ -507,6 +504,9 @@ export const run = async () => {
507
504
}
508
505
}
509
506
}
507
+ } else {
508
+ warnings . push ( "Theme colors are missing" ) ;
509
+ invalidColors = true ;
510
510
}
511
511
if ( invalidColors ) {
512
512
themeValid [ theme ] = false ;
@@ -597,7 +597,10 @@ export const run = async () => {
597
597
// Create or update theme-preview comment.
598
598
debug ( "Create or update theme-preview comment..." ) ;
599
599
let comment_url ;
600
- if ( ! DRY_RUN ) {
600
+ if ( DRY_RUN ) {
601
+ info ( `DRY_RUN: Comment body: ${ commentBody } ` ) ;
602
+ comment_url = "" ;
603
+ } else {
601
604
comment_url = await upsertComment (
602
605
OCTOKIT ,
603
606
PULL_REQUEST_ID ,
@@ -606,9 +609,6 @@ export const run = async () => {
606
609
comment ?. id ,
607
610
commentBody ,
608
611
) ;
609
- } else {
610
- info ( `DRY_RUN: Comment body: ${ commentBody } ` ) ;
611
- comment_url = "" ;
612
612
}
613
613
614
614
// Change review state and add/remove `invalid` label based on theme PR validity.
@@ -620,7 +620,10 @@ export const run = async () => {
620
620
const reviewReason = themesValid
621
621
? undefined
622
622
: INVALID_REVIEW_COMMENT ( comment_url ) ;
623
- if ( ! DRY_RUN ) {
623
+ if ( DRY_RUN ) {
624
+ info ( `DRY_RUN: Review state: ${ reviewState } ` ) ;
625
+ info ( `DRY_RUN: Review reason: ${ reviewReason } ` ) ;
626
+ } else {
624
627
await addReview (
625
628
OCTOKIT ,
626
629
PULL_REQUEST_ID ,
@@ -637,13 +640,13 @@ export const run = async () => {
637
640
"invalid" ,
638
641
! themesValid ,
639
642
) ;
640
- } else {
641
- info ( `DRY_RUN: Review state: ${ reviewState } ` ) ;
642
- info ( `DRY_RUN: Review reason: ${ reviewReason } ` ) ;
643
643
}
644
644
} catch ( error ) {
645
645
debug ( "Set review state to `REQUEST_CHANGES` and add `invalid` label..." ) ;
646
- if ( ! DRY_RUN ) {
646
+ if ( DRY_RUN ) {
647
+ info ( `DRY_RUN: Review state: REQUEST_CHANGES` ) ;
648
+ info ( `DRY_RUN: Review reason: ${ error . message } ` ) ;
649
+ } else {
647
650
await addReview (
648
651
OCTOKIT ,
649
652
PULL_REQUEST_ID ,
@@ -662,9 +665,6 @@ export const run = async () => {
662
665
"invalid" ,
663
666
true ,
664
667
) ;
665
- } else {
666
- info ( `DRY_RUN: Review state: REQUEST_CHANGES` ) ;
667
- info ( `DRY_RUN: Review reason: ${ error . message } ` ) ;
668
668
}
669
669
setFailed ( error . message ) ;
670
670
}
0 commit comments