11#!/usr/bin/env tsx
22import axios from 'axios'
33import { parse } from 'csv-parse'
4- import { stringify } from 'csv-stringify'
54import fs from 'fs'
65import path from 'path'
76
@@ -25,7 +24,12 @@ async function onboardProjectsFromCsv(
2524 csvFilePath : string ,
2625 bearerToken : string ,
2726 isDryRun = false ,
28- ) : Promise < { successCount : number ; failureCount : number ; errors : string [ ] } > {
27+ ) : Promise < {
28+ successCount : number
29+ failureCount : number
30+ errors : string [ ]
31+ failedProjects : FailedProjectRow [ ]
32+ } > {
2933 log . info ( `Starting project onboarding from CSV: ${ csvFilePath } ` )
3034
3135 const projects : ProjectRow [ ] = [ ]
@@ -80,7 +84,7 @@ async function onboardProjectsFromCsv(
8084 const errorMsg = `Failed to read or parse CSV file: ${ error . message } `
8185 log . error ( error , errorMsg )
8286 errors . push ( errorMsg )
83- return { successCount : 0 , failureCount : 0 , errors }
87+ return { successCount : 0 , failureCount : 0 , errors, failedProjects : [ ] }
8488 }
8589
8690 // Process each project
@@ -121,17 +125,11 @@ async function onboardProjectsFromCsv(
121125 }
122126 }
123127
124- // Write failed projects to CSV if any
125- if ( failedProjects . length > 0 ) {
126- const failedCsvPath = csvFilePath . replace ( '.csv' , '_failed.csv' )
127- await writeFailedProjectsCsv ( failedProjects , failedCsvPath )
128- log . info ( `Written ${ failedProjects . length } failed projects to ${ failedCsvPath } ` )
129- }
130-
131128 const result = {
132129 successCount,
133130 failureCount : failedProjects . length ,
134131 errors,
132+ failedProjects,
135133 }
136134
137135 log . info ( `Onboarding completed: ${ successCount } successful, ${ failedProjects . length } failed` )
@@ -255,31 +253,6 @@ function parseGithubUrl(repoUrl: string): { owner: string; repo: string } {
255253 }
256254}
257255
258- async function writeFailedProjectsCsv (
259- failedProjects : FailedProjectRow [ ] ,
260- filePath : string ,
261- ) : Promise < void > {
262- return new Promise ( ( resolve , reject ) => {
263- const columns = [ 'name' , 'slug' , 'repoUrl' , 'reason' ]
264-
265- stringify (
266- failedProjects ,
267- {
268- header : true ,
269- columns,
270- } ,
271- ( err : any , output : any ) => {
272- if ( err ) {
273- reject ( err )
274- } else {
275- fs . writeFileSync ( filePath , output )
276- resolve ( )
277- }
278- } ,
279- )
280- } )
281- }
282-
283256async function main ( ) {
284257 const args = process . argv . slice ( 2 )
285258
@@ -340,10 +313,12 @@ async function main() {
340313 } )
341314 }
342315
343- if ( result . failureCount > 0 ) {
344- console . log (
345- `\n📄 Failed projects have been written to: ${ resolvedPath . replace ( '.csv' , '_failed.csv' ) } ` ,
346- )
316+ if ( result . failedProjects . length > 0 ) {
317+ console . log ( '\n=== Failed Projects ===' )
318+ result . failedProjects . forEach ( ( project , index ) => {
319+ console . log ( `${ index + 1 } . ${ project . name } (${ project . slug } ) - ${ project . reason } ` )
320+ console . log ( ` Repo: ${ project . repoUrl } ` )
321+ } )
347322 }
348323
349324 console . log ( '\n=== Summary ===' )
0 commit comments