1+ import { usePipelineStore } from "../store/usePipelineStore" ;
2+
13export const BASE =
2- import . meta. env . VITE_API_BASE ?? "http://localhost:3333 /api" ;
4+ import . meta. env . VITE_API_BASE ?? "http://localhost:3000 /api" ;
35
46// Derive the server base without any trailing "/api" for MCP calls
57const SERVER_BASE = BASE . replace ( / \/ a p i $ / , "" ) ;
@@ -37,7 +39,7 @@ export const api = {
3739 const data = await mcp < {
3840 repositories : { name : string ; full_name : string ; branches ?: string [ ] } [ ] ;
3941 } > ( "repo_reader" , { } ) ;
40- const repos = ( data ?. repositories ?? [ ] ) . map ( ( r ) => r . full_name ) ;
42+ const repos = ( data ?. data ?. repositories ?? [ ] ) . map ( ( r ) => r . full_name ) ;
4143 return { repos } ;
4244 } ,
4345
@@ -46,7 +48,7 @@ export const api = {
4648 const data = await mcp < {
4749 repositories : { name : string ; full_name : string ; branches ?: string [ ] } [ ] ;
4850 } > ( "repo_reader" , { } ) ;
49- const item = ( data ?. repositories ?? [ ] ) . find ( ( r ) => r . full_name === repo ) ;
51+ const item = ( data ?. data ?. repositories ?? [ ] ) . find ( ( r ) => r . full_name === repo ) ;
5052 return { branches : item ?. branches ?? [ ] } ;
5153 } ,
5254
@@ -139,35 +141,82 @@ export const api = {
139141 return { results } ;
140142 } ,
141143
142- // --- Mock deploy APIs for Dashboard ---
143- async startDeploy ( { repo, env } : { repo : string ; env : string } ) {
144- const jobId = `job_${ Math . random ( ) . toString ( 36 ) . slice ( 2 ) } ` ;
145- // Stash minimal job info in memory for the stream to reference
146- JOBS . set ( jobId , { repo, env, startedAt : Date . now ( ) } ) ;
147- return { jobId } as const ;
148- } ,
144+ // --- Deploy APIs for Dashboard ---
145+ async startDeploy ( {
146+ repoFullName : fromCallerRepo ,
147+ branch,
148+ env,
149+ yaml : fromCallerYaml ,
150+ provider,
151+ path,
152+ } : {
153+ repoFullName ?: string ;
154+ branch ?: string ;
155+ env ?: string ;
156+ yaml ?: string ;
157+ provider ?: string ;
158+ path ?: string ;
159+ } ) {
160+ const pipelineStore = usePipelineStore . getState ( ) ;
161+ const repoFullName = fromCallerRepo || pipelineStore ?. repoFullName || pipelineStore ?. result ?. repo ;
162+ const selectedBranch = branch || pipelineStore ?. selectedBranch || "main" ;
163+ const yaml = pipelineStore ?. result ?. generated_yaml ;
164+ const environment = env || pipelineStore ?. environment || "dev" ;
165+
166+ const providerFinal = provider || pipelineStore ?. provider || "aws" ;
167+ const pathFinal = path || `.github/workflows/${ environment } -deploy.yml` ;
168+
169+ console . group ( "[Deploy Debug]" ) ;
170+ console . log ( "repoFullName:" , repoFullName ) ;
171+ console . log ( "selectedBranch:" , selectedBranch ) ;
172+ console . log ( "environment:" , environment ) ;
173+ console . log ( "provider:" , providerFinal ) ;
174+ console . log ( "path:" , pathFinal ) ;
175+ console . log ( "YAML length:" , yaml ? yaml . length : 0 ) ;
176+ console . groupEnd ( ) ;
177+
178+ const payload = {
179+ repoFullName,
180+ branch : selectedBranch ,
181+ env : environment ,
182+ yaml,
183+ provider : providerFinal ,
184+ path : pathFinal ,
185+ } ;
186+
187+ console . log ( "[Deploy] Final payload:" , payload ) ;
188+
189+ const res = await fetch ( `${ SERVER_BASE } /mcp/v1/pipeline_commit` , {
190+ method : "POST" ,
191+ headers : { "Content-Type" : "application/json" } ,
192+ credentials : "include" ,
193+ body : JSON . stringify ( payload ) ,
194+ } ) ;
195+
196+ const data = await res . json ( ) . catch ( ( ) => ( { } ) ) ;
197+
198+ console . group ( "[Deploy Response]" ) ;
199+ console . log ( "Status:" , res . status ) ;
200+ console . log ( "Data:" , data ) ;
201+ console . groupEnd ( ) ;
202+
203+ if ( ! res . ok ) throw new Error ( `Pipeline commit failed: ${ res . statusText } ` ) ;
204+ return data ;
205+ } ,
149206
150- streamJob (
151- jobId : string ,
152- onEvent : ( e : { ts : string ; level : "info" | "warn" | "error" ; msg : string } ) => void
153- ) {
154- const meta = JOBS . get ( jobId ) || { repo : "?" , env : "dev" } ;
207+ streamJob ( _jobId : string , onEvent : ( e : { ts : string ; level : "info" ; msg : string } ) => void ) {
155208 const steps = [
156- `Authenticating to AWS (${ meta . env } )` ,
157- `Assuming role` ,
158- `Validating permissions` ,
159- `Building artifacts` ,
160- `Deploying ${ meta . repo } ` ,
161- `Verifying rollout` ,
162- `Done`
209+ "Connecting to GitHub..." ,
210+ "Committing workflow file..." ,
211+ "Verifying commit..." ,
212+ "Done ✅"
163213 ] ;
164214 let i = 0 ;
165215 const timer = setInterval ( ( ) => {
166216 if ( i >= steps . length ) return ;
167- const level = i === steps . length - 1 ? "info" : "info" ;
168- onEvent ( { ts : new Date ( ) . toISOString ( ) , level, msg : steps [ i ++ ] } ) ;
217+ onEvent ( { ts : new Date ( ) . toISOString ( ) , level : "info" , msg : steps [ i ++ ] } ) ;
169218 if ( i >= steps . length ) clearInterval ( timer ) ;
170- } , 800 ) ;
219+ } , 600 ) ;
171220 return ( ) => clearInterval ( timer ) ;
172221 } ,
173222
0 commit comments