Skip to content

Commit 085c17c

Browse files
committed
feat: add build service override state
1 parent d0c0773 commit 085c17c

8 files changed

Lines changed: 1024 additions & 26 deletions

File tree

Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title>Build Service Overrides Reviewer Guide</title>
7+
<style>
8+
:root {
9+
--bg: #f7f8fa;
10+
--panel: #ffffff;
11+
--text: #18212f;
12+
--muted: #5d6878;
13+
--border: #d8dee8;
14+
--accent: #1769aa;
15+
--accent-soft: #e8f2fb;
16+
--code-bg: #111827;
17+
--code-text: #e5e7eb;
18+
}
19+
20+
* {
21+
box-sizing: border-box;
22+
}
23+
24+
body {
25+
margin: 0;
26+
background: var(--bg);
27+
color: var(--text);
28+
font-family:
29+
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
30+
line-height: 1.55;
31+
}
32+
33+
main {
34+
max-width: 1080px;
35+
margin: 0 auto;
36+
padding: 40px 24px 64px;
37+
}
38+
39+
h1,
40+
h2,
41+
h3 {
42+
margin: 0;
43+
line-height: 1.2;
44+
}
45+
46+
h1 {
47+
max-width: 860px;
48+
font-size: clamp(2rem, 4vw, 3.4rem);
49+
letter-spacing: 0;
50+
}
51+
52+
h2 {
53+
margin-top: 34px;
54+
font-size: 1.45rem;
55+
}
56+
57+
h3 {
58+
margin-top: 22px;
59+
font-size: 1rem;
60+
}
61+
62+
p {
63+
margin: 12px 0 0;
64+
}
65+
66+
code {
67+
border-radius: 4px;
68+
background: #eef1f5;
69+
padding: 0.12rem 0.28rem;
70+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
71+
font-size: 0.92em;
72+
}
73+
74+
pre {
75+
overflow-x: auto;
76+
border-radius: 8px;
77+
background: var(--code-bg);
78+
color: var(--code-text);
79+
padding: 18px;
80+
font-size: 0.9rem;
81+
}
82+
83+
pre code {
84+
background: transparent;
85+
color: inherit;
86+
padding: 0;
87+
}
88+
89+
table {
90+
width: 100%;
91+
margin-top: 16px;
92+
border-collapse: collapse;
93+
overflow: hidden;
94+
border: 1px solid var(--border);
95+
border-radius: 8px;
96+
background: var(--panel);
97+
}
98+
99+
th,
100+
td {
101+
padding: 12px 14px;
102+
border-bottom: 1px solid var(--border);
103+
text-align: left;
104+
vertical-align: top;
105+
}
106+
107+
th {
108+
background: #eef2f7;
109+
color: #344054;
110+
font-size: 0.82rem;
111+
text-transform: uppercase;
112+
}
113+
114+
tr:last-child td {
115+
border-bottom: 0;
116+
}
117+
118+
ul,
119+
ol {
120+
margin: 12px 0 0;
121+
padding-left: 24px;
122+
}
123+
124+
li + li {
125+
margin-top: 8px;
126+
}
127+
128+
.lede {
129+
max-width: 860px;
130+
color: var(--muted);
131+
font-size: 1.08rem;
132+
}
133+
134+
.panel {
135+
margin-top: 18px;
136+
padding: 18px;
137+
border: 1px solid var(--border);
138+
border-radius: 8px;
139+
background: var(--panel);
140+
}
141+
142+
.decision {
143+
border-left: 4px solid var(--accent);
144+
}
145+
146+
.badge {
147+
display: inline-block;
148+
margin-bottom: 14px;
149+
border-radius: 999px;
150+
background: var(--accent-soft);
151+
color: var(--accent);
152+
padding: 4px 10px;
153+
font-size: 0.78rem;
154+
font-weight: 700;
155+
text-transform: uppercase;
156+
}
157+
158+
@media (max-width: 760px) {
159+
main {
160+
padding: 28px 16px 48px;
161+
}
162+
163+
table {
164+
display: block;
165+
overflow-x: auto;
166+
white-space: nowrap;
167+
}
168+
}
169+
</style>
170+
</head>
171+
<body>
172+
<main>
173+
<header>
174+
<span class="badge">Reviewer guide</span>
175+
<h1>Build service override state in the build response</h1>
176+
<p class="lede">
177+
This PR lets the UI build the service override form from the existing
178+
<code>GET /api/v2/builds/{uuid}</code> response by annotating each returned deploy with
179+
<code>serviceOverride</code>. The separate services GET endpoint is removed.
180+
</p>
181+
</header>
182+
183+
<section class="panel decision">
184+
<h2>Decision</h2>
185+
<p>
186+
Keep <code>deploys[]</code> as the source list and add a nullable nested
187+
<code>deploy.serviceOverride</code> object. This gives the UI one build-detail request while keeping computed
188+
service override semantics separate from raw deploy fields.
189+
</p>
190+
</section>
191+
192+
<section>
193+
<h2>Response shape</h2>
194+
<pre><code>{
195+
"data": {
196+
"uuid": "white-poetry-596195",
197+
"deploys": [
198+
{
199+
"uuid": "api-white-poetry-596195",
200+
"status": "Deployed",
201+
"statusMessage": null,
202+
"active": true,
203+
"branchName": "feature/api",
204+
"publicUrl": "https://api.example.com",
205+
"updatedAt": "2026-05-08T12:00:00.000Z",
206+
"deployable": {
207+
"name": "api",
208+
"type": "github"
209+
},
210+
"serviceOverride": {
211+
"name": "api",
212+
"branchOrExternalUrl": "feature/api",
213+
"group": "default",
214+
"editable": true
215+
}
216+
},
217+
{
218+
"uuid": "internal-api-white-poetry-596195",
219+
"status": "Pending",
220+
"active": true,
221+
"deployable": {
222+
"name": "internal-api",
223+
"type": "github"
224+
},
225+
"serviceOverride": null
226+
}
227+
]
228+
}
229+
}</code></pre>
230+
</section>
231+
232+
<section>
233+
<h2>Why nested instead of top-level?</h2>
234+
<p>
235+
The UI team can now build the service override screen directly from <code>data.deploys</code>. Rows with
236+
<code>serviceOverride === null</code> are still real deploys, but they are not rows the service override form
237+
should render as editable choices.
238+
</p>
239+
<ul>
240+
<li>The build detail endpoint remains the single read path for this screen.</li>
241+
<li>Raw deploy state stays on the deploy object: <code>active</code>, <code>status</code>, errors, timestamps, URLs.</li>
242+
<li>Computed edit-form state stays under <code>serviceOverride</code>: <code>name</code>, <code>branchOrExternalUrl</code>, <code>group</code>, and <code>editable</code>.</li>
243+
<li>The UI does not need to duplicate grouping, display-value, or editability rules.</li>
244+
<li>The PATCH endpoint can continue accepting the compact <code>serviceOverrides[]</code> form payload.</li>
245+
</ul>
246+
</section>
247+
248+
<section>
249+
<h2>Why not flatten onto deploy?</h2>
250+
<p>
251+
Fields like <code>branchOrExternalUrl</code>, <code>group</code>, and <code>editable</code> are not native
252+
deploy fields. They are service override edit semantics derived from deploy type, environment grouping, and PR
253+
comment behavior. Nesting keeps that boundary clear.
254+
</p>
255+
</section>
256+
257+
<section>
258+
<h2>Backend rules kept server-side</h2>
259+
<table>
260+
<thead>
261+
<tr>
262+
<th>Rule</th>
263+
<th>Why it stays in the API</th>
264+
</tr>
265+
</thead>
266+
<tbody>
267+
<tr>
268+
<td>Default vs optional grouping</td>
269+
<td>Full-yaml builds group from deployable active state; classic builds group from environment service relations.</td>
270+
</tr>
271+
<tr>
272+
<td>Display value</td>
273+
<td>GitHub, Helm, External HTTP, Docker, Codefresh, and Configuration services use different display rules.</td>
274+
</tr>
275+
<tr>
276+
<td>Editability</td>
277+
<td>Only GitHub, Helm, and External HTTP expose an editable branch or URL text field.</td>
278+
</tr>
279+
<tr>
280+
<td>Internal dependencies</td>
281+
<td>Internal dependency deploys stay in <code>deploys[]</code>, but receive <code>serviceOverride: null</code>.</td>
282+
</tr>
283+
<tr>
284+
<td>Whole-form PATCH validation</td>
285+
<td>The same computed display value is used to allow unchanged display-only rows and reject changed ones.</td>
286+
</tr>
287+
</tbody>
288+
</table>
289+
</section>
290+
291+
<section>
292+
<h2>PATCH remains targeted</h2>
293+
<p>
294+
Service updates still go through <code>PATCH /api/v2/builds/{uuid}/services</code>. The read shape is
295+
deploy-centric, but the write shape remains a concise list of service changes.
296+
</p>
297+
<pre><code>{
298+
"serviceOverrides": [
299+
{
300+
"name": "api",
301+
"active": false,
302+
"branchOrExternalUrl": "feature/api"
303+
}
304+
]
305+
}</code></pre>
306+
</section>
307+
308+
<section>
309+
<h2>Suggested review path</h2>
310+
<ol>
311+
<li>Review <code>src/server/services/build.ts</code> for how service override state is attached to deploys.</li>
312+
<li>Review <code>src/server/services/override.ts</code> for grouping, display values, and editability rules.</li>
313+
<li>Review <code>src/app/api/v2/builds/[uuid]/services/route.ts</code> to confirm the redundant GET is gone and PATCH still works.</li>
314+
<li>Review <code>src/shared/openApiSpec.ts</code> for the new nullable <code>deploy.serviceOverride</code> schema.</li>
315+
<li>Review tests for build response annotation and PATCH validation behavior.</li>
316+
</ol>
317+
</section>
318+
</main>
319+
</body>
320+
</html>

