({
project,
getVcsForWorkspace,
sessionId,
organizationId,
}: {
project: Project;
getVcsForWorkspace: (workspaceId: string) => SyncVCSLike;
sessionId: string;
organizationId: string;
})
| 168 | } |
| 169 | |
| 170 | export async function updateLocalProjectToRemote({ |
| 171 | project, |
| 172 | getVcsForWorkspace, |
| 173 | sessionId, |
| 174 | organizationId, |
| 175 | }: { |
| 176 | project: Project; |
| 177 | getVcsForWorkspace: (workspaceId: string) => SyncVCSLike; |
| 178 | sessionId: string; |
| 179 | organizationId: string; |
| 180 | }) { |
| 181 | try { |
| 182 | const newCloudProject = await createTeamProject({ |
| 183 | sessionId, |
| 184 | organizationId, |
| 185 | name: project.name, |
| 186 | }); |
| 187 | const updatedProject = await services.project.update(project, { |
| 188 | name: newCloudProject.name, |
| 189 | remoteId: newCloudProject.id, |
| 190 | }); |
| 191 | |
| 192 | // For each workspace in the local project |
| 193 | const projectWorkspaces = await services.workspace.listByParentId(updatedProject._id); |
| 194 | |
| 195 | for (const workspace of projectWorkspaces) { |
| 196 | const workspaceMeta = await services.workspaceMeta.getOrCreateByParentId(workspace._id); |
| 197 | |
| 198 | // Initialize Sync on the workspace if it's not using Git sync |
| 199 | try { |
| 200 | if (!workspaceMeta.gitRepositoryId) { |
| 201 | const vcs = getVcsForWorkspace(workspace._id); |
| 202 | invariant(vcs, 'VCS must be initialized'); |
| 203 | |
| 204 | await initializeLocalBackendProjectAndMarkForSync({ vcs, workspace }); |
| 205 | await pushSnapshotOnInitialize({ vcs, workspace, project: updatedProject }); |
| 206 | } |
| 207 | } catch (e) { |
| 208 | console.warn( |
| 209 | 'Failed to initialize sync on workspace. This will be retried when the workspace is opened on the app.', |
| 210 | e, |
| 211 | ); |
| 212 | // TODO: here we should show the try again dialog |
| 213 | } |
| 214 | } |
| 215 | } catch (error: unknown) { |
| 216 | if (isApiError(error)) { |
| 217 | let errorMessage = 'An unexpected error occurred while connecting the project. Please try again.'; |
| 218 | if (error.name === 'FORBIDDEN' || error.name === 'NEEDS_TO_UPGRADE') { |
| 219 | errorMessage = error.message; |
| 220 | } |
| 221 | return { |
| 222 | error: errorMessage, |
| 223 | }; |
| 224 | } |
| 225 | return { |
| 226 | error: error instanceof Error ? error.message : String(error), |
| 227 | }; |
no test coverage detected