From 4471cb3de2f786da4b80ccab76db4cae08e48fce Mon Sep 17 00:00:00 2001
From: Nikhil Bhoski <47204011+nbhoski@users.noreply.github.com>
Date: Wed, 22 May 2024 15:43:21 +0530
Subject: [PATCH] Refactored mathods for good readability

---
 src/buildSummary.ts | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/buildSummary.ts b/src/buildSummary.ts
index 641e635..cefdcf7 100644
--- a/src/buildSummary.ts
+++ b/src/buildSummary.ts
@@ -1,5 +1,6 @@
 // Copyright 2024 The MathWorks, Inc.
 import * as core from "@actions/core";
+import { join } from 'path';
 import { readFile } from 'fs';
 import { promisify } from 'util';
 
@@ -28,7 +29,7 @@ export async function readJsonFile(filePath: string): Promise<TaskList> {
   }
 }
 
-export function addBuildSummaryTable(tasks: TaskList): void {
+export function getBuildSummaryTable(tasks: TaskList): string[][] {
   const header: string[] = ['Task Name', 'Status', 'Description', 'Duration (HH:MM:SS)'];
   let taskSummaryTableRows: string[][] = [header];
 
@@ -48,10 +49,14 @@ export function addBuildSummaryTable(tasks: TaskList): void {
     taskSummaryTableRows.push(taskDetails);
   });
 
-  core.summary
-    .addHeading('MATLAB Build Results')
-    .addTable(taskSummaryTableRows)
-    .write();
+  return taskSummaryTableRows;
+}
+
+export function writeSummary(taskSummaryTableRows: string[][]) {
+    core.summary
+      .addHeading('MATLAB Build Results')
+      .addTable(taskSummaryTableRows)
+      .write();
 }
 
 export async function processAndDisplayBuildSummary() {
@@ -64,9 +69,10 @@ export async function processAndDisplayBuildSummary() {
 
   try {
     const runnerTemp = process.env.RUNNER_TEMP;
-    const filePath = runnerTemp + `/buildSummary_${runId}.json`;
+    const filePath = join(runnerTemp, `buildSummary_${runId}.json`);
     const data = await readJsonFile(filePath);
-    addBuildSummaryTable(data);
+    const taskSummaryTableRows = getBuildSummaryTable(data);
+    writeSummary(taskSummaryTableRows);
   } catch (error) {
     console.error('An error occurred while reading the build summary file or adding the build summary table:', error);
   }