‎src/app/api/v2/builds/[uuid]/services/route.ts‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { NextRequest } from 'next/server';
1919
import { createApiHandler } from 'server/lib/createApiHandler';
2020
import { errorResponse, successResponse } from 'server/lib/response';
2121
import OverrideService, {
22+
ServiceOverrideNotEditableError,
2223
ServiceOverrideNotFoundError,
2324
type ServiceOverridePatchInput,
2425
} from 'server/services/override';
@@ -40,12 +41,12 @@ function validateServiceOverride(value: unknown, index: number): ServiceOverride
4041
return new Error(`serviceOverrides[${index}] must be an object`);
4142
}
4243

43-
const serviceName = value.serviceName;
44+
const name = value.name;
4445
const hasActive = hasOwn(value, 'active');
4546
const hasBranchOrExternalUrl = hasOwn(value, 'branchOrExternalUrl');
4647

47-
if (typeof serviceName !== 'string' || serviceName.length === 0) {
48-
return new Error(`serviceOverrides[${index}].serviceName must be a non-empty string`);
48+
if (typeof name !== 'string' || name.length === 0) {
49+
return new Error(`serviceOverrides[${index}].name must be a non-empty string`);
4950
}
5051

5152
if (!hasActive && !hasBranchOrExternalUrl) {
@@ -61,7 +62,7 @@ function validateServiceOverride(value: unknown, index: number): ServiceOverride
6162
}
6263

6364
return {
64-
serviceName,
65+
name,
6566
...(hasActive ? { active: value.active as boolean } : {}),
6667
...(hasBranchOrExternalUrl ? { branchOrExternalUrl: value.branchOrExternalUrl as string } : {}),
6768
};
@@ -95,7 +96,7 @@ function validateServiceOverride(value: unknown, index: number): ServiceOverride
9596
* content:
9697
* application/json:
9798
* schema:
98-
* $ref: '#/components/schemas/BuildOverrideUpdateSuccessResponse'
99+
* $ref: '#/components/schemas/UpdateBuildServiceOverridesSuccessResponse'
99100
* '400':
100101
* description: Invalid request body.
101102
* content:
@@ -136,7 +137,7 @@ const patchHandler = async (req: NextRequest, { params }: { params: { uuid: stri
136137
const override = new OverrideService();
137138
const build = await override.db.models.Build.query()
138139
.findOne({ uuid: params.uuid })
139-
.withGraphFetched('[pullRequest, deploys.[service, deployable]]');
140+
.withGraphFetched('[pullRequest, environment.[defaultServices, optionalServices], deploys.[service, deployable]]');
140141

141142
if (!build) {
142143
return errorResponse(new Error(`Build with UUID ${params.uuid} not found`), { status: 404 }, req);
@@ -150,13 +151,26 @@ const patchHandler = async (req: NextRequest, { params }: { params: { uuid: stri
150151
serviceOverrides,
151152
runUuid: nanoid(),
152153
});
154+
const updatedBuild = await override.db.models.Build.query()
155+
.findOne({ uuid: params.uuid })
156+
.withGraphFetched('[environment.[defaultServices, optionalServices], deploys.[service, deployable]]');
153157

154-
return successResponse(result, { status: 200 }, req);
158+
if (!updatedBuild) {
159+
return errorResponse(new Error(`Build with UUID ${params.uuid} not found`), { status: 404 }, req);
160+
}
161+
162+
const updatedServiceOverrides = await override.getServiceOverrideStates(updatedBuild, updatedBuild.deploys || []);
163+
164+
return successResponse({ serviceOverrides: updatedServiceOverrides, queued: result.queued }, { status: 200 }, req);
155165
} catch (error) {
156166
if (error instanceof ServiceOverrideNotFoundError) {
157167
return errorResponse(error, { status: 404 }, req);
158168
}
159169

170+
if (error instanceof ServiceOverrideNotEditableError) {
171+
return errorResponse(error, { status: 400 }, req);
172+
}
173+
160174
throw error;
161175
}
162176
};

0 commit comments

Comments
 (0)