1import { ReviewOutput, ReviewStatus } from './types'; 2 3/** 4 * Generates the review comment based on given outputs and the commit the checks were run against. 5 */ 6export function generateReviewBodyFromOutputs( 7 outputs: ReviewOutput[], 8 hasComments: boolean, 9 commitSha: string 10): string { 11 return [ 12 "*Hi there! I'm a bot whose goal is to ensure your contributions meet our guidelines.*", 13 header(outputs, hasComments), 14 outputs.map(reportForOutput).join('\n'), 15 footerForCommit(commitSha), 16 ] 17 .filter(Boolean) 18 .join('\n\n'); 19} 20 21/** 22 * Generates a report based on given review output. 23 */ 24function reportForOutput(output: ReviewOutput): string { 25 return `<details> 26 <summary><strong>${prefixForStatus(output.status)}</strong>: ${output.title}</summary> 27 28\\ 29${output.body} 30</details> 31 32---`; 33} 34 35/** 36 * Returns appropriate header for the review, depending on review results. 37 */ 38function header(outputs: ReviewOutput[], hasComments: boolean): string { 39 if (outputs.length > 0) { 40 return `I've found some issues in your pull request that should be addressed (click on them to expand) `; 41 } 42 if (hasComments) { 43 return `It's pretty good I just have a few comments to consider `; 44 } 45 return 'Looks like I have nothing to complain about Keep up the good work! '; 46} 47 48/** 49 * Returns review body footer containing commit hash against which the review was made. 50 */ 51function footerForCommit(sha: string): string { 52 return `*Generated by ExpoBot against ${sha}*`; 53} 54 55/** 56 * Returns title prefix depending on the status. 57 */ 58function prefixForStatus(status: ReviewStatus): string { 59 switch (status) { 60 case ReviewStatus.WARN: 61 return '⚠️ Warning'; 62 case ReviewStatus.ERROR: 63 return '❌ Error'; 64 } 65 return ''; 66} 67