Skip to content

Git Credentials: Refactor deletion logic [INS-2471]#9906

Open
yaoweiprc wants to merge 1 commit into
developfrom
fix/delete-git-credentials
Open

Git Credentials: Refactor deletion logic [INS-2471]#9906
yaoweiprc wants to merge 1 commit into
developfrom
fix/delete-git-credentials

Conversation

@yaoweiprc
Copy link
Copy Markdown
Contributor

Problem

Two bugs existed in the Git credential deletion flow:

1. False "Cannot Delete Git Credential" warning

When deleting a Git credential, the app checks whether any projects are linked to it via a GitRepository. If linked projects are found, it blocks deletion and shows a warning listing those projects.

However, the query returned all linked projects regardless of ownership. A project belonging to a different user (i.e., whose parentId is not in the current user's organizations) would still appear in the list, causing the warning to fire — even though the current user cannot see or manage that project.

2. Incomplete cleanup on credential deletion

When a credential was deleted, the action only set credentialsId: null on connected GitRepository records, leaving the repositories intact and still linked to their associated projects and workspace metas. This left those projects in a broken git state.

Changes

  • git-credentials.$id.related-projects.tsx: After fetching projects linked to a credential's repositories, filter them to only include projects whose parentId belongs to the current user's organizations (matching the same ownership check used in untrackedProjects). Projects owned by other users are excluded, so they no longer trigger the deletion warning.

  • session.ts: Exported the existing _removeGitRepository helper so it can be reused outside the module.

  • git-credentials.$id.delete.tsx: On credential deletion, call _removeGitRepository for each connected repository instead of only nulling credentialsId. This properly unlinks the repository from associated projects (resetting gitRepositoryId to EMPTY_GIT_PROJECT_ID) and workspace metas before removing the repository record.

Copilot AI review requested due to automatic review settings May 7, 2026 10:24
@yaoweiprc yaoweiprc changed the title Git Credentials: Refactor deletion logic Git Credentials: Refactor deletion logic [INS-2471] May 7, 2026
@yaoweiprc yaoweiprc requested a review from gatzjames May 7, 2026 10:27
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

✅ Circular References Report

Generated at: 2026-05-07T10:30:02.716Z
Status: ✅ NO CHANGE

Summary

Metric Base (develop) PR Change
Total Circular References 19 19 0 (0.00%)
Click to view all circular references in PR (19)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts -> insomnia/src/script-executor.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts -> insomnia/src/script-executor.ts -> insomnia/src/scripting/require-interceptor.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/concurrency.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts -> insomnia/src/templating/index.ts -> insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/network/network.ts -> insomnia/src/main/network/get-auth-header.ts -> insomnia/src/main/network/o-auth-2/get-token.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/store.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/misc.ts
insomnia/src/templating/base-extension-worker.ts -> insomnia/src/templating/worker.ts
insomnia/src/templating/index.ts -> insomnia/src/templating/base-extension.ts
insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/templating/types.ts -> insomnia/src/templating/utils.ts
insomnia/src/ui/components/settings/import-export.tsx -> insomnia/src/ui/components/modals/export-requests-modal.tsx
insomnia/src/ui/components/tabs/tab-list.tsx -> insomnia/src/ui/components/tabs/tab.tsx
insomnia/src/ui/components/templating/tag-editor-arg-sub-form.tsx -> insomnia/src/ui/components/templating/external-vault/external-vault-form.tsx
insomnia/src/ui/components/viewers/response-viewer.tsx -> insomnia/src/ui/components/viewers/response-multipart-viewer.tsx
Click to view all circular references in base branch (19)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts -> insomnia/src/script-executor.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts -> insomnia/src/script-executor.ts -> insomnia/src/scripting/require-interceptor.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/concurrency.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts -> insomnia/src/templating/index.ts -> insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/network/network.ts -> insomnia/src/main/network/get-auth-header.ts -> insomnia/src/main/network/o-auth-2/get-token.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/store.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/misc.ts
insomnia/src/templating/base-extension-worker.ts -> insomnia/src/templating/worker.ts
insomnia/src/templating/index.ts -> insomnia/src/templating/base-extension.ts
insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/templating/types.ts -> insomnia/src/templating/utils.ts
insomnia/src/ui/components/settings/import-export.tsx -> insomnia/src/ui/components/modals/export-requests-modal.tsx
insomnia/src/ui/components/tabs/tab-list.tsx -> insomnia/src/ui/components/tabs/tab.tsx
insomnia/src/ui/components/templating/tag-editor-arg-sub-form.tsx -> insomnia/src/ui/components/templating/external-vault/external-vault-form.tsx
insomnia/src/ui/components/viewers/response-viewer.tsx -> insomnia/src/ui/components/viewers/response-multipart-viewer.tsx

Analysis

No Change: This PR does not introduce or remove any circular references.


This report was generated automatically by comparing against the develop branch.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the Git credential deletion flow to (1) avoid blocking deletion due to projects the current user doesn’t own and (2) ensure connected git repositories are properly unlinked/removed when a credential is deleted.

Changes:

  • Filters “related projects” for a credential to only those owned by the current user’s organizations (plus scratchpad).
  • Exports the git-repository removal helper from session.ts for reuse.
  • Deletes connected git repositories (and unlinks projects/workspace metas) when deleting a credential, instead of only nulling credentialsId.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/insomnia/src/routes/git-credentials.$id.related-projects.tsx Filters related projects by current user org ownership before returning them to the UI.
packages/insomnia/src/routes/git-credentials.$id.delete.tsx Uses _removeGitRepository to fully unlink/remove repos when deleting a credential.
packages/insomnia/src/account/session.ts Exposes _removeGitRepository for use outside the session module.
Comments suppressed due to low confidence (1)

packages/insomnia/src/account/session.ts:235

  • _removeGitRepository deletes the repository record directly, but unlike resetGitRepoAction (main process) it does not stop repoFileWatcherRegistry or clear conflict suppression. Now that this helper is used outside logout (e.g., credential deletion), consider coordinating with the main-process git service (via IPC) to ensure watchers are stopped and any per-repo state is cleaned up when a repo is removed.
export async function _removeGitRepository(repo: GitRepository) {
  const queryIds = models.project.getQueryableGitRepositoryIds(repo._id);
  const projects = await database.find<Project>(models.project.type, { gitRepositoryId: { $in: queryIds } });
  for (const p of projects) {
    await services.project.update(p, { gitRepositoryId: models.project.EMPTY_GIT_PROJECT_ID });
  }

  const workspaceMetas = await database.find<WorkspaceMeta>(models.workspaceMeta.type, { gitRepositoryId: repo._id });
  for (const wsMeta of workspaceMetas) {
    await services.workspaceMeta.update(wsMeta, { gitRepositoryId: null });
  }
  await services.gitRepository.remove(repo);
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +18 to +26
const { accountId } = await services.userSession.getOrCreate();
const organizations = JSON.parse(localStorage.getItem(`${accountId}:organizations`) || '[]') as Organization[];
const currentUserOrganizationIds = new Set([
...organizations.map(o => o.id),
models.organization.SCRATCHPAD_ORGANIZATION_ID,
]);

const currentUserProjects = relatedProjects.filter(p => currentUserOrganizationIds.has(p.parentId));

Comment on lines 16 to 20
const connectedRepositories = await services.gitRepository.getAllByCredentialId(id);

for (const repo of connectedRepositories) {
await services.gitRepository.update(repo, { credentialsId: null });
await _removeGitRepository(repo);
}
Comment on lines +223 to 225
export async function _removeGitRepository(repo: GitRepository) {
const queryIds = models.project.getQueryableGitRepositoryIds(repo._id);
const projects = await database.find<Project>(models.project.type, { gitRepositoryId: { $in: queryIds } });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants