1import { ReviewOutput, ReviewStatus } from './types'; 2 3// We add this at the top of each report to identify which ones come from this command. 4export const COMMENT_HEADER = `<!-- Made with ❤️ by \`expotools code-review\` -->`; 5 6/** 7 * Generates the report based on given outputs and the commit the checks were run against. 8 */ 9export function generateReportFromOutputs(outputs: ReviewOutput[], commitSha: string): string { 10 return [ 11 COMMENT_HEADER, 12 "*Hi there! I'm a bot whose goal is to ensure your contributions meet our guidelines.*", 13 header(outputs), 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 * Returns appropriate header for the review, depending on review results. 36 */ 37function header(outputs: ReviewOutput[]): string { 38 if (outputs.length > 0) { 39 return `I've found some issues in your pull request that should be addressed (click on them for more details) `; 40 } 41 return 'Looks like I have nothing to complain about Keep up the good work! '; 42} 43 44/** 45 * Returns review body footer containing commit hash against which the review was made. 46 */ 47function footerForCommit(sha: string): string { 48 return `---\n*Generated by ExpoBot against ${sha}*`; 49} 50 51/** 52 * Returns title prefix depending on the status. 53 */ 54function prefixForStatus(status: ReviewStatus): string { 55 switch (status) { 56 case ReviewStatus.WARN: 57 return '⚠️ Suggestion'; 58 case ReviewStatus.ERROR: 59 return '❌ Error'; 60 } 61 return ''; 62} 63