@@ -46,7 +46,7 @@ export const latestCommitTool: ToolConfig<LatestCommitParams, LatestCommitRespon
4646 } ) ,
4747 } ,
4848
49- transformResponse : async ( response ) => {
49+ transformResponse : async ( response , params ) => {
5050 if ( ! response . ok ) {
5151 throw new Error ( `GitHub API error: ${ response . statusText } ` )
5252 }
@@ -56,6 +56,48 @@ export const latestCommitTool: ToolConfig<LatestCommitParams, LatestCommitRespon
5656 // Create a human-readable content string
5757 const content = `Latest commit: "${ data . commit . message } " by ${ data . commit . author . name } on ${ data . commit . author . date } . SHA: ${ data . sha } `
5858
59+ // Initialize files array and add file information
60+ const files = data . files || [ ]
61+ const fileDetailsWithContent = [ ]
62+
63+ // Fetch raw content for each file if includeFileContent is true
64+ if ( files . length > 0 ) {
65+ for ( const file of files ) {
66+ const fileDetail = {
67+ filename : file . filename ,
68+ additions : file . additions ,
69+ deletions : file . deletions ,
70+ changes : file . changes ,
71+ status : file . status ,
72+ raw_url : file . raw_url ,
73+ blob_url : file . blob_url ,
74+ patch : file . patch ,
75+ content : undefined as string | undefined ,
76+ }
77+
78+ // Only try to fetch content for files that are not too large and not deleted
79+ if ( file . status !== 'removed' && file . raw_url ) {
80+ try {
81+ // Fetch the raw file content
82+ const contentResponse = await fetch ( file . raw_url , {
83+ headers : {
84+ Authorization : `Bearer ${ params ?. apiKey } ` ,
85+ 'X-GitHub-Api-Version' : '2022-11-28' ,
86+ } ,
87+ } )
88+
89+ if ( contentResponse . ok ) {
90+ fileDetail . content = await contentResponse . text ( )
91+ }
92+ } catch ( error ) {
93+ console . error ( `Failed to fetch content for ${ file . filename } :` , error )
94+ }
95+ }
96+
97+ fileDetailsWithContent . push ( fileDetail )
98+ }
99+ }
100+
59101 return {
60102 success : true ,
61103 output : {
@@ -81,6 +123,7 @@ export const latestCommitTool: ToolConfig<LatestCommitParams, LatestCommitRespon
81123 deletions : data . stats . deletions ,
82124 total : data . stats . total ,
83125 } : undefined ,
126+ files : fileDetailsWithContent . length > 0 ? fileDetailsWithContent : undefined ,
84127 } ,
85128 } ,
86129 }
0 commit comments