Skip to content

Commit

Permalink
fix: #6304 git clone collections
Browse files Browse the repository at this point in the history
  • Loading branch information
filfreire committed Aug 18, 2023
1 parent bec4e82 commit ce6ec8c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
13 changes: 0 additions & 13 deletions packages/insomnia/src/sync/git/force-workspace-scope-to-design.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/insomnia/src/sync/git/ne-db-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as models from '../../models';
import { BaseModel } from '../../models';
import { isWorkspace } from '../../models/workspace';
import { resetKeys } from '../ignore-keys';
import { forceWorkspaceScopeToDesign } from './force-workspace-scope-to-design';
import { GIT_INSOMNIA_DIR_NAME } from './git-vcs';
import parseGitPath from './parse-git-path';
import Stat from './stat';
Expand Down Expand Up @@ -106,8 +105,6 @@ export class NeDBClient {
doc.parentId = this._projectId;
}

forceWorkspaceScopeToDesign(doc);

await db.upsert(doc, true);
}

Expand Down
34 changes: 31 additions & 3 deletions packages/insomnia/src/ui/routes/git-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,15 +476,32 @@ export const cloneGitRepoAction: ActionFunction = async ({
return rootDirs.includes(models.workspace.type);
};

// get workspace scope from workspace dir
const getWorkspaceScopeFromWorkspaceDir = async (
fsClient: Record<string, any>
): Promise<'design' | 'collection'> => {
const workspaceBase = path.join(GIT_INSOMNIA_DIR, models.workspace.type);
const workspaces = await fsClient.promises.readdir(workspaceBase);
const workspacePath = path.join(workspaceBase, workspaces[0]);
const workspaceJson = await fsClient.promises.readFile(workspacePath);
const workspace = YAML.parse(workspaceJson.toString());
if (workspace.scope === WorkspaceScopeKeys.collection) {
return WorkspaceScopeKeys.collection;
}
return WorkspaceScopeKeys.design;
};

// Stop the DB from pushing updates to the UI temporarily
const bufferId = await database.bufferChanges();
let workspaceId = '';
const scope = await getWorkspaceScopeFromWorkspaceDir(fsClient);
// If no workspace exists we create a new one
if (!(await containsInsomniaWorkspaceDir(fsClient))) {
// Create a new workspace

const workspace = await models.workspace.create({
name: repoSettingsPatch.uri.split('/').pop(),
scope: WorkspaceScopeKeys.design,
scope: scope,
parentId: project._id,
description: `Insomnia Workspace for ${repoSettingsPatch.uri}}`,
});
Expand Down Expand Up @@ -543,7 +560,12 @@ export const cloneGitRepoAction: ActionFunction = async ({
const existingWorkspace = await models.workspace.getById(workspace._id);

if (existingWorkspace) {
return redirect(`/organization/${existingWorkspace.parentId || DEFAULT_ORGANIZATION_ID}/project/${existingWorkspace.parentId || DEFAULT_PROJECT_ID}/workspace/${existingWorkspace._id}/debug`);
// if collection scope, redirect to debug instead
if (existingWorkspace.scope === WorkspaceScopeKeys.collection) {
return redirect(`/organization/${existingWorkspace.parentId || DEFAULT_ORGANIZATION_ID}/project/${existingWorkspace.parentId || DEFAULT_PROJECT_ID}/workspace/${existingWorkspace._id}/debug`);
}

return redirect(`/organization/${existingWorkspace.parentId || DEFAULT_ORGANIZATION_ID}/project/${existingWorkspace.parentId || DEFAULT_PROJECT_ID}/workspace/${existingWorkspace._id}/${ACTIVITY_SPEC}`);
}

// Loop over all model folders in root
Expand All @@ -555,9 +577,10 @@ export const cloneGitRepoAction: ActionFunction = async ({
const docPath = path.join(modelDir, docFileName);
const docYaml = await fsClient.promises.readFile(docPath);
const doc: models.BaseModel = YAML.parse(docYaml.toString());
const scope = await getWorkspaceScopeFromWorkspaceDir(fsClient);
if (isWorkspace(doc)) {
doc.parentId = project._id;
doc.scope = WorkspaceScopeKeys.design;
doc.scope = scope;
const workspace = await database.upsert(doc);
workspaceId = workspace._id;
} else {
Expand All @@ -581,6 +604,11 @@ export const cloneGitRepoAction: ActionFunction = async ({

invariant(workspaceId, 'Workspace ID is required');

if (scope === WorkspaceScopeKeys.collection) {
return redirect(
`/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/debug`
);
}
return redirect(
`/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/${ACTIVITY_SPEC}`
);
Expand Down

0 comments on commit ce6ec8c

Please sign in to comment.