Skip to content

Commit 2706280

Browse files
authored
Merge pull request #19 from oslabs-beta/paython-mcp
✅ Deploy flow: wired pipeline_commit to send repoFullName + YAML from…
2 parents 0bb005e + a455b14 commit 2706280

File tree

7 files changed

+156
-36
lines changed

7 files changed

+156
-36
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ web_modules/
6969
.env
7070
.env.*
7171
!.env.example
72+
curl.txt
73+
7274

7375
# parcel-bundler cache (https://parceljs.org/)
7476
.cache

client/src/lib/api.ts

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { usePipelineStore } from "../store/usePipelineStore";
2+
13
export const BASE =
24
import.meta.env.VITE_API_BASE ?? "http://localhost:3000/api";
35

@@ -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
};

client/src/pages/ConfigurePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export default function ConfigurePage() {
122122

123123
<div>
124124
<div>YAML Preview</div>
125-
<pre style={{ maxHeight: 400, overflow: "auto", background: "#f6f6f6", padding: 12 }}>
125+
<pre style={{ maxHeight: 400, overflow: "auto", background: "#131212ff", padding: 12 }}>
126126
{pipeline.result?.yaml ?? pipeline.result?.generated_yaml ?? "Click Generate Pipeline to preview YAML…"}
127127
</pre>
128128
</div>

client/src/pages/DashboardPage.tsx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ import { useDeployStore } from "../store/useDeployStore";
77
export default function DashboardPage() {
88
const { repo } = useRepoStore();
99
const { result } = usePipelineStore();
10+
console.log("Debug: result.generated_yaml =", result?.generated_yaml);
1011
const cfg = useConfigStore();
1112

13+
console.log("Debug: repo =", repo);
14+
console.log("Debug: cfg.env =", cfg.env);
15+
console.log("Debug: result =", result);
16+
1217
// Select stable slices from the deploy store to avoid effect loops
1318
const running = useDeployStore((s) => s.running);
1419
const events = useDeployStore((s) => s.events);
@@ -34,23 +39,48 @@ export default function DashboardPage() {
3439
<div style={{ color: "#666", fontSize: 12 }}>
3540
{result?.pipeline_name} · Generated {result ? new Date(result.created_at).toLocaleString() : "—"}
3641
</div>
37-
<pre style={{ maxHeight: 280, overflow: "auto", background: "#f6f6f6", padding: 12 }}>
42+
<pre style={{ maxHeight: 280, overflow: "auto", background: "#1e1c1cff", padding: 12 }}>
3843
{result?.generated_yaml ?? "No pipeline generated yet."}
3944
</pre>
4045
</div>
4146

4247
<div>
4348
<button
4449
disabled={running}
45-
onClick={() => startDeploy({ repo: repo!, env: cfg.env })}
50+
onClick={() => {
51+
const repoFullName = result?.repo || repo;
52+
const yaml = result?.generated_yaml;
53+
const branch = result?.branch || "main";
54+
const environment = cfg.env || "dev";
55+
const provider = "aws";
56+
const path = `.github/workflows/${environment}-deploy.yml`;
57+
58+
console.log("Deploy button clicked with payload:", {
59+
repoFullName,
60+
branch,
61+
env: environment,
62+
yaml: yaml ? yaml.slice(0, 100) + "..." : "No YAML",
63+
provider,
64+
path,
65+
});
66+
67+
startDeploy({
68+
repoFullName,
69+
branch,
70+
env: environment,
71+
yaml,
72+
provider,
73+
path,
74+
});
75+
}}
4676
>
47-
{running ? "Deploying…" : "Deploy to AWS"}
77+
{running ? "Committing…" : "Commit to GitHub"}
4878
</button>
4979
{running && <button onClick={stop} style={{ marginLeft: 8 }}>Stop</button>}
5080
</div>
5181

5282
<div>
53-
<strong>Logs</strong>
83+
<strong>Commit Logs</strong>
5484
<div style={{ height: 280, overflow: "auto", background: "#111", color: "#ddd", padding: 12, fontFamily: "monospace", fontSize: 12 }}>
5585
{events.length === 0 ? "No logs yet." :
5686
events.map((e, i) => (

client/src/pages/DeployPage.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,29 @@ export default function DeployPage() {
1010
// loadRoles();
1111
}, []);
1212

13+
function startCommit() {
14+
// Placeholder function to start commit process
15+
console.log("Commit to GitHub started");
16+
}
17+
1318
return (
1419
<div className="p-6 max-w-2xl mx-auto space-y-4">
20+
<h2 className="text-lg font-semibold">Commit Workflow to GitHub</h2>
1521
{!repo || !branch ? (
1622
<p className="text-sm text-orange-700">Pick a repo/branch on Connect first.</p>
1723
) : (
18-
<p className="text-sm opacity-80">Deploying <strong>{repo}</strong> @ <strong>{branch}</strong></p>
24+
<>
25+
<p className="text-sm opacity-80">Committing workflow to <strong>GitHub</strong> for <strong>{repo}</strong> @ <strong>{branch}</strong></p>
26+
<button
27+
className="mt-2 px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700"
28+
onClick={startCommit}
29+
>
30+
Commit to GitHub
31+
</button>
32+
</>
1933
)}
2034

21-
{/* role picker + open PR button go here, wired to your deploy store */}
35+
{/* role picker + commit to GitHub button go here, wired to your deploy store */}
2236
</div>
2337
);
2438
}

client/src/store/useDeployStore.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,29 @@ type DeployActions = {
1919
export const useDeployStore = create<DeployState & DeployActions>()((set) => ({
2020
running: false,
2121
events: [],
22-
async startDeploy({ repo, env }) {
22+
async startDeploy(payload: {
23+
repoFullName: string;
24+
branch?: string;
25+
env: string;
26+
yaml?: string;
27+
provider?: string;
28+
path?: string;
29+
}) {
30+
const { repoFullName, branch = "main", env, yaml, provider = "aws", path = `.github/workflows/${env}-deploy.yml` } = payload || {};
2331
set({ running: true, events: [] });
24-
const { jobId } = await api.startDeploy({ repo, env });
25-
const stop = api.streamJob(jobId, (e) =>
26-
set((s) => ({ events: [...s.events, e] }))
27-
);
28-
set({ jobId, stopStream: stop });
32+
try {
33+
console.group("[useDeployStore.startDeploy] Prepared payload");
34+
console.log({ repoFullName, branch, env, provider, path, yamlLength: yaml ? yaml.length : 0 });
35+
console.groupEnd();
36+
const { jobId } = await api.startDeploy({ repoFullName, branch, env, yaml, provider, path });
37+
const stop = api.streamJob(jobId, (e) =>
38+
set((s) => ({ events: [...s.events, e] }))
39+
);
40+
set({ jobId, stopStream: stop });
41+
} catch (err) {
42+
console.error("[useDeployStore.startDeploy] Error:", err);
43+
set({ running: false });
44+
}
2945
},
3046
stop() {
3147
set((s) => {

client/src/store/usePipelineStore.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type PipelineState = {
1818

1919
// outputs from MCP
2020
result?: McpPipeline;
21+
repoFullName?: string;
2122

2223
// local UI state
2324
roles: { name: string; arn: string }[];
@@ -117,8 +118,16 @@ export const usePipelineStore = create<PipelineState & PipelineActions>()((set,
117118
res?.generated_yaml ||
118119
"";
119120

121+
const repoFullName =
122+
res?.data?.data?.repo ||
123+
res?.data?.repo ||
124+
"";
125+
126+
console.log("[usePipelineStore] Captured repoFullName:", repoFullName);
127+
120128
set({
121-
result: { ...res, yaml: generated_yaml },
129+
result: { ...res, yaml: generated_yaml, generated_yaml },
130+
repoFullName,
122131
status: "success",
123132
editing: false,
124133
editedYaml: undefined,

0 commit comments

Comments
 (0)