Skip to content

Commit c45bcf5

Browse files
committed
fix(deploy): integrate PR #855 with consistent branch rescans and saves
2 parents b2cd784 + 409e669 commit c45bcf5

12 files changed

Lines changed: 697 additions & 45 deletions

File tree

‎apps/api/test/modules/github/github-sdk-parity.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ describe("GitHub operations shared by SDK and HTTP", () => {
8484
for (const call of provider.cloneToken.mock.calls) expect(call.slice(1)).toEqual(["acme", undefined, { repositories: ["app"] }]);
8585
});
8686

87+
it("saves a scanned branch and build settings together through native and HTTP project operations", async () => {
88+
const owner = await seedOwner();
89+
const c = await clients(owner);
90+
const group = await repos.projectGroup.create({ organizationId: owner.orgId, name: "Scan", slug: `scan-${owner.userId}` });
91+
const project = await repos.project.create({ organizationId: owner.orgId, groupId: group.id, name: "Scan", slug: `scan-${owner.userId}`, gitOwner: "acme", gitRepo: "app", gitProvider: "github", gitBranch: "main", composePath: "old/compose.yml" });
92+
for (const client of [c.native, c.remote]) {
93+
await client.projects.setOptions(project.id, { gitBranch: "plain", framework: "node", buildCommand: "npm run build", composePath: null });
94+
expect(await repos.project.findById(project.id)).toMatchObject({ gitBranch: "plain", framework: "node", buildCommand: "npm run build", composePath: null });
95+
await expect(client.projects.setOptions(project.id, { gitBranch: " ", buildCommand: "invalid update" })).rejects.toMatchObject({ statusCode: 400 });
96+
expect((await repos.project.findById(project.id))?.buildCommand).toBe("npm run build");
97+
}
98+
});
99+
87100
it("filters repository counts and directory entries before returning them to a restricted principal", async () => {
88101
const owner = await seedOwner(), member = await memberOf(owner), c = await clients(member, owner.orgId);
89102
provider.source.mockResolvedValue({ listReposForOwner: async () => [mapped("app"), mapped("hidden")] });

‎apps/dashboard/src/app/(dashboard)/(deployment)/deploy/[slug]/components/Sidebar.tsx‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ const ComposeChecklist: React.FC = () => {
153153
// ─── Sidebar ─────────────────────────────────────────────────────────────────
154154

155155
const Sidebar: React.FC = () => {
156-
const { config, state, updateConfig, startDeployment } = useDeployment();
156+
const { config, state, updateConfig, startDeployment, rescanWithBranch, isRescanning } =
157+
useDeployment();
157158
const { t } = useI18n();
158159
const { requireCloud } = useCloud();
159160
const { baseDomain, selfHosted, deployMode } = usePlatform();
@@ -163,6 +164,15 @@ const Sidebar: React.FC = () => {
163164
const { showToast } = useToast();
164165
const router = useRouter();
165166
const isServices = usesServiceDeployment(config);
167+
const [branchError, setBranchError] = React.useState<string | null>(null);
168+
const handleBranchChange = useCallback(
169+
async (branch: string) => {
170+
setBranchError(null);
171+
const result = await rescanWithBranch(branch);
172+
if (!result.success && result.error) setBranchError(result.error);
173+
},
174+
[rescanWithBranch],
175+
);
166176

167177
// Copy a ready-to-run `git clone` command with a short-lived GitHub App
168178
// installation token. Cloud / GitHub-App mode only — surfaces a clear
@@ -457,7 +467,8 @@ const Sidebar: React.FC = () => {
457467
repo={config.repo}
458468
projectId={config.projectId}
459469
value={config.branch}
460-
onChange={(val) => updateConfig({ branch: val })}
470+
onChange={(val) => void handleBranchChange(val)}
471+
disabled={isRescanning || isSaving || state.isDeploying}
461472
initialBranches={config.branches}
462473
initialPage={config.branchPage}
463474
initialHasMore={config.branchesHasMore}
@@ -469,6 +480,20 @@ const Sidebar: React.FC = () => {
469480
}
470481
: undefined}
471482
/>
483+
{isRescanning && (
484+
<p
485+
role="status"
486+
className="flex items-center gap-2 mt-2 text-sm text-muted-foreground"
487+
>
488+
<Loader2 className="size-3.5 animate-spin" aria-hidden="true" />
489+
{t.importProject.buildSettings.composePath.scanning}
490+
</p>
491+
)}
492+
{branchError && (
493+
<p role="alert" className="mt-2 text-sm text-danger break-words">
494+
{branchError}
495+
</p>
496+
)}
472497
</div>
473498
)}
474499
{config.branches.length === 0 && config.branch && (
@@ -518,7 +543,7 @@ const Sidebar: React.FC = () => {
518543
{isConfigMode ? (
519544
<button
520545
onClick={handleSave}
521-
disabled={isSaving}
546+
disabled={isSaving || isRescanning}
522547
className="w-full inline-flex items-center justify-center gap-2 px-5 py-3 bg-primary text-primary-foreground text-sm font-medium rounded-xl hover:bg-primary/90 transition-all hover:shadow-lg hover:shadow-primary/25 hover:-translate-y-0.5 disabled:opacity-50 disabled:cursor-not-allowed"
523548
>
524549
{isSaving ? (
@@ -536,7 +561,7 @@ const Sidebar: React.FC = () => {
536561
) : (
537562
<button
538563
onClick={handleDeploy}
539-
disabled={state.isDeploying}
564+
disabled={state.isDeploying || isRescanning}
540565
className="w-full inline-flex items-center justify-center gap-2 px-5 py-3 bg-primary text-primary-foreground text-sm font-medium rounded-xl hover:bg-primary/90 transition-all hover:shadow-lg hover:shadow-primary/25 hover:-translate-y-0.5 disabled:opacity-50 disabled:cursor-not-allowed"
541566
>
542567
{state.isDeploying ? (

‎apps/dashboard/src/components/import-project/ComposePathField.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const ComposePathField: React.FC = () => {
5454
const subtitle = saved || (composeActive ? cp.subtitle : cp.subtitleOptIn);
5555

5656
const apply = async () => {
57-
if (pending || !isDirty) return;
57+
if (pending || deployment?.isRescanning || !isDirty) return;
5858
setPending(true);
5959
setError(null);
6060
const result = await rescan(trimmed);
@@ -125,14 +125,14 @@ export const ComposePathField: React.FC = () => {
125125
void apply();
126126
}
127127
}}
128-
disabled={pending}
128+
disabled={pending || deployment?.isRescanning}
129129
placeholder="deploy/docker-compose/docker-compose.yml"
130130
className="flex-1 min-w-0 px-3.5 py-2.5 border border-border/50 rounded-lg text-sm text-foreground bg-muted/30 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:opacity-60"
131131
/>
132132
<button
133133
type="button"
134134
onClick={() => void apply()}
135-
disabled={pending || !isDirty}
135+
disabled={pending || deployment?.isRescanning || !isDirty}
136136
className="shrink-0 flex items-center gap-1.5 px-3 py-2.5 rounded-lg text-xs font-medium border border-border/50 text-foreground hover:bg-muted/50 disabled:opacity-40 disabled:hover:bg-transparent transition-colors"
137137
>
138138
{pending ? (

‎apps/dashboard/src/components/import-project/ProjectSettings.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ const ProjectSettings: React.FC = () => {
1818
const detectedFw = config.detectedFramework ? getFrameworkConfig(config.detectedFramework) : null;
1919

2020
const currentFwConfig = getFrameworkConfig(config.framework);
21-
const [activeTab, setActiveTab] = useState<StackCategory>(currentFwConfig.category);
21+
const [activeTab, setActiveTab] = useState<StackCategory>(
22+
stackCategories.some((category) => category.id === currentFwConfig.category)
23+
? currentFwConfig.category
24+
: stackCategories[0].id,
25+
);
2226

2327
const filteredFrameworks = useMemo(
2428
() => frameworks.filter((fw) => fw.category === activeTab),
@@ -113,7 +117,7 @@ const ProjectSettings: React.FC = () => {
113117
</div>
114118

115119
{/* Category tabs */}
116-
<div className="flex gap-1 p-1 bg-muted/50 rounded-lg mb-4 w-fit">
120+
<div className="flex flex-wrap gap-1 p-1 bg-muted/50 rounded-lg mb-4 w-fit max-w-full">
117121
{stackCategories.map((cat) => (
118122
<button
119123
key={cat.id}

‎apps/dashboard/src/context/DeploymentContext.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const useOptionalDeployment = () => useContext(DeploymentContext);
2020
export const DeploymentProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
2121
const {
2222
config,
23+
isRescanning,
2324
setConfig,
2425
updateConfig,
2526
updateOptions,
@@ -28,6 +29,7 @@ export const DeploymentProvider: React.FC<{ children: React.ReactNode }> = ({ ch
2829
initializeFromUpload,
2930
initializeFromProject,
3031
rescanWithComposePath,
32+
rescanWithBranch,
3133
} = useDeploymentConfig();
3234

3335
const {
@@ -50,6 +52,7 @@ export const DeploymentProvider: React.FC<{ children: React.ReactNode }> = ({ ch
5052

5153
const value: DeploymentContextType = {
5254
config,
55+
isRescanning,
5356
state,
5457
terminalRef,
5558
canStreamContainer,
@@ -60,6 +63,7 @@ export const DeploymentProvider: React.FC<{ children: React.ReactNode }> = ({ ch
6063
initializeFromUpload,
6164
initializeFromProject,
6265
rescanWithComposePath,
66+
rescanWithBranch,
6367
startDeployment,
6468
connectToBuild,
6569
loadBuildSession,

0 commit comments

Comments
 (0